don't e-mail errors, just save them to file
[koha-bibliografija] / html / filters.js
1
2 function toc_count_update(type_cat) {
3         var selector = '#toc-count-'+type_cat.replace(/\./g,'-');
4         var e = $(selector);
5         if ( ! e )  {
6                 console.error(selector, 'not found');
7                 return;
8         }
9         var old_val = parseInt( e.text() );
10         var new_val = parseInt( type_cat_count[type_cat] );
11
12         if ( old_val != new_val ) {
13                 e.text(new_val);
14                 console.debug( selector, 'old', old_val, 'new', new_val);
15
16                 var cat = type_cat.split('-')[0];
17                 var val = type_cat_count['_toc_count'][cat] += new_val - old_val;
18                 console.log(cat, val);
19                 $('#toc-count-'+cat).text(val);
20
21         }
22 }
23
24 function year_show(year) {
25         $('.y'+year).show();
26         console.debug('show', year);
27         for(var type_cat in years[year]) {
28 //console.log('year_show', type_cat, type_cat_count[ type_cat ], years[year][type_cat] );
29                 if ( ( type_cat_count[ type_cat ] += parseInt(years[year][type_cat]) ) > 0 ) {
30                         $('a[name="'+type_cat+'"]').show();
31                         console.debug(type_cat, 'show');
32                 }
33                 toc_count_update(type_cat);
34         }
35 }
36
37 function year_hide(year) {
38         $('.y'+year).hide();
39         console.debug('hide', year);
40         for(var type_cat in years[year]) {
41 //console.log('year_hide', type_cat, type_cat_count[ type_cat ], years[year][type_cat] );
42                 if ( ( type_cat_count[ type_cat ] -= parseInt(years[year][type_cat]) ) == 0 ) {
43                         $('a[name="'+type_cat+'"]').hide();
44                         console.debug(type_cat, 'hide');
45                 }
46                 toc_count_update(type_cat);
47         }
48 }
49
50 function toggle_year(year, el) {
51         if ( el.checked ) {
52                 year_show(year);
53         } else {
54                 year_hide(year);
55         }
56 }
57
58 function all_years( turn_on ) {
59         $('input[name=year_selection]').each( function(i,el) {
60                 if ( turn_on ) {
61                         if ( ! el.checked ) {
62                                 el.checked = true;
63                                 year_show( el.value );
64                         }
65                 } else {
66                         if ( el.checked ) {
67                                 el.checked = false;
68                                 year_hide( el.value );
69                         }
70                 }
71         } );
72 }
73
74 $(document).ready( function() {
75         console.info('ready');
76
77         $('input[name=year_selection]').each( function(i, el) {
78                 var year = el.value;
79                 console.debug( 'on load', year, el.checked );
80                 if (! el.checked) year_hide(year);
81         });
82
83 });