Files
old-ribica/front-ui/app/components/browsing/bySection.js

101 lines
4.3 KiB
JavaScript
Raw Normal View History

2015-01-25 13:38:25 +01:00
var React = require('react'),
Router = require('react-router'),
ItemActions = require('../../actions/itemActions.js'),
ItemStore = require('../../stores/itemStore'),
NavigationStore = require('../../stores/navigationStore'),
ItemList = require('../items/itemList'),
ItemCollection = require('../../models/itemCollection'),
SectionStore = require('../../stores/sectionStore'),
SectionActions = require('../../actions/sectionActions.js'),
2015-01-31 14:49:27 +01:00
NavigationActions = require('../../actions/navigationActions'),
2015-02-07 18:16:21 +01:00
Section = require('../../models/section'),
2015-03-29 12:46:51 +02:00
LinkBanner = require('../linkBanner/linkBanner'),
2015-02-07 18:16:21 +01:00
Category = require('../../models/category');
2015-01-25 13:38:25 +01:00
var BySection = React.createClass({
2015-01-25 16:42:16 +01:00
mixins: [Router.State],
getInitialState : function() {
return {
items: (new ItemCollection()),
section : (new Section())
};
},
2015-01-25 13:38:25 +01:00
render : function() {
var s ={ float: 'left'};
2015-01-31 14:49:27 +01:00
var self = this;
2015-01-25 16:42:16 +01:00
return ( <div>
2015-01-25 13:38:25 +01:00
2015-01-25 16:42:16 +01:00
<div className='col-md-2'>
Here goes section for refining search, by section
</div>
<div className='col-md-10'>
2015-03-29 12:46:51 +02:00
<LinkBanner locationName="section" locationId={Number(this.getParams().id)} />
<div className='h3'>
Najprodavanije u sekciji {this.state.section.get('name')}
</div>
<ItemList items={this.state.items} />
<div className='h3'>Kategorije</div>
<div>
{(this.state.section.get('categories') || []).map(function(category){
return (
<div style={s}>
2015-02-04 06:51:49 +01:00
<a onClick={self.onCategoryClick.bind(self, category, self.state.section)}>
2015-01-31 14:49:27 +01:00
<img src={category.image_url || 'http://www.windeln.de/resources/img/content/kat_windelnwickeln.jpg'}/>
2015-02-04 06:51:49 +01:00
<div>{category.name}</div>
</a>
2015-01-31 14:49:27 +01:00
<ul>
{category.sub_categories.map(function(sc) {
return (<li>{sc.name}</li>)
})}
</ul>
</div>
)
})}
</div>
2015-01-25 16:42:16 +01:00
</div>
</div> )
},
2015-01-31 14:49:27 +01:00
onCategoryClick: function(category, section) {
2015-02-07 18:16:21 +01:00
NavigationActions.goToCategory(new Category(category), section);
2015-01-31 14:49:27 +01:00
},
componentWillReceiveProps: function(nextProps) {
var sectionId = this.getParams().id;
ItemActions.loadBestSellingItemsForSection(sectionId);
SectionActions.loadSectionDetails(sectionId);
},
componentDidMount: function() {
console.log('mounting....');
var sectionId = this.getParams().id;
ItemActions.loadBestSellingItemsForSection(sectionId);
SectionActions.loadSectionDetails(sectionId);
SectionStore.addChangeListener(this._onSectionChange);
ItemStore.addChangeListener(this._onChange);
},
2015-02-04 06:51:49 +01:00
componentWillUnmount: function() {
SectionStore.removeChangeListener(this._onSectionChange);
ItemStore.removeChangeListener(this._onChange);
},
_onSectionChange: function() {
if(this.isMounted()) {
this.setState({
section: SectionStore.getSectionDetails()
});
}
},
_onChange: function() {
if(this.isMounted()) {
console.log('items store changed! by section');
this.setState({items: ItemStore.getBestSellingForSection()});
}
2015-01-25 13:38:25 +01:00
}
});
module.exports = BySection;