address saving now works - masallah, la hawle we la kuwette ila billah :)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
helpers do
|
helpers do
|
||||||
def anonymous_id
|
def anonymous_id
|
||||||
@@ -55,7 +55,7 @@ update_delivery_destination = ->() {
|
|||||||
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
||||||
cart.delivery_destination.update_attributes(params)
|
cart.delivery_destination.update_attributes(params)
|
||||||
cart.delivery_destination.save!
|
cart.delivery_destination.save!
|
||||||
cart.delivery_destination.to_json
|
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
||||||
}
|
}
|
||||||
put '/cart/delivery_destination', &update_delivery_destination
|
put '/cart/delivery_destination', &update_delivery_destination
|
||||||
post '/cart/delivery_destination', &update_delivery_destination
|
post '/cart/delivery_destination', &update_delivery_destination
|
||||||
@@ -40,7 +40,7 @@ var CartActions = {
|
|||||||
changeDeliveryDestinationProperty: function(property, value) {
|
changeDeliveryDestinationProperty: function(property, value) {
|
||||||
AppDispatcher.handleAction({
|
AppDispatcher.handleAction({
|
||||||
actionType: CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY,
|
actionType: CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY,
|
||||||
property: property,
|
propertyName: property,
|
||||||
value: value
|
value: value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,20 +30,22 @@ var loadCart = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_itemsForDisplay.fetch({
|
_itemsForDisplay.fetch({
|
||||||
success: function() {
|
success: function() {
|
||||||
CartActions.dataLoaded();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
_deliveryDestination.fetch({
|
|
||||||
success: function() {
|
|
||||||
CartActions.dataLoaded();
|
CartActions.dataLoaded();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (!_deliveryDestination.get('id')) {
|
||||||
|
_deliveryDestination.fetch({
|
||||||
|
success: function() {
|
||||||
|
CartActions.dataLoaded();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var addItem = function(itemId) {
|
var addItem = function(itemId) {
|
||||||
|
|
||||||
var state = states[itemId] || new ItemInCart({
|
var state = states[itemId] || new ItemInCart({
|
||||||
item_id: itemId,
|
item_id: itemId,
|
||||||
count: 0
|
count: 0
|
||||||
@@ -54,13 +56,13 @@ var addItem = function(itemId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var takeItemOut = function(itemId) {
|
var takeItemOut = function(itemId) {
|
||||||
|
|
||||||
var state = states[itemId] || new ItemInCart({
|
var state = states[itemId] || new ItemInCart({
|
||||||
item_id: itemId,
|
item_id: itemId,
|
||||||
count: 0
|
count: 0
|
||||||
})
|
})
|
||||||
if (state.get('count') > 0) {
|
if (state.get('count') > 0) {
|
||||||
state.set('count', state.get('count') - 1);
|
state.set('count', state.get('count') - 1);
|
||||||
}
|
}
|
||||||
states[itemId] = state;
|
states[itemId] = state;
|
||||||
saveCartStateForItem(itemId);
|
saveCartStateForItem(itemId);
|
||||||
@@ -69,13 +71,13 @@ var takeItemOut = function(itemId) {
|
|||||||
var saveCartStateForItem = function(itemId) {
|
var saveCartStateForItem = function(itemId) {
|
||||||
var item = CartStore.getStateFor(itemId);
|
var item = CartStore.getStateFor(itemId);
|
||||||
item.save({
|
item.save({
|
||||||
success: function () {
|
success: function() {
|
||||||
CartActions.dataLoaded();
|
CartActions.dataLoaded();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var changeDeliveryDestinationProperty = function (property, value) {
|
var changeDeliveryDestinationProperty = function(property, value) {
|
||||||
_deliveryDestination.set(property, value);
|
_deliveryDestination.set(property, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ var saveDeliveryDestination = function() {
|
|||||||
var CartStore = _.extend({}, EventEmitter.prototype, {
|
var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||||
|
|
||||||
getStateFor: function(itemId) {
|
getStateFor: function(itemId) {
|
||||||
|
|
||||||
var state = states[itemId] || new ItemInCart({
|
var state = states[itemId] || new ItemInCart({
|
||||||
item_id: itemId,
|
item_id: itemId,
|
||||||
count: 0
|
count: 0
|
||||||
@@ -102,16 +104,16 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
|||||||
|
|
||||||
getWholeCartState: function() {
|
getWholeCartState: function() {
|
||||||
|
|
||||||
var numberOfItems = 0;
|
var numberOfItems = 0;
|
||||||
|
|
||||||
for (key in states) {
|
for (key in states) {
|
||||||
if(states.hasOwnProperty(key)){
|
if (states.hasOwnProperty(key)) {
|
||||||
var value = states[key];
|
var value = states[key];
|
||||||
if (value.get('count') > 0) {
|
if (value.get('count') > 0) {
|
||||||
numberOfItems += value.get('count');
|
numberOfItems += value.get('count');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var state = {
|
var state = {
|
||||||
count: numberOfItems,
|
count: numberOfItems,
|
||||||
@@ -144,7 +146,7 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
|||||||
// Register callback with AppDispatcher
|
// Register callback with AppDispatcher
|
||||||
AppDispatcher.register(function(payload) {
|
AppDispatcher.register(function(payload) {
|
||||||
var action = payload.action;
|
var action = payload.action;
|
||||||
var text;
|
var text;
|
||||||
|
|
||||||
switch (action.actionType) {
|
switch (action.actionType) {
|
||||||
|
|
||||||
@@ -163,12 +165,14 @@ AppDispatcher.register(function(payload) {
|
|||||||
// do nothing - jsut emmit change
|
// do nothing - jsut emmit change
|
||||||
break;
|
break;
|
||||||
case CartConstants.SAVE_CART_STATE_FOR_ITEM:
|
case CartConstants.SAVE_CART_STATE_FOR_ITEM:
|
||||||
// saveCartStateForItem(action.itemId);
|
saveCartStateForItem(action.itemId);
|
||||||
break;
|
break;
|
||||||
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
|
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
|
||||||
changeDeliveryDestinationProperty(action.propety, action.value)
|
changeDeliveryDestinationProperty(action.propertyName, action.value)
|
||||||
|
break;
|
||||||
case CartConstants.CONFIRM_DELIVERY:
|
case CartConstants.CONFIRM_DELIVERY:
|
||||||
saveDeliveryDestination();
|
saveDeliveryDestination();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user