From 76d5fd7599ffb1126a7cde6121b9379f2d35c780 Mon Sep 17 00:00:00 2001 From: Edin Dazdarevic Date: Mon, 30 Mar 2015 00:05:57 +0200 Subject: [PATCH] fixed paging on subcategory browsing page --- front-ui/app/actions/bySubCategoryActions.js | 6 ++++ .../app/components/browsing/bySubCategory.js | 10 ++++-- front-ui/app/components/items/itemList.js | 1 - .../app/constants/bySubCategoryConstants.js | 3 +- front-ui/app/stores/bySubCategoryStore.js | 31 ++++++++++--------- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/front-ui/app/actions/bySubCategoryActions.js b/front-ui/app/actions/bySubCategoryActions.js index 49ad8ba..37f2e19 100644 --- a/front-ui/app/actions/bySubCategoryActions.js +++ b/front-ui/app/actions/bySubCategoryActions.js @@ -24,6 +24,12 @@ var BySubCategoryActions = { actionType: BySubCategoryConstants.REMOVE_APPLIED_FILTER, name: name }); + }, + changePage: function(page) { + AppDispatcher.handleAction({ + actionType: BySubCategoryConstants.CHANGE_PAGE, + page: page + }); }, }; diff --git a/front-ui/app/components/browsing/bySubCategory.js b/front-ui/app/components/browsing/bySubCategory.js index 0415aa5..4a7834e 100644 --- a/front-ui/app/components/browsing/bySubCategory.js +++ b/front-ui/app/components/browsing/bySubCategory.js @@ -23,6 +23,9 @@ var BySubCategory = React.createClass({ removeAppliedFilter: function(name) { BySubCategoryActions.removeAppliedFilter(name); }, + onChangePage: function(page) { + BySubCategoryActions.changePage(page); + }, render : function() { return (
@@ -32,14 +35,17 @@ var BySubCategory = React.createClass({
+

Podkategorija {this.state.subCategory.get('name')} +

- Number of items in this subcategory: {this.state.items.length} +
Number of items in this subcategory: {this.state.items.length}
+
total count : {this.state.items.totalCount}
- +
) }, diff --git a/front-ui/app/components/items/itemList.js b/front-ui/app/components/items/itemList.js index 1f75fa0..1647382 100644 --- a/front-ui/app/components/items/itemList.js +++ b/front-ui/app/components/items/itemList.js @@ -62,7 +62,6 @@ var ItemList = React.createClass({ return ( ) diff --git a/front-ui/app/constants/bySubCategoryConstants.js b/front-ui/app/constants/bySubCategoryConstants.js index 68a2b72..e08a643 100644 --- a/front-ui/app/constants/bySubCategoryConstants.js +++ b/front-ui/app/constants/bySubCategoryConstants.js @@ -4,5 +4,6 @@ var keyMirror = require('react/lib/keyMirror'); module.exports = keyMirror({ LOAD: null, FILTER_CRITERIA_CLICK: null, - REMOVE_APPLIED_FILTER: null + REMOVE_APPLIED_FILTER: null, + CHANGE_PAGE: null }); diff --git a/front-ui/app/stores/bySubCategoryStore.js b/front-ui/app/stores/bySubCategoryStore.js index 2bd0807..578a82a 100644 --- a/front-ui/app/stores/bySubCategoryStore.js +++ b/front-ui/app/stores/bySubCategoryStore.js @@ -8,11 +8,16 @@ var BySubCategoryConstants = require('../constants/bySubCategoryConstants'); var ItemCollection = require('../models/itemCollection'); var _ = require('underscore'); +var Globals = require('../globals'); + var _state = { subCategory : (new SubCategory()), items: (new ItemCollection()), filter: {}, - pagination: {} + pagination: { + offset : 0, + limit: Globals.DefaultPageSize + } }; //var _categoryDetails = new Category(); @@ -65,7 +70,8 @@ var load = function(subCategoryId, offset, limit, filter) { } }); _state.filter = filter; - //BySubCategoryStore.emitChange(); + _state.pagination.limit = limit; + _state.pagination.offset = offset; }; var handleFilterCriteriaClick = function(fc, fcv) { @@ -83,19 +89,13 @@ var handleRemoveAppliedFilter= function(name) { NavigationActions.goToSubCategory(_state.subCategory, 0, _state.pagination.limit, _state.filter); }, 0); }; -//var loadCategoryDetails = function(categoryId) { - //var category = new Category({id : categoryId}); - //category.fetch({ - //success: function() { - //_categoryDetails = category; - //BySubCategoryStore.emitChange(); - //} - //}); -//}; -//var setHovered = function(id) { - //sectionState.hoveredSection = id; -//} +var handleChangePage = function(page) { + setTimeout(function() { + NavigationActions.goToSubCategory(_state.subCategory, parseInt(page) * _state.pagination.limit, _state.pagination.limit, _state.filter); + }, 0); +}; + // Extend SectionStore with EventEmitter to add eventing capabilities @@ -139,6 +139,9 @@ AppDispatcher.register(function(payload) { case BySubCategoryConstants.REMOVE_APPLIED_FILTER: handleRemoveAppliedFilter(action.name); break; + case BySubCategoryConstants.CHANGE_PAGE: + handleChangePage(action.page); + break; // Respond to SELECT_ITEM action //case SectionConstants.LOAD_SECTIONS: