changed itemcollection to support filtering by traits
This commit is contained in:
@@ -4,6 +4,10 @@ var Backbone = require('backbone'),
|
||||
|
||||
var ItemCollection = Backbone.Collection.extend({
|
||||
|
||||
addFilter : function(name, value) {
|
||||
this.filters = this.filters || {};
|
||||
this.filters[name] = value;
|
||||
},
|
||||
setLimit: function(limit) {
|
||||
this.queryLimit = limit;
|
||||
},
|
||||
@@ -24,14 +28,28 @@ var ItemCollection = Backbone.Collection.extend({
|
||||
|
||||
model: Item,
|
||||
url: function() {
|
||||
var path = '/item'
|
||||
var path = '/item'
|
||||
if(this.classificationType > 0) {
|
||||
// eg. http://localhost:4567/item/section/1/offset/0/limit/10
|
||||
var urlPart = this.classificationTypeUrlParts[this.classificationType];
|
||||
path += "/" + urlPart + "/" + this.classificationId
|
||||
// eg. http://localhost:4567/item/section/1/offset/0/limit/10
|
||||
var urlPart = this.classificationTypeUrlParts[this.classificationType];
|
||||
path += "/" + urlPart + "/" + this.classificationId;
|
||||
} // else eg. http://localhost:4567/item/offset/0/limit/10
|
||||
path += "/offset/" + this.offset + "/limit/" + this.queryLimit;
|
||||
return Globals.ApiUrl + path;
|
||||
path += "/offset/" + this.offset + "/limit/" + this.queryLimit;
|
||||
|
||||
var queryParts = [];
|
||||
|
||||
for(var key in this.filters) {
|
||||
if (this.filters.hasOwnProperty(key)) {
|
||||
queryParts.push(key + '=' + this.filters[key]);
|
||||
}
|
||||
}
|
||||
var query = '';
|
||||
|
||||
if (queryParts.length > 0) {
|
||||
query = '?' + queryParts.join('&');
|
||||
}
|
||||
|
||||
return Globals.ApiUrl + path + query;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user