Add a Facets.keyParser setting, which allows for the label to be set
when a new item is set. This is meant to be used against the key, and not be dynamically updated.
Showing
1 changed file
with
12 additions
and
2 deletions
... | @@ -216,6 +216,9 @@ define(function(require) { | ... | @@ -216,6 +216,9 @@ define(function(require) { |
216 | this.facetField = options.facetField; | 216 | this.facetField = options.facetField; |
217 | this.queryField = options.queryField; | 217 | this.queryField = options.queryField; |
218 | this.queryValue = options.queryValue; | 218 | this.queryValue = options.queryValue; |
219 | if (options.keyParser) { | ||
220 | this.keyParser = options.keyParser; | ||
221 | } | ||
219 | this.bins = options.bins; | 222 | this.bins = options.bins; |
220 | switch (this.facetType) { | 223 | switch (this.facetType) { |
221 | case 'year': | 224 | case 'year': |
... | @@ -239,6 +242,9 @@ define(function(require) { | ... | @@ -239,6 +242,9 @@ define(function(require) { |
239 | } | 242 | } |
240 | return Facet.__super__.initialize.apply(this, arguments); | 243 | return Facet.__super__.initialize.apply(this, arguments); |
241 | }, | 244 | }, |
245 | keyParser: function(key) { | ||
246 | return {key: key, label: key}; | ||
247 | }, | ||
242 | resetSearch: function(options) { | 248 | resetSearch: function(options) { |
243 | this.get('items').invoke('reset', null, options); | 249 | this.get('items').invoke('reset', null, options); |
244 | }, | 250 | }, |
... | @@ -347,10 +353,14 @@ define(function(require) { | ... | @@ -347,10 +353,14 @@ define(function(require) { |
347 | }, | 353 | }, |
348 | getOrCreateItem: function addOrGetItem(key) { | 354 | getOrCreateItem: function addOrGetItem(key) { |
349 | var items = this.get('items'); | 355 | var items = this.get('items'); |
350 | key = Facet.Item.checkNull(key); | 356 | var keyInfo = this.keyParser(Facet.Item.checkNull(key)); |
357 | key = keyInfo.key; | ||
358 | var label = keyInfo.label; | ||
351 | var item = items.get(key); | 359 | var item = items.get(key); |
352 | if (!item) { | 360 | if (!item) { |
353 | item = new Facet.Item({key: key, value: 0}); | 361 | item = new Facet.Item({key: key, label: label, value: 0}); |
362 | } else if (label !== undefined) { | ||
363 | item.set('label', label); | ||
354 | } | 364 | } |
355 | return item; | 365 | return item; |
356 | }, | 366 | }, | ... | ... |
-
Please register or sign in to post a comment