cart display works but it's far from finished
This commit is contained in:
@@ -4,56 +4,75 @@ var Backbone = require('backbone'),
|
||||
|
||||
var ItemCollection = Backbone.Collection.extend({
|
||||
|
||||
addFilter : function(name, value) {
|
||||
this.filters = this.filters || {};
|
||||
this.filters[name] = value;
|
||||
},
|
||||
clearFilter: function() {
|
||||
this.filters = [];
|
||||
initialize: function() {
|
||||
$.ajaxPrefilter(
|
||||
function(options, originalOptions, jqXHR) {
|
||||
options.xhrFields = {
|
||||
withCredentials: true
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
setLimit: function(limit) {
|
||||
this.queryLimit = limit;
|
||||
|
||||
addFilter: function(name, value) {
|
||||
this.filters = this.filters || {};
|
||||
this.filters[name] = value;
|
||||
},
|
||||
clearFilter: function() {
|
||||
this.filters = [];
|
||||
},
|
||||
setLimit: function(limit) {
|
||||
this.queryLimit = limit;
|
||||
},
|
||||
|
||||
setOffset: function(offset) {
|
||||
this.offset = offset;
|
||||
this.offset = offset;
|
||||
},
|
||||
|
||||
classificationTypeUrlParts: ['','section','category','sub_category'],
|
||||
classificationTypeUrlParts: ['', 'section', 'category', 'sub_category'],
|
||||
|
||||
setClassificationType: function(type) {
|
||||
this.classificationType = type;
|
||||
} ,
|
||||
this.classificationType = type;
|
||||
},
|
||||
|
||||
setClassificationId: function(id) {
|
||||
this.classificationId = id;
|
||||
},
|
||||
this.classificationId = id;
|
||||
},
|
||||
|
||||
setFromCart: function(fromCart) {
|
||||
this.fromCart = fromCart;
|
||||
},
|
||||
|
||||
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;
|
||||
|
||||
var queryParts = [];
|
||||
|
||||
for(var key in this.filters) {
|
||||
if (this.filters.hasOwnProperty(key)) {
|
||||
queryParts.push(key + '=' + this.filters[key]);
|
||||
url: function() {
|
||||
if (this.fromCart === true) {
|
||||
return Globals.ApiUrl + "/cart/item/display";
|
||||
}
|
||||
}
|
||||
var query = '';
|
||||
|
||||
if (queryParts.length > 0) {
|
||||
query = '?' + queryParts.join('&');
|
||||
}
|
||||
var path = '/item';
|
||||
|
||||
return Globals.ApiUrl + path + query;
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ItemCollection;
|
||||
module.exports = ItemCollection;
|
||||
Reference in New Issue
Block a user