|
|
@ -2,6 +2,7 @@ var _ = require('underscore');
|
|
|
|
var Backbone = require('backbone');
|
|
|
|
var Backbone = require('backbone');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(){
|
|
|
|
module.exports = function(){
|
|
|
|
|
|
|
|
|
|
|
|
this.prototype.setFilter = function(filter, options){
|
|
|
|
this.prototype.setFilter = function(filter, options){
|
|
|
|
options = _.extend({reset : true}, options || {});
|
|
|
|
options = _.extend({reset : true}, options || {});
|
|
|
|
this.state.filterKey = filter[0];
|
|
|
|
this.state.filterKey = filter[0];
|
|
|
@ -15,10 +16,13 @@ module.exports = function(){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.prototype.setFilterMode = function(mode, options){
|
|
|
|
this.prototype.setFilterMode = function(mode, options){
|
|
|
|
return this.setFilter(this.filterModes[mode], options);
|
|
|
|
return this.setFilter(this.filterModes[mode], options);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var originalMakeFullCollection = this.prototype._makeFullCollection;
|
|
|
|
var originalMakeFullCollection = this.prototype._makeFullCollection;
|
|
|
|
|
|
|
|
|
|
|
|
this.prototype._makeFullCollection = function(models, options){
|
|
|
|
this.prototype._makeFullCollection = function(models, options){
|
|
|
|
var self = this;
|
|
|
|
var self = this;
|
|
|
|
self.shadowCollection = originalMakeFullCollection.call(this, models, options);
|
|
|
|
self.shadowCollection = originalMakeFullCollection.call(this, models, options);
|
|
|
@ -30,18 +34,23 @@ module.exports = function(){
|
|
|
|
return model.get(self.state.filterKey) === self.state.filterValue;
|
|
|
|
return model.get(self.state.filterKey) === self.state.filterValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
self.shadowCollection.filtered = function(){
|
|
|
|
self.shadowCollection.filtered = function(){
|
|
|
|
return this.filter(filterModel);
|
|
|
|
return this.filter(filterModel);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var filteredModels = self.shadowCollection.filtered();
|
|
|
|
var filteredModels = self.shadowCollection.filtered();
|
|
|
|
var fullCollection = originalMakeFullCollection.call(this, filteredModels, options);
|
|
|
|
var fullCollection = originalMakeFullCollection.call(this, filteredModels, options);
|
|
|
|
|
|
|
|
|
|
|
|
fullCollection.resetFiltered = function(options){
|
|
|
|
fullCollection.resetFiltered = function(options){
|
|
|
|
Backbone.Collection.prototype.reset.call(this, self.shadowCollection.filtered(), options);
|
|
|
|
Backbone.Collection.prototype.reset.call(this, self.shadowCollection.filtered(), options);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
fullCollection.reset = function(models, options){
|
|
|
|
fullCollection.reset = function(models, options){
|
|
|
|
self.shadowCollection.reset(models, options);
|
|
|
|
self.shadowCollection.reset(models, options);
|
|
|
|
self.fullCollection.resetFiltered();
|
|
|
|
self.fullCollection.resetFiltered();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return fullCollection;
|
|
|
|
return fullCollection;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
_.extend(this.prototype.state, {
|
|
|
|
_.extend(this.prototype.state, {
|
|
|
|