stuff not ready to be pushed to master
This commit is contained in:
@@ -52,6 +52,13 @@ var UserActions = {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: UserConstants.USER_LOGOUT_DONE
|
||||
});
|
||||
NavigationActions.goToHome();
|
||||
},
|
||||
clearLogin: function() {
|
||||
console.log('clearing login form');
|
||||
AppDispatcher.handleAction({
|
||||
actionType: UserConstants.USER_LOGIN_CLEAR
|
||||
});
|
||||
},
|
||||
userLogin: function(loginDetails) {
|
||||
AppDispatcher.handleAction({
|
||||
|
||||
@@ -12,10 +12,14 @@ var Login = React.createClass({
|
||||
mixins: [RibicaValidationMixin],
|
||||
componentDidMount:function() {
|
||||
UserStore.addChangeListener(this.onUserStoreChange);
|
||||
UserActions.clearLogin();
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
UserStore.removeChangeListener(this.onUserStoreChange);
|
||||
},
|
||||
componentWillReceiveProps: function() {
|
||||
UserActions.clearLogin();
|
||||
},
|
||||
onUserStoreChange: function() {
|
||||
if(this.isMounted()) {
|
||||
var loginState = UserStore.getLoginState();
|
||||
|
||||
@@ -11,5 +11,6 @@ module.exports = keyMirror({
|
||||
CHECK_LOGIN: null,
|
||||
CHECK_LOGIN_ARRIVED: null,
|
||||
USER_LOGOUT_DONE: null,
|
||||
USER_LOGOUT: null
|
||||
USER_LOGOUT: null,
|
||||
USER_LOGIN_CLEAR: null
|
||||
});
|
||||
|
||||
@@ -8,10 +8,12 @@ var ItemInCartCollection = require('../models/itemInCartCollection');
|
||||
var ItemCollection = require('../models/itemCollection');
|
||||
var DeliveryDestination = require('../models/deliveryDestination');
|
||||
var OrderConfirmation = require('../models/orderConfirmation');
|
||||
|
||||
var globals = require('../globals');
|
||||
var Superagent = require('superagent');
|
||||
var _ = require('underscore');
|
||||
|
||||
var states = {}
|
||||
var initialized = false;
|
||||
|
||||
var _itemsInCart = new ItemInCartCollection();
|
||||
var _itemsForDisplay = new ItemCollection();
|
||||
@@ -19,30 +21,53 @@ _itemsForDisplay.setFromCart(true);
|
||||
var _deliveryDestination = new DeliveryDestination();
|
||||
|
||||
|
||||
var loadCart = function() {
|
||||
_itemsInCart.fetch({
|
||||
success: function() {
|
||||
states = {}
|
||||
for (var i = 0; i < _itemsInCart.models.length; i++) {
|
||||
var itemInCart = _itemsInCart.models[i];
|
||||
states[itemInCart.get('item_id')] = itemInCart;
|
||||
}
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
|
||||
_itemsForDisplay.fetch({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
})
|
||||
if (!_deliveryDestination.get('id')) {
|
||||
_deliveryDestination.fetch({
|
||||
var loadCart = function() {
|
||||
var get = function() {
|
||||
_itemsInCart.fetch({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
states = {}
|
||||
for (var i = 0; i < _itemsInCart.models.length; i++) {
|
||||
var itemInCart = _itemsInCart.models[i];
|
||||
states[itemInCart.get('item_id')] = itemInCart;
|
||||
}
|
||||
//CartActions.dataLoaded();
|
||||
|
||||
_itemsForDisplay.fetch({
|
||||
success: function() {
|
||||
//CartActions.dataLoaded();
|
||||
if (!_deliveryDestination.get('id')) {
|
||||
_deliveryDestination.fetch({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
get();
|
||||
//if(initialized) {
|
||||
//get();
|
||||
//} else {
|
||||
//Superagent
|
||||
//.get(globals.ApiUrl + '/cart/init')
|
||||
//.withCredentials()
|
||||
//.end(function(response) {
|
||||
//if(response.ok) {
|
||||
//initialized = true;
|
||||
//get();
|
||||
//}
|
||||
//});
|
||||
//}
|
||||
};
|
||||
|
||||
|
||||
@@ -201,4 +226,4 @@ AppDispatcher.register(function(payload) {
|
||||
|
||||
});
|
||||
|
||||
module.exports = CartStore;
|
||||
module.exports = CartStore;
|
||||
|
||||
@@ -59,6 +59,12 @@ var handleLogoutDone = function() {
|
||||
}
|
||||
};
|
||||
|
||||
var handleClearLogin = function() {
|
||||
_loginState = {
|
||||
loggedIn: false
|
||||
}
|
||||
};
|
||||
|
||||
// Extend SectionStore with EventEmitter to add eventing capabilities
|
||||
var UserStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
@@ -97,22 +103,25 @@ AppDispatcher.register(function(payload) {
|
||||
|
||||
case UserConstants.REGISTRATION_SUCCESS:
|
||||
handleRegistrationSuccess(action.user);
|
||||
break;
|
||||
break;
|
||||
case UserConstants.REGISTRATION_FAILURE:
|
||||
handleRegistrationFailure(action.error);
|
||||
break;
|
||||
break;
|
||||
case UserConstants.LOGIN_SUCCESS:
|
||||
handleLoginSuccess(action.user);
|
||||
break;
|
||||
break;
|
||||
case UserConstants.LOGIN_FAILURE:
|
||||
handleLoginFailure(action.error);
|
||||
break;
|
||||
break;
|
||||
case UserConstants.CHECK_LOGIN_ARRIVED:
|
||||
handleCheckLoginArrived(action.user, action.error);
|
||||
break;
|
||||
handleCheckLoginArrived(action.user, action.error);
|
||||
break;
|
||||
case UserConstants.USER_LOGOUT_DONE:
|
||||
handleLogoutDone();
|
||||
break;
|
||||
handleLogoutDone();
|
||||
break;
|
||||
case UserConstants.USER_LOGIN_CLEAR:
|
||||
handleClearLogin();
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user