by category page

This commit is contained in:
Edin Dazdarevic
2015-02-04 06:51:49 +01:00
parent 67e31fe716
commit 6fc5969fe6
7 changed files with 105 additions and 11 deletions

View File

@@ -8,7 +8,8 @@ var _ = require('underscore');
// Define initial data points
var _items = new ItemCollection(),
_itemWithDetails = new ItemWithDetails(),
_bestSellingForSection = new ItemCollection();
_bestSellingForSection = new ItemCollection(),
_itemsByCategory = new ItemCollection();
var loadItemsForFrontpage = function() {
@@ -50,6 +51,19 @@ var fetchItemWithDetails = function() {
}
}
var fetchItemsByCategory = function(categoryId) {
var items = _itemsByCategory;
items.setClassificationType(2);
items.setClassificationId(categoryId);
items.setLimit(30);
items.setOffset(0);
items.fetch({
success: function() {
ItemStore.emitChange();
}});
};
var fetchBestSellingItemsForSection = function(sectionId) {
console.log('getting section', sectionId);
var items = _bestSellingForSection;
@@ -70,6 +84,9 @@ var fetchBestSellingItemsForSection = function(sectionId) {
// Extend ItemStore with EventEmitter to add eventing capabilities
var ItemStore = _.extend({}, EventEmitter.prototype, {
getItemsForCategory: function() {
return _itemsByCategory;
},
getBestSellingForSection: function() {
return _bestSellingForSection;
@@ -122,6 +139,9 @@ AppDispatcher.register(function(payload) {
case ItemConstants.LOAD_FOR_FRONTPAGE:
loadItemsForFrontpage();
break;
case ItemConstants.LOAD_BY_CATEGORY:
fetchItemsByCategory(action.categoryId);
break;
default:
return true;