@@ -42,6 +43,10 @@ var CartIcon = React.createClass({
componentWillUnmount: function () {
CartStore.removeChangeListener(this._onChange);
+ },
+
+ _onClick: function() {
+ NavigationActions.goToCart();
}
diff --git a/front-ui/app/components/cart/cartPage.js b/front-ui/app/components/cart/cartPage.js
index cc2b61d..a144bd8 100644
--- a/front-ui/app/components/cart/cartPage.js
+++ b/front-ui/app/components/cart/cartPage.js
@@ -1,5 +1,8 @@
var React = require('react'),
CartStore = require('../../stores/cartStore'),
+ AddToCart = require('../cart/addToCart'),
+ CartActions = require('../../actions/cartActions'),
+ SingleItem = require('../items/singleItem'),
AddToCart = require('../cart/addToCart');
var Router = require('react-router');
@@ -9,11 +12,19 @@ var ItemWithDetailsPage = React.createClass({
render: function() {
+ var displayedItems = this.state.items.map(function (i) {
+ return (
+
- This is the cart page!
-
+
+ {displayedItems}
);
@@ -22,7 +33,7 @@ var ItemWithDetailsPage = React.createClass({
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
-
+ CartActions.load();
},
componentWillUnmount: function () {
@@ -30,15 +41,14 @@ var ItemWithDetailsPage = React.createClass({
},
_onChange: function () {
-
if (this.isMounted()) {
- this.setState(ItemDetailsStore.getState());
+ this.setState(CartStore.getWholeCartState());
}
},
getInitialState: function () {
- return CartStore.getState();
+ return CartStore.getWholeCartState();
}
});
diff --git a/front-ui/app/css/cart.css b/front-ui/app/css/cart.css
index 231cf34..6a054cf 100644
--- a/front-ui/app/css/cart.css
+++ b/front-ui/app/css/cart.css
@@ -6,6 +6,7 @@
display: inline-block;
position: relative;
border-radius: 25px;
+ cursor: pointer;
}
.shopping-cart-notification-text {
diff --git a/front-ui/app/models/itemCollection.js b/front-ui/app/models/itemCollection.js
index 914d92b..4d94b70 100644
--- a/front-ui/app/models/itemCollection.js
+++ b/front-ui/app/models/itemCollection.js
@@ -4,56 +4,75 @@ var Backbone = require('backbone'),
var ItemCollection = Backbone.Collection.extend({
- addFilter : function(name, value) {
- this.filters = this.filters || {};
- this.filters[name] = value;
- },
- clearFilter: function() {
- this.filters = [];
+ initialize: function() {
+ $.ajaxPrefilter(
+ function(options, originalOptions, jqXHR) {
+ options.xhrFields = {
+ withCredentials: true
+ }
+ }
+ );
},
- setLimit: function(limit) {
- this.queryLimit = limit;
+
+ addFilter: function(name, value) {
+ this.filters = this.filters || {};
+ this.filters[name] = value;
+ },
+ clearFilter: function() {
+ this.filters = [];
+ },
+ setLimit: function(limit) {
+ this.queryLimit = limit;
},
setOffset: function(offset) {
- this.offset = offset;
+ this.offset = offset;
},
- classificationTypeUrlParts: ['','section','category','sub_category'],
+ classificationTypeUrlParts: ['', 'section', 'category', 'sub_category'],
setClassificationType: function(type) {
- this.classificationType = type;
- } ,
+ this.classificationType = type;
+ },
setClassificationId: function(id) {
- this.classificationId = id;
- },
+ this.classificationId = id;
+ },
+
+ setFromCart: function(fromCart) {
+ this.fromCart = fromCart;
+ },
model: Item,
- url: function() {
- var path = '/item'
- if(this.classificationType > 0) {
- // eg. http://localhost:4567/item/section/1/offset/0/limit/10
- var urlPart = this.classificationTypeUrlParts[this.classificationType];
- path += "/" + urlPart + "/" + this.classificationId;
- } // else eg. http://localhost:4567/item/offset/0/limit/10
- path += "/offset/" + this.offset + "/limit/" + this.queryLimit;
-
- var queryParts = [];
-
- for(var key in this.filters) {
- if (this.filters.hasOwnProperty(key)) {
- queryParts.push(key + '=' + this.filters[key]);
+ url: function() {
+ if (this.fromCart === true) {
+ return Globals.ApiUrl + "/cart/item/display";
}
- }
- var query = '';
- if (queryParts.length > 0) {
- query = '?' + queryParts.join('&');
- }
+ var path = '/item';
- return Globals.ApiUrl + path + query;
+ if (this.classificationType > 0) {
+ // eg. http://localhost:4567/item/section/1/offset/0/limit/10
+ var urlPart = this.classificationTypeUrlParts[this.classificationType];
+ path += "/" + urlPart + "/" + this.classificationId;
+ } // else eg. http://localhost:4567/item/offset/0/limit/10
+ path += "/offset/" + this.offset + "/limit/" + this.queryLimit;
+
+ var queryParts = [];
+
+ for (var key in this.filters) {
+ if (this.filters.hasOwnProperty(key)) {
+ queryParts.push(key + '=' + this.filters[key]);
+ }
+ }
+ var query = '';
+
+ if (queryParts.length > 0) {
+ query = '?' + queryParts.join('&');
+ }
+
+ return Globals.ApiUrl + path + query;
}
});
-module.exports = ItemCollection;
+module.exports = ItemCollection;
\ No newline at end of file
diff --git a/front-ui/app/router.js b/front-ui/app/router.js
index c99c628..596713b 100644
--- a/front-ui/app/router.js
+++ b/front-ui/app/router.js
@@ -8,6 +8,7 @@ var ItemWithDetailsPage = require('./components/items/itemWithDetailsPage');
var ItemList = require('./components/items/itemList');
var SectionsListComponent = require('./components/shared/sectionsListComponent');
var AllItems = require('./components/items/allItems');
+var CartPage = require('./components/cart/cartPage');
var RootApp = require('./components/rootApp');
var StartPage = require('./components/startPage/startPage');
var ByCategory = require('./components/browsing/byCategory');
@@ -18,6 +19,7 @@ var routes = (
+
diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js
index 129dce9..880621f 100644
--- a/front-ui/app/stores/cartStore.js
+++ b/front-ui/app/stores/cartStore.js
@@ -4,11 +4,15 @@ var CartConstants = require('../constants/cartConstants');
var CartActions = require('../actions/cartActions');
var ItemInCart = require('../models/itemInCart');
var ItemInCartCollection = require('../models/itemInCartCollection');
+var ItemCollection = require('../models/itemCollection');
+
var _ = require('underscore');
var states = {}
var _itemsInCart = new ItemInCartCollection();
+var _itemsForDisplay = new ItemCollection();
+_itemsForDisplay.setFromCart(true);
var loadCart = function() {
@@ -21,9 +25,16 @@ var loadCart = function() {
}
CartActions.dataLoaded();
}
+ });
+
+ _itemsForDisplay.fetch({
+ success: function() {
+ CartActions.dataLoaded();
+ }
})
};
+
var addItem = function(itemId) {
var state = states[itemId] || new ItemInCart({
@@ -56,6 +67,10 @@ var saveCartStateForItem = function(itemId) {
}
});
}
+/*
+var syncCountsWithDetails = function() {
+ for(i in )
+}*/
@@ -86,7 +101,8 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
};
var state = {
- count: numberOfItems
+ count: numberOfItems,
+ items: _itemsForDisplay
};
return state;
},
@@ -129,10 +145,10 @@ AppDispatcher.register(function(payload) {
takeItemOut(action.itemId);
break;
case CartConstants.CART_DATA_LOADED:
- // just emit change
+ // do nothing - jsut emmit change
break;
case CartConstants.SAVE_CART_STATE_FOR_ITEM:
- saveCartStateForItem(action.itemId);
+ // saveCartStateForItem(action.itemId);
break;
default:
return true;