3b36fcf975f21a5d8790e93efabcead6f4545770
[MojoFacets.git] / templates / all_checkboxes.html.ep
1 <span id=column_selection>
2 <a id="all"  href="#">all</a>
3 <a id="toggle" href="#">toggle</a>
4 <a id="none" href="#">none</a>
5
6 <label for=filter_regex>
7 <input tabindex=1 type=text name=filter_regex title="enter regex to filter values" placeholder="regex">
8 <a tabindex=2 id="included" href="#" style="display:none">included</a>
9 <a tabindex=3 id="excluded" href="#" style="display:none">excluded</a>
10 </label>
11 </span>
12
13
14 <script type="text/javascript">
15
16 $(document).ready( function(){
17
18 $('a#all').click( function(){
19     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
20          $('#checked-count').text( $('#facet-count').text() );
21 });
22
23 $('a#none').click( function(){
24     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
25         $('#checked-count').text( 0 );
26 });
27
28 $('a#toggle').click( function(){
29         var count = 0;
30     $("input[type='checkbox']:not([disabled='disabled'])").each( function() {
31                 this.checked = ! this.checked;
32                 if ( this.checked ) count++;
33         });
34         $('#checked-count').text( count );
35 });
36
37 function update_checked_count(full) {
38         var count = $('#checked-count');
39         var nr = -1;
40         if ( full ) {
41                 nr = $("label input[type='checkbox']:checked").length;
42         } else {
43                 nr = parseInt( count.text() );
44                 if ( this.checked ) {
45                         nr++;
46                 } else {
47                         nr--;
48                 }
49         }
50         count.text( nr );
51 }
52
53 $("input[type='checkbox']").bind( 'click', update_checked_count );
54
55 var toggle_checkbox = function() {
56                 this.checked = ! this.checked;
57 };
58
59 $('a#included').click( function(){
60     $("label.included input[type='checkbox']:not([disabled='disabled'])").each( toggle_checkbox );
61         update_checked_count(1);
62 });
63
64 $('a#excluded').click( function(){
65     $("label.excluded input[type='checkbox']:not([disabled='disabled'])").each( toggle_checkbox );
66         update_checked_count(1);
67 });
68
69
70 // regex for column names
71
72 var apply_regex = function(e) {
73         console.debug( this, e );
74         var r = new RegExp( this.value ,'i');
75         var included = 0;
76         var excluded = 0;
77     $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
78                 if ( r.test( this.value ) ) {
79                         $(this).parent().removeClass('excluded').addClass('included');
80                         included++;
81                 } else {
82                         $(this).parent().removeClass('included').addClass('excluded');
83                         excluded++;
84                 }
85         });
86
87         $('a#included').text(included).show();
88         $('a#excluded').text(excluded).show();
89         return false;
90 };
91
92 $('input[name=filter_regex]')
93 .focusout( apply_regex )
94 .keypress( function(e) {
95         // disable enter
96         var code = e.keyCode ? e.keyCode : e.which;
97         //console.debug('key code',code);
98         if ( code == 13 ) {
99                 return apply_regex(e);
100         } else {
101                 return true;
102         }
103 });
104
105
106 update_checked_count(1);
107
108 }); // document.ready
109
110 </script>
111