023217a0 by Adam Heath

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.
1 parent 4f066cf3
......@@ -216,6 +216,9 @@ define(function(require) {
this.facetField = options.facetField;
this.queryField = options.queryField;
this.queryValue = options.queryValue;
if (options.keyParser) {
this.keyParser = options.keyParser;
}
this.bins = options.bins;
switch (this.facetType) {
case 'year':
......@@ -239,6 +242,9 @@ define(function(require) {
}
return Facet.__super__.initialize.apply(this, arguments);
},
keyParser: function(key) {
return {key: key, label: key};
},
resetSearch: function(options) {
this.get('items').invoke('reset', null, options);
},
......@@ -347,10 +353,14 @@ define(function(require) {
},
getOrCreateItem: function addOrGetItem(key) {
var items = this.get('items');
key = Facet.Item.checkNull(key);
var keyInfo = this.keyParser(Facet.Item.checkNull(key));
key = keyInfo.key;
var label = keyInfo.label;
var item = items.get(key);
if (!item) {
item = new Facet.Item({key: key, value: 0});
item = new Facet.Item({key: key, label: label, value: 0});
} else if (label !== undefined) {
item.set('label', label);
}
return item;
},
......