Files
old-ribica/front-ui/app/models/itemCollection.js
2015-01-22 22:20:34 +01:00

39 lines
1.1 KiB
JavaScript

var Backbone = require('backbone'),
Item = require('./item'),
Globals = require('../globals');
var ItemCollection = Backbone.Collection.extend({
setLimit: function(limit) {
this.queryLimit = limit;
},
setOffset: function(offset) {
this.offset = offset;
},
classificationTypeUrlParts: ['','section','category','sub_category'],
setClassificationType: function(type) {
this.classificationType = type;
} ,
setClassificatonId: function(id) {
this.classificationId = id;
},
model: Item,
url: function() {
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
} // else eg. http://localhost:4567/item/offset/0/limit/10
path += "/offset/" + this.offset + "/limit/" + this.queryLimit;
return Globals.ApiUrl + path;
}
});
module.exports = ItemCollection;