+ getInitialState : function() {
+ return {
+ items: (new ItemCollection()),
+ section : (new Section())
+ };
+ },
+ render : function() {
+ var s ={ float: 'left'};
+ var self = this;
+ return (
+
-
- Here goes section for refining search, by section
-
-
-
-
- Najprodavanije u sekciji {this.state.section.get('name')}
-
-
-
Kategorije
-
- {(this.state.section.get('categories') || []).map(function(category){
- return (
-
- )
- })}
+
+
+ {(this.state.section.get('categories')).map(function(category) {
+ return (- {category.name}
)
+ })}
+
+
+
+
+
+ Najprodavanije u sekciji {this.state.section.get('name')}
+
+
+
+ {/*
+
Kategorije
+
+ {(this.state.section.get('categories') || []).map(function(category){
+ return (
+
+ )
+ })}
+
*/}
-
)
- },
- onCategoryClick: function(category, section) {
- NavigationActions.goToCategory(new Category(category), section);
-
- },
- 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);
+
+ )
+ },
+ onCategoryClick: function(category, section) {
+ NavigationActions.goToCategory(new Category(category), section);
- SectionStore.addChangeListener(this._onSectionChange);
- ItemStore.addChangeListener(this._onChange);
- },
- 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()});
- }
+ },
+ 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);
+ },
+ 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()});
+ }
+ }
});
module.exports = BySection;
diff --git a/front-ui/app/models/section.js b/front-ui/app/models/section.js
index a1453bf..c57c86f 100644
--- a/front-ui/app/models/section.js
+++ b/front-ui/app/models/section.js
@@ -4,7 +4,8 @@ var Globals = require('../globals');
var Section = Backbone.Model.extend({
urlRoot : Globals.ApiUrl + '/section',
defaults : {
- name: ''
+ name: '',
+ categories: []
}
});
diff --git a/front-ui/app/stores/sectionStore.js b/front-ui/app/stores/sectionStore.js
index d2614d7..4fa8924 100644
--- a/front-ui/app/stores/sectionStore.js
+++ b/front-ui/app/stores/sectionStore.js
@@ -12,16 +12,16 @@ var sectionState = {
};
-var loadSections = function() {
+var loadSections = function() {
var sections = new SectionCollection();
sections.fetch({success: function() {
sectionState.sections = sections.models;
// change will be called automatically when
// action is run but we need to emit it again
- // when the data arive
+ // when the data arive
// it's a bit "unfluxy" but convenient.
// "true philosophy" would be to run another "data arrived" action
- SectionStore.emitChange();
+ SectionStore.emitChange();
}});
};
@@ -30,6 +30,7 @@ var loadSectionDetails = function(sectionId) {
section.fetch({
success: function() {
_sectionDetails = section;
+ console.log('section details', _sectionDetails);
SectionStore.emitChange();
}
});
@@ -43,7 +44,7 @@ var setHovered = function(id) {
// Extend SectionStore with EventEmitter to add eventing capabilities
var SectionStore = _.extend({}, EventEmitter.prototype, {
- // Return Single Item With Details
+ // Return Single Item With Details
getState: function() {
return sectionState;
},
@@ -77,7 +78,7 @@ AppDispatcher.register(function(payload) {
// Respond to SELECT_ITEM action
case SectionConstants.LOAD_SECTIONS:
- loadSections();
+ loadSections();
break;
case SectionConstants.SET_SECTION_HOVER: