loading best selling items for sections

This commit is contained in:
Edin Dazdarevic
2015-01-31 13:31:56 +01:00
parent 35cc279527
commit 50a233eae8
8 changed files with 145 additions and 44 deletions

View File

@@ -7,7 +7,8 @@ var _ = require('underscore');
// Define initial data points
var _items = new ItemCollection(),
_itemWithDetails = new ItemWithDetails();
_itemWithDetails = new ItemWithDetails(),
_bestSellingForSection = new ItemCollection();
var loadItemsForFrontpage = function() {
@@ -49,10 +50,30 @@ var fetchItemWithDetails = function() {
}
}
var fetchBestSellingItemsForSection = function(sectionId) {
console.log('getting section', sectionId);
var items = _bestSellingForSection;
items.setClassificationType(1);
items.setClassificationId(sectionId);
items.setLimit(30);
items.setOffset(0);
items.fetch({
success: function() {
ItemStore.emitChange();
}
});
};
// Extend ItemStore with EventEmitter to add eventing capabilities
var ItemStore = _.extend({}, EventEmitter.prototype, {
getBestSellingForSection: function() {
return _bestSellingForSection;
},
// item with details
getLoadedItemWithDetails: function() {
return _itemWithDetails;
@@ -94,6 +115,9 @@ AppDispatcher.register(function(payload) {
fetchItemWithDetails();
break;
case ItemConstants.LOAD_BSI_FOR_SECTION:
fetchBestSellingItemsForSection(action.sectionId);
break;
case ItemConstants.LOAD_FOR_FRONTPAGE:
loadItemsForFrontpage();
@@ -109,4 +133,4 @@ AppDispatcher.register(function(payload) {
});
module.exports = ItemStore;
module.exports = ItemStore;