716f1e9b by Adam Heath

Set Facet.{itemCount,checkedCount}.

1 parent bda1adc2
...@@ -30,6 +30,8 @@ define(function(require) { ...@@ -30,6 +30,8 @@ define(function(require) {
30 var Facet = Backbone.Model.extend({ 30 var Facet = Backbone.Model.extend({
31 defaults: function defaults() { 31 defaults: function defaults() {
32 return { 32 return {
33 itemCount: 0,
34 checkedCount: 0,
33 checkedKeys: [], 35 checkedKeys: [],
34 formName: null, 36 formName: null,
35 query: null, 37 query: null,
...@@ -67,6 +69,7 @@ define(function(require) { ...@@ -67,6 +69,7 @@ define(function(require) {
67 try { 69 try {
68 this.set({ 70 this.set({
69 all: checkedCount === 0, 71 all: checkedCount === 0,
72 checkedCount: checkedCount,
70 checkedKeys: checkedKeys, 73 checkedKeys: checkedKeys,
71 74
72 }); 75 });
...@@ -120,6 +123,7 @@ define(function(require) { ...@@ -120,6 +123,7 @@ define(function(require) {
120 }); 123 });
121 this.set({ 124 this.set({
122 all: checkedCount === 0, 125 all: checkedCount === 0,
126 checkedCount: checkedCount,
123 }); 127 });
124 } finally { 128 } finally {
125 skipCallback = null; 129 skipCallback = null;
...@@ -180,12 +184,19 @@ define(function(require) { ...@@ -180,12 +184,19 @@ define(function(require) {
180 items.sort(); 184 items.sort();
181 }, this); 185 }, this);
182 186
183 this.set('items', new ItemCollection([])); 187 var items = new ItemCollection([]);
188 this.set('items', items);
184 this.set('comparator', options.comparator, {silent: true}); 189 this.set('comparator', options.comparator, {silent: true});
185 this.trigger('change:comparator'); 190 this.trigger('change:comparator');
186 this.get('items').on('item-change', function(model, value, options) { 191 items.on('item-change', function(model, value, options) {
187 this.trigger('item-change', null, null, options); 192 this.trigger('item-change', null, null, options);
188 }, this); 193 }, this);
194 items.on('update', function(model, value, options) {
195 var items = this.get('items');
196 this.set({
197 itemCount: items.length,
198 });
199 }, this);
189 this.facetType = options.facetType; 200 this.facetType = options.facetType;
190 this.facetStats = options.facetStats; 201 this.facetStats = options.facetStats;
191 this.other = options.other; 202 this.other = options.other;
......