Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php |
— | — | @@ -37,21 +37,25 @@ |
38 | 38 | |
39 | 39 | $ret = array(); |
40 | 40 | |
41 | | - if ( array_key_exists( 'value filter switches', $params ) ) { |
| 41 | + if ( array_key_exists( 'value filter switches', $params ) ) { |
42 | 42 | $switches = explode( ',', $params['value filter switches'] ); |
43 | 43 | $switches = array_map( 'trim', $switches ); |
44 | 44 | |
45 | 45 | $ret['switches'] = $switches; |
46 | 46 | } |
47 | 47 | |
48 | | - if ( array_key_exists( 'value filter collapsible', $params ) ) { |
| 48 | + if ( array_key_exists( 'value filter collapsible', $params ) ) { |
49 | 49 | $ret['collapsible'] = trim($params['value filter collapsible']); |
50 | 50 | } |
51 | 51 | |
52 | | - if ( array_key_exists( 'value filter height', $params ) ) { |
| 52 | + if ( array_key_exists( 'value filter height', $params ) ) { |
53 | 53 | $ret['height'] = trim($params['value filter height']); |
54 | 54 | } |
55 | 55 | |
| 56 | + if ( array_key_exists( 'value filter values', $params ) ) { |
| 57 | + $ret['values'] = trim($params['value filter values']); |
| 58 | + } |
| 59 | + |
56 | 60 | return $ret; |
57 | 61 | } |
58 | 62 | |
Index: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.value-filter.js |
— | — | @@ -21,20 +21,20 @@ |
22 | 22 | |
23 | 23 | // show all if no value is checked |
24 | 24 | if ( selectedInputs.length == 0 ) { |
25 | | - for ( i in values ) { |
| 25 | + for ( valueId in values ) { |
26 | 26 | filtered.filtered( 'voteItemVisibilityAndUpdate', { |
27 | 27 | 'filter': 'value', |
28 | 28 | 'printout' : target, |
29 | 29 | 'visible': true, |
30 | | - 'item': i |
| 30 | + 'item': valueId |
31 | 31 | }); |
32 | 32 | } |
33 | 33 | |
34 | 34 | } else { |
35 | 35 | |
36 | | - for ( i in values ) { |
| 36 | + for ( valueId in values ) { |
37 | 37 | |
38 | | - var printoutValues = values[i]['printouts'][target]['values']; |
| 38 | + var printoutValues = values[valueId]['printouts'][target]['values']; |
39 | 39 | var useOr = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'use or'} ); |
40 | 40 | |
41 | 41 | if ( useOr ) { |
— | — | @@ -70,7 +70,7 @@ |
71 | 71 | 'filter': 'value', |
72 | 72 | 'printout' : target, |
73 | 73 | 'visible': selected, |
74 | | - 'item': i |
| 74 | + 'item': valueId |
75 | 75 | }); |
76 | 76 | |
77 | 77 | } |
— | — | @@ -85,32 +85,50 @@ |
86 | 86 | var switches = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'switches'} ); |
87 | 87 | var collapsible = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'collapsible'} ); |
88 | 88 | var height = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'height'} ); |
| 89 | + var fixedValues = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'values'} ); |
89 | 90 | |
90 | | - // find distinct values and set visibility for all items that have |
91 | | - // some value for this printout |
92 | | - var distinctValues = []; |
93 | | - |
94 | | - var i; |
95 | | - for ( i in values ) { |
96 | | - var printoutValues = values[i]['printouts'][target]['values']; |
| 91 | + var valueId; // just some valid value ID |
| 92 | + if ( fixedValues == null ) { |
| 93 | + // build filter values from available values in result set |
97 | 94 | |
98 | | - for (var j in printoutValues) { |
99 | | - distinctValues[ printoutValues[j] ] = true; |
| 95 | + // find distinct values and set visibility for all items that have |
| 96 | + // some value for this printout |
| 97 | + var distinctValues = []; |
| 98 | + |
| 99 | + for ( valueId in values ) { |
| 100 | + var printoutValues = values[valueId]['printouts'][target]['values']; |
| 101 | + |
| 102 | + for (var j in printoutValues) { |
| 103 | + distinctValues[ printoutValues[j] ] = true; |
| 104 | + } |
| 105 | + |
| 106 | + filtered.filtered( 'voteItemVisibility', { |
| 107 | + 'filter': 'value', |
| 108 | + 'printout' : target, |
| 109 | + 'visible': true, |
| 110 | + 'item': valueId |
| 111 | + }); |
100 | 112 | } |
101 | 113 | |
102 | | - filtered.filtered( 'voteItemVisibility', { |
103 | | - 'filter': 'value', |
104 | | - 'printout' : target, |
105 | | - 'visible': true, |
106 | | - 'item': i |
107 | | - }); |
| 114 | + var sortedDistinctValues = []; |
| 115 | + |
| 116 | + for ( var i in distinctValues ) { |
| 117 | + sortedDistinctValues.push(i); |
| 118 | + } |
| 119 | + |
| 120 | + sortedDistinctValues.sort(); |
| 121 | + } else { |
| 122 | + // use given values |
| 123 | + sortedDistinctValues = fixedValues.split(/\s*,\s*/); |
| 124 | + |
| 125 | + for ( valueId in values ) break; // get some valid value ID |
108 | 126 | } |
109 | 127 | |
110 | 128 | // build filter controls |
111 | 129 | var filtercontrols = this.children('.filtered-filters').children('.' + target).filter('.filtered-value'); |
112 | 130 | |
113 | 131 | // insert the label of the printout this filter filters on |
114 | | - filtercontrols.append('<div class="filtered-value-label"><span>' + values[i]['printouts'][target]['label'] + '</span></div>'); |
| 132 | + filtercontrols.append('<div class="filtered-value-label"><span>' + values[valueId]['printouts'][target]['label'] + '</span></div>'); |
115 | 133 | |
116 | 134 | if ( collapsible != null && ( collapsible == 'collapsed' || collapsible == 'uncollapsed') ) { |
117 | 135 | |
— | — | @@ -192,14 +210,6 @@ |
193 | 211 | } |
194 | 212 | |
195 | 213 | |
196 | | - var sortedDistinctValues = []; |
197 | | - |
198 | | - for ( var i in distinctValues ) { |
199 | | - sortedDistinctValues.push(i); |
200 | | - } |
201 | | - |
202 | | - sortedDistinctValues.sort(); |
203 | | - |
204 | 214 | // insert options (checkboxes and labels) and attach event handlers |
205 | 215 | // TODO: Do we need to wrap these in a form? |
206 | 216 | for ( var j in sortedDistinctValues ) { |