diff --git a/front-ui/app/actions/cartActions.js b/front-ui/app/actions/cartActions.js index 4da0adc..297b456 100644 --- a/front-ui/app/actions/cartActions.js +++ b/front-ui/app/actions/cartActions.js @@ -10,24 +10,10 @@ var CartActions = { }); }, - addItem: function(itemId) { - AppDispatcher.handleAction({ - actionType: CartConstants.ADD_ITEM, - itemId: itemId - }); - }, - - takeItemOut: function(itemId) { - AppDispatcher.handleAction({ - actionType: CartConstants.TAKE_ITEM_OUT, - itemId: itemId - }); - }, - - setItemCount: function(itemId, count) { + setItemCount: function(item, count) { AppDispatcher.handleAction({ actionType: CartConstants.SET_ITEM_COUNT, - itemId: itemId, + item: item, count: count }); }, diff --git a/front-ui/app/actions/navigationActions.js b/front-ui/app/actions/navigationActions.js index 1e7c978..889df5c 100644 --- a/front-ui/app/actions/navigationActions.js +++ b/front-ui/app/actions/navigationActions.js @@ -5,7 +5,7 @@ var NavigationConstants = require('../constants/navigationConstants'); var NavigationActions = { // select item goToItemDetails: function(item) { - console.log("Going to item details"); + AppDispatcher.handleAction({ actionType: NavigationConstants.CHANGE_URL, url: '/artikal/' + item.get('id') +'/' + item.get('name') @@ -13,7 +13,6 @@ var NavigationActions = { }, goToSection: function(section) { - console.log("Going to item details"); AppDispatcher.handleAction({ actionType: NavigationConstants.CHANGE_URL, url: '/sekcija/'+ section.get('id') + '/' + section.get('name') diff --git a/front-ui/app/components/browsing/bySection.js b/front-ui/app/components/browsing/bySection.js index 164d506..c276a83 100644 --- a/front-ui/app/components/browsing/bySection.js +++ b/front-ui/app/components/browsing/bySection.js @@ -91,7 +91,7 @@ var BySection = React.createClass({ SectionActions.loadSectionDetails(sectionId); }, componentDidMount: function() { - console.log('mounting....'); + var sectionId = this.getParams().id; ItemActions.loadBestSellingItemsForSection(sectionId); SectionActions.loadSectionDetails(sectionId); @@ -112,7 +112,7 @@ var BySection = React.createClass({ }, _onChange: function() { if(this.isMounted()) { - console.log('items store changed! by section'); + this.setState({items: ItemStore.getBestSellingForSection()}); } } diff --git a/front-ui/app/components/cart/addToCart.js b/front-ui/app/components/cart/addToCart.js index 62c324a..8a3dc3f 100644 --- a/front-ui/app/components/cart/addToCart.js +++ b/front-ui/app/components/cart/addToCart.js @@ -35,12 +35,15 @@ var AddToCart = React.createClass({ // Add change listeners to stores componentDidMount: function() { CartStore.addChangeListener(this._onChange); - CartActions.load(); + + if(!CartStore.dataStartedLoading()) { + CartActions.load(); + }; }, getInitialState: function() { - var itemInCart = CartStore.getStateFor(this.props.itemId); + var itemInCart = CartStore.getStateFor(this.props.item.get('id')); return { item: itemInCart, count: 0 @@ -50,13 +53,13 @@ var AddToCart = React.createClass({ _onChange: function () { if (this.isMounted()) { - var item = CartStore.getStateFor(this.props.itemId); + var item = CartStore.getStateFor(this.props.item.get('id')); this.setState({ item: item, count: 0 }); } }, _onIncreaseClick: function () { - //CartActions.addItem(this.props.itemId); + if (this.state.count < Globals.MaxNumberOfItemsToBeAdded ) { this.state.count = this.state.count + 1; this.setState(this.state); @@ -64,7 +67,7 @@ var AddToCart = React.createClass({ }, _onDecreaseClick: function () { - // CartActions.takeItemOut(this.props.itemId); + if (this.state.count > 0) { this.state.count = this.state.count - 1; this.setState(this.state); @@ -72,7 +75,7 @@ var AddToCart = React.createClass({ }, _addToCartClick: function () { - CartActions.setItemCount(this.props.itemId, this.state.count); + CartActions.setItemCount(this.props.item, this.state.count); }, componentWillUnmount: function () { diff --git a/front-ui/app/components/cart/cartIcon.js b/front-ui/app/components/cart/cartIcon.js index ae31adf..23e4cca 100644 --- a/front-ui/app/components/cart/cartIcon.js +++ b/front-ui/app/components/cart/cartIcon.js @@ -40,7 +40,9 @@ var CartIcon = React.createClass({ // Add change listeners to stores componentDidMount: function() { CartStore.addChangeListener(this._onChange); - CartActions.load(); + if(!CartStore.dataStartedLoading()) { + CartActions.load(); + }; }, @@ -51,6 +53,7 @@ var CartIcon = React.createClass({ _onChange: function () { if (this.isMounted()) { + this.setState(CartStore.getWholeCartState()); } }, diff --git a/front-ui/app/components/cart/cartPage.js b/front-ui/app/components/cart/cartPage.js index 4accbe9..f25a1b3 100644 --- a/front-ui/app/components/cart/cartPage.js +++ b/front-ui/app/components/cart/cartPage.js @@ -27,7 +27,8 @@ var CartPage = React.createClass({
{ Globals.FormatCurrency(price) }
-
+
+ 42
{ Globals.FormatCurrency(count * price) }
@@ -65,7 +66,7 @@ var CartPage = React.createClass({ }; - console.log("length :" , this.state.items.length); + return ( diff --git a/front-ui/app/components/cart/cartTotal.js b/front-ui/app/components/cart/cartTotal.js index 925f759..3b54bc3 100644 --- a/front-ui/app/components/cart/cartTotal.js +++ b/front-ui/app/components/cart/cartTotal.js @@ -8,42 +8,25 @@ var Router = require('react-router'); var CartTotal = React.createClass({ - render: function() { + render: function() { + + var counts = this.props.itemCounts; var total = 0; - this.props.items.map(function (i) { - var count = counts[i.get('id')].get('count'); - var price = i.get('list_price'); + var items = this.props.items.models; + + for (var i = 0; i < items.length; i++) { + var item = items[i]; + var count = counts[item.get('id')].get('count'); + var price = item.get('list_price'); total += (price * count) - return total; + }; - }); - var deliveryCosts = this.props.deliveryCosts.get('delivery_price'); - - if (!this.props.justMerchandise) { - - return ( -
-
- Roba: {Globals.FormatCurrency(total)} -
-
- Dostava: {Globals.FormatCurrency(deliveryCosts)} -
-
- Ukupno: {Globals.FormatCurrency(total + (+deliveryCosts))} -
- -
- ); - - } - else { - return ( {Globals.FormatCurrency(total)}); - } + + return ( {Globals.FormatCurrency(total)}); } diff --git a/front-ui/app/components/items/itemWithDetailsPage.js b/front-ui/app/components/items/itemWithDetailsPage.js index 8f5f6f0..b1f121e 100644 --- a/front-ui/app/components/items/itemWithDetailsPage.js +++ b/front-ui/app/components/items/itemWithDetailsPage.js @@ -25,10 +25,10 @@ var ItemWithDetailsPage = React.createClass({
{this.state.item.get('name')}
{this.state.item.get('list_price')} KM
- +
Količina
-
+
{this.state.item.get('description')}
diff --git a/front-ui/app/components/items/singleItem.js b/front-ui/app/components/items/singleItem.js index 016cc62..5add52e 100644 --- a/front-ui/app/components/items/singleItem.js +++ b/front-ui/app/components/items/singleItem.js @@ -44,7 +44,7 @@ var SingleItem = React.createClass({ itemClick: function(e) { NavigationActions.goToItemDetails(this.props.item); - console.log(this.props.item) + } }); diff --git a/front-ui/app/constants/cartConstants.js b/front-ui/app/constants/cartConstants.js index 4a62ba0..58a8068 100644 --- a/front-ui/app/constants/cartConstants.js +++ b/front-ui/app/constants/cartConstants.js @@ -3,8 +3,6 @@ var keyMirror = require('react/lib/keyMirror'); // Define action constants module.exports = keyMirror({ LOAD_CART_CONTENTS: null, - ADD_ITEM: null, - TAKE_ITEM_OUT: null , CART_DATA_LOADED: null, SAVE_CART_STATE_FOR_ITEM: null, CHANGE_DELIVERY_DESTINATION_PROPERTY: null, diff --git a/front-ui/app/dispatcher/appDispatcher.js b/front-ui/app/dispatcher/appDispatcher.js index e8e6b14..3bab3b1 100644 --- a/front-ui/app/dispatcher/appDispatcher.js +++ b/front-ui/app/dispatcher/appDispatcher.js @@ -10,7 +10,7 @@ AppDispatcher.handleAction = function(action) { action: action }); - console.log("Dispatching:", action); + } module.exports = AppDispatcher; \ No newline at end of file diff --git a/front-ui/app/stores/bySubCategoryStore.js b/front-ui/app/stores/bySubCategoryStore.js index 578a82a..8c2d8fd 100644 --- a/front-ui/app/stores/bySubCategoryStore.js +++ b/front-ui/app/stores/bySubCategoryStore.js @@ -106,7 +106,7 @@ var BySubCategoryStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("Emmiting BySubCategory change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js index 7a387d8..57ac382 100644 --- a/front-ui/app/stores/cartStore.js +++ b/front-ui/app/stores/cartStore.js @@ -24,8 +24,12 @@ var _deliveryCosts = new Place({ postalCode: _deliveryDestination.get('place') }) +var _cartDataLoadCalled = false; + var loadCart = function() { + + states = {}; _itemsInCart.fetch({ success: function() { states = {} @@ -50,8 +54,10 @@ var loadCart = function() { CartActions.dataLoaded(); } }); + + _cartDataLoadCalled = true; -}; +}; var fetchPlace = function() { @@ -71,22 +77,12 @@ var saveCartStateForItem = function(itemId) { var item = CartStore.getStateFor(itemId); item.save({ success: function() { - CartActions.dataLoaded(); + loadCart(); } }); }; -var addItem = function(itemId) { - - var state = states[itemId] || new ItemInCart({ - item_id: itemId, - count: 0 - }) - state.set('count', state.get('count') + 1); - states[itemId] = state; - saveCartStateForItem(itemId); - -}; +/* need it for delete - will delete it later var takeItemOut = function(itemId) { @@ -101,15 +97,20 @@ var takeItemOut = function(itemId) { saveCartStateForItem(itemId); }; -var setItemCount = function(itemId, count) { +*/ + +var setItemCount = function(item, count) { + + var itemId = item.get('id'); var state = states[itemId] || new ItemInCart({ item_id: itemId, count: 0 }) - console.log("Old state", state.get('count')); + + _itemsForDisplay.add(item); state.set('count', state.get('count') + count); - console.log("New state", state.get('count')); + states[itemId] = state; saveCartStateForItem(itemId); } @@ -125,7 +126,7 @@ var changeDeliveryDestinationProperty = function(property, value) { var confirmOrder = function() { - console.log("confirming"); + var oc = new OrderConfirmation({ hamo: 'meho' }); @@ -133,7 +134,7 @@ var confirmOrder = function() { b: 'b' }, { success: function() { - console.log("done"); + NavigationActions.goToThankYou(); loadCart(); } @@ -142,10 +143,9 @@ var confirmOrder = function() { var saveDeliveryDestination = function() { - console.log("saving delivery destination"); _deliveryDestination.save(null, { success: function() { - console.log("saved delivery destination"); + confirmOrder(); } }) @@ -197,6 +197,10 @@ var isDeliveryDestinationValid = function() { // Extend CartStore with EventEmitter to add eventing capabilities var CartStore = _.extend({}, EventEmitter.prototype, { + dataStartedLoading: function() { + return _cartDataLoadCalled; + }, + getStateFor: function(itemId) { var state = states[itemId] || new ItemInCart({ @@ -234,7 +238,6 @@ var CartStore = _.extend({}, EventEmitter.prototype, { // Emit Change event emitChange: function() { - console.log("Emitting cart change!"); this.emit('change'); }, @@ -288,7 +291,7 @@ AppDispatcher.register(function(payload) { saveDeliveryDestination(); break; case CartConstants.SET_ITEM_COUNT: - setItemCount(action.itemId, action.count); + setItemCount(action.item, action.count); break; default: return true; diff --git a/front-ui/app/stores/categoryStore.js b/front-ui/app/stores/categoryStore.js index 415ab86..b256e89 100644 --- a/front-ui/app/stores/categoryStore.js +++ b/front-ui/app/stores/categoryStore.js @@ -45,7 +45,7 @@ var CategoryStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("Emmiting Section change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/initializationStore.js b/front-ui/app/stores/initializationStore.js index 0b688e2..9dc64e9 100644 --- a/front-ui/app/stores/initializationStore.js +++ b/front-ui/app/stores/initializationStore.js @@ -106,7 +106,7 @@ var InitializationStore = _.extend({}, EventEmitter.prototype, { // Emit Change event emitChange: function() { - console.log("InitializationStore change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/itemDetailsStore.js b/front-ui/app/stores/itemDetailsStore.js index 0c48b93..aa9ce80 100644 --- a/front-ui/app/stores/itemDetailsStore.js +++ b/front-ui/app/stores/itemDetailsStore.js @@ -19,7 +19,7 @@ var getItemIdFromUrl = function() { var url = document.URL; var itemIdRegex = /artikal\/(\d+)\//g; var match = itemIdRegex.exec(url); - console.log(match); + return match[1]; }; @@ -95,7 +95,6 @@ var ItemWithDetailsStore = _.extend({}, EventEmitter.prototype, { // Emit Change event emitChange: function() { - console.log("Emitting change!"); this.emit('change'); }, diff --git a/front-ui/app/stores/itemStore.js b/front-ui/app/stores/itemStore.js index 80ee48c..37a89d6 100644 --- a/front-ui/app/stores/itemStore.js +++ b/front-ui/app/stores/itemStore.js @@ -33,7 +33,7 @@ var getItemIdFromUrl = function() { var url = document.URL; var itemIdRegex = /artikal\/(\d+)\//g; var match = itemIdRegex.exec(url); - console.log(match); + return match[1]; }; @@ -80,7 +80,7 @@ var fetchItemsByCategory = function(categoryId, offset, limit, query) { }; var fetchBestSellingItemsForSection = function(sectionId) { - console.log('getting section', sectionId); + var items = _bestSellingForSection; items.setClassificationType(1); items.setClassificationId(sectionId); @@ -96,7 +96,7 @@ var fetchBestSellingItemsForSection = function(sectionId) { var fetchBestSellingItemsForGroup = function(groupId) { - console.log('getting group', groupId); + var items = _bestSellingForGroup; items.setClassificationType(4); items.setClassificationId(groupId); @@ -138,7 +138,7 @@ var ItemStore = _.extend({}, EventEmitter.prototype, { // Emit Change event emitChange: function() { - console.log("Emitting change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/menuItemStore.js b/front-ui/app/stores/menuItemStore.js index 252bc00..d5036c3 100644 --- a/front-ui/app/stores/menuItemStore.js +++ b/front-ui/app/stores/menuItemStore.js @@ -38,7 +38,6 @@ var MenuItemStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("Emmiting MenuItemStore change!"); this.emit('change'); }, diff --git a/front-ui/app/stores/navigationStore.js b/front-ui/app/stores/navigationStore.js index d9ce8f8..ac6d28a 100644 --- a/front-ui/app/stores/navigationStore.js +++ b/front-ui/app/stores/navigationStore.js @@ -9,7 +9,6 @@ var _ = require('underscore'); var getGroupIdFromUrl = function() { - console.log("yeee" , match); // ugly but it seems to me that // router does not want to expose its // state (for phylosophical reasons) @@ -31,7 +30,6 @@ var NavigationStore = _.extend({}, EventEmitter.prototype, { // Emit Change event emitChange: function() { - console.log("NavigationStore change!"); this.emit('change'); }, diff --git a/front-ui/app/stores/searchStore.js b/front-ui/app/stores/searchStore.js index 5a58ba1..6797a45 100644 --- a/front-ui/app/stores/searchStore.js +++ b/front-ui/app/stores/searchStore.js @@ -46,7 +46,7 @@ var SearchStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("SearchStore change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/sectionStore.js b/front-ui/app/stores/sectionStore.js index 4fa8924..ef3c068 100644 --- a/front-ui/app/stores/sectionStore.js +++ b/front-ui/app/stores/sectionStore.js @@ -30,7 +30,7 @@ var loadSectionDetails = function(sectionId) { section.fetch({ success: function() { _sectionDetails = section; - console.log('section details', _sectionDetails); + SectionStore.emitChange(); } }); @@ -53,7 +53,7 @@ var SectionStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("Emmiting Section change!"); + this.emit('change'); }, diff --git a/front-ui/app/stores/userStore.js b/front-ui/app/stores/userStore.js index 3f8b066..d2261e9 100644 --- a/front-ui/app/stores/userStore.js +++ b/front-ui/app/stores/userStore.js @@ -23,8 +23,6 @@ var handleRegistrationFailure = function(error) { error: error }; - - console.log('ERROR JE: ', error); }; var handleLoginSuccess = function(user) { @@ -92,7 +90,6 @@ var UserStore = _.extend({}, EventEmitter.prototype, { }, // Emit Change event emitChange: function() { - console.log("Emmiting Section change!"); this.emit('change'); },