byCategory component small refactoring
This commit is contained in:
@@ -9,7 +9,8 @@ var React = require('react'),
|
|||||||
ItemStore = require('../../stores/itemStore'),
|
ItemStore = require('../../stores/itemStore'),
|
||||||
NavigationStore = require('../../stores/navigationStore'),
|
NavigationStore = require('../../stores/navigationStore'),
|
||||||
ItemList = require('../items/itemList'),
|
ItemList = require('../items/itemList'),
|
||||||
NavigationActions = require('../../actions/navigationActions');
|
NavigationActions = require('../../actions/navigationActions'),
|
||||||
|
Globals = require('../../globals');
|
||||||
|
|
||||||
var ByCategory = React.createClass({
|
var ByCategory = React.createClass({
|
||||||
mixins: [Router.State],
|
mixins: [Router.State],
|
||||||
@@ -51,9 +52,9 @@ var ByCategory = React.createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className='col-md-2'>
|
<div className='col-md-2'>
|
||||||
<div className='h4'>{this.state.category.get('name')}</div>
|
<div className='h4'>{this.state.category.get('name')}</div>
|
||||||
<div>Podkategorije</div>
|
<div>Podkategorije</div>
|
||||||
<ul>
|
<ul>
|
||||||
{(this.state.category.get('sub_categories') || []).map(function(sc) {
|
{(this.state.category.get('sub_categories') || []).map(function(sc) {
|
||||||
return (<li> <a>{sc.name}</a></li>)
|
return (<li> <a>{sc.name}</a></li>)
|
||||||
@@ -104,13 +105,12 @@ var ByCategory = React.createClass({
|
|||||||
}
|
}
|
||||||
return filters;
|
return filters;
|
||||||
},
|
},
|
||||||
componentWillReceiveProps: function() {
|
update: function() {
|
||||||
var categoryId = this.getParams().id;
|
var categoryId = this.getParams().id;
|
||||||
|
|
||||||
this.filter = this.getQuery();
|
this.filter = this.getQuery();
|
||||||
var offset = this.filter.offset || 0;
|
var offset = this.filter.offset || 0;
|
||||||
var limit = this.filter.limit || 30;
|
var limit = this.filter.limit || Globals.DefaultPageSize;
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
filter: this.filter,
|
filter: this.filter,
|
||||||
@@ -122,23 +122,11 @@ var ByCategory = React.createClass({
|
|||||||
ItemActions.loadByCategory(categoryId, offset, limit, this.filter);
|
ItemActions.loadByCategory(categoryId, offset, limit, this.filter);
|
||||||
CategoryActions.loadCategoryDetails(categoryId);
|
CategoryActions.loadCategoryDetails(categoryId);
|
||||||
},
|
},
|
||||||
|
componentWillReceiveProps: function() {
|
||||||
|
this.update();
|
||||||
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
var categoryId = this.getParams().id;
|
this.update();
|
||||||
|
|
||||||
this.filter = this.getQuery();
|
|
||||||
|
|
||||||
var offset = this.filter.offset || 0;
|
|
||||||
var limit = this.filter.limit || 30;
|
|
||||||
this.setState({
|
|
||||||
filter: this.filter,
|
|
||||||
pagination: {
|
|
||||||
offset: offset,
|
|
||||||
limit: limit
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ItemActions.loadByCategory(categoryId, offset, limit, this.getQuery());
|
|
||||||
CategoryActions.loadCategoryDetails(categoryId);
|
|
||||||
|
|
||||||
ItemStore.addChangeListener(this._onChange);
|
ItemStore.addChangeListener(this._onChange);
|
||||||
CategoryStore.addChangeListener(this._onChange);
|
CategoryStore.addChangeListener(this._onChange);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
ApiUrl: 'http://localhost:4567',
|
ApiUrl: 'http://localhost:4567',
|
||||||
|
DefaultPageSize: 18,
|
||||||
FormatCurrency: function(amount_s) {
|
FormatCurrency: function(amount_s) {
|
||||||
var amount = parseFloat(amount_s);
|
var amount = parseFloat(amount_s);
|
||||||
return ( amount.toFixed(2) + " KM" )
|
return ( amount.toFixed(2) + " KM" )
|
||||||
|
|||||||
Reference in New Issue
Block a user