fixed paging on subcategory browsing page

This commit is contained in:
Edin Dazdarevic
2015-03-30 00:05:57 +02:00
parent 7c1eb2f4fd
commit 76d5fd7599
5 changed files with 33 additions and 18 deletions

View File

@@ -24,6 +24,12 @@ var BySubCategoryActions = {
actionType: BySubCategoryConstants.REMOVE_APPLIED_FILTER,
name: name
});
},
changePage: function(page) {
AppDispatcher.handleAction({
actionType: BySubCategoryConstants.CHANGE_PAGE,
page: page
});
},
};

View File

@@ -23,6 +23,9 @@ var BySubCategory = React.createClass({
removeAppliedFilter: function(name) {
BySubCategoryActions.removeAppliedFilter(name);
},
onChangePage: function(page) {
BySubCategoryActions.changePage(page);
},
render : function() {
return (<div>
@@ -32,14 +35,17 @@ var BySubCategory = React.createClass({
</div>
<div classname='col-md-10'>
<h2>
Podkategorija {this.state.subCategory.get('name')}
</h2>
Number of items in this subcategory: {this.state.items.length}
<div>Number of items in this subcategory: {this.state.items.length}</div>
<div>total count : {this.state.items.totalCount}</div>
<div>
<AppliedFiltersList filters={this.appliedSubCategoryFiltersArray()} onRemove={this.removeAppliedFilter} />
</div>
<ItemList items={this.state.items} paginationEnabled={true} total={this.state.items.totalCount} limit={this.state.pagination.limit} onPageChange={this.changePage} currentOffset={this.state.pagination.offset} />
<ItemList items={this.state.items} paginationEnabled={true} total={this.state.items.totalCount} limit={this.state.pagination.limit} onPageChange={this.onChangePage} currentOffset={this.state.pagination.offset} />
</div>
</div>)
},

View File

@@ -62,7 +62,6 @@ var ItemList = React.createClass({
return (
<nav>
<ul className="pagination">
{pages}
</ul>
</nav>)

View File

@@ -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
});

View File

@@ -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: