Gift support changes
This commit is contained in:
@@ -7,7 +7,6 @@ var ItemInCart = require('../models/itemInCart');
|
||||
var ItemInCartCollection = require('../models/itemInCartCollection');
|
||||
var ItemCollection = require('../models/itemCollection');
|
||||
var DeliveryDestination = require('../models/deliveryDestination');
|
||||
var RecipientDestination = require('../models/recipientDestination');
|
||||
var OrderConfirmation = require('../models/orderConfirmation');
|
||||
var Place = require('../models/place');
|
||||
var Validation = require('../utils/validation');
|
||||
@@ -26,12 +25,6 @@ var _deliveryCosts = new Place({
|
||||
postalCode: _deliveryDestination.get('place')
|
||||
});
|
||||
|
||||
var _recipientDestination = new RecipientDestination();
|
||||
var _recipientDestinationErrors = {};
|
||||
var _recipientCosts = new Place({
|
||||
postalCode: _recipientDestination.get('place')
|
||||
});
|
||||
|
||||
var _addressColapsed = false;
|
||||
|
||||
var supportedPlaces = [{
|
||||
@@ -2610,9 +2603,12 @@ var collapseAddressIfNeeded = function() {
|
||||
}
|
||||
}
|
||||
|
||||
var fetchPlace = function() {
|
||||
var fetchPlace = function(gift) {
|
||||
gift = gift === true;
|
||||
postalCode = gift ? _deliveryDestination.get('recipient_place') : _deliveryDestination.get('place')
|
||||
|
||||
_deliveryCosts = new Place({
|
||||
postalCode: _deliveryDestination.get('place')
|
||||
postalCode: postalCode
|
||||
})
|
||||
_deliveryCosts.fetch({
|
||||
success: function() {
|
||||
@@ -2704,18 +2700,11 @@ var changeDeliveryDestinationProperty = function(property, value) {
|
||||
if (property === 'place') {
|
||||
fetchPlace();
|
||||
}
|
||||
|
||||
validateDeliveryDestinationForm();
|
||||
};
|
||||
|
||||
var changeRecipientDestinationProperty = function(property, value) {
|
||||
_recipientDestination.set(property, value);
|
||||
|
||||
if (property === 'place') {
|
||||
fetchPlace();
|
||||
if (property === 'recipient_place') {
|
||||
fetchPlace(true);
|
||||
}
|
||||
|
||||
validateRecipientDestinationForm();
|
||||
validateDeliveryDestinationForm();
|
||||
};
|
||||
|
||||
var confirmOrder = function() {
|
||||
@@ -2744,11 +2733,10 @@ var saveDeliveryDestinationAnd = function(successCallback) {
|
||||
|
||||
var saveDeliveryDestination = function() {
|
||||
_deliveryDestination.save(null, {
|
||||
success: function() {
|
||||
|
||||
confirmOrder();
|
||||
}
|
||||
})
|
||||
success: function() {
|
||||
confirmOrder();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var validateDeliveryDestinationForm = function() {
|
||||
@@ -2779,46 +2767,34 @@ var validateDeliveryDestinationForm = function() {
|
||||
_deliveryDestinationErrors['place'] = "Mjesto mora biti izabrano";
|
||||
}
|
||||
|
||||
if(_deliveryDestination.get('gift')) {
|
||||
if (Validation.safeString(_deliveryDestination.get('recipient_name')).search(nameRegex) < 0) {
|
||||
_deliveryDestinationErrors['recipient_name'] = "I prezime i ime su obavezni";
|
||||
}
|
||||
|
||||
if (Validation.safeString(_deliveryDestination.get('recipient_address')).search(addressRegex) < 0) {
|
||||
_deliveryDestinationErrors['recipient_address'] = "Adresa mora biti ispravna";
|
||||
}
|
||||
|
||||
if (_deliveryDestination.get('recipient_email') && Validation.safeString(_deliveryDestination.get('recipient_email')).search(emailRegex) < 0) {
|
||||
_deliveryDestinationErrors['recipient_email'] = "Email mora biti ispravno upisan";
|
||||
}
|
||||
|
||||
if (Validation.safeString(_deliveryDestination.get('recipient_phone')).search(phoneRegex) < 0) {
|
||||
_deliveryDestinationErrors['recipient_phone'] = "Telefon mora biti ispravan";
|
||||
}
|
||||
|
||||
if (Validation.safeString(_deliveryDestination.get('recipient_place')).search(placeRegex) < 0) {
|
||||
_deliveryDestinationErrors['recipient_place'] = "Mjesto mora biti izabrano";
|
||||
}
|
||||
}
|
||||
|
||||
var requiredFields = ["name", "email", "place", 'address', 'phone'];
|
||||
for (var i in requiredFields) {
|
||||
var value = _deliveryDestination.get(requiredFields[i]);
|
||||
if (value === undefined || value === null || value === "") {
|
||||
// if it's required there will be a star there
|
||||
_deliveryDestinationErrors[requiredFields[i]] = "*";
|
||||
}
|
||||
|
||||
if(_deliveryDestination.get('gift')) {
|
||||
requiredFields = requiredFields.concat(["recipient_name", "recipient_place", 'recipient_address', 'recipient_phone']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var validateRecipientDestinationForm = function() {
|
||||
_recipientDestinationErrors = {};
|
||||
|
||||
var nameRegex = /.+\s+.+/i;
|
||||
if (Validation.safeString(_recipientDestinationErrors.get('name')).search(nameRegex) < 0) {
|
||||
_recipientDestinationErrors['name'] = "I prezime i ime su obavezni";
|
||||
}
|
||||
|
||||
var addressRegex = /.+\s+.+/i;
|
||||
if (Validation.safeString(_recipientDestinationErrors.get('address')).search(addressRegex) < 0) {
|
||||
_recipientDestinationErrors['address'] = "Adresa mora biti ispravna";
|
||||
}
|
||||
|
||||
var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/i;
|
||||
if (Validation.safeString(_recipientDestinationErrors.get('email')).search(emailRegex) < 0) {
|
||||
_recipientDestinationErrors['email'] = "Email mora biti ispravno upisan";
|
||||
}
|
||||
|
||||
var phoneRegex = /^[\d\s-]{8,12}$/i;
|
||||
if (Validation.safeString(_recipientDestinationErrors.get('phone')).search(phoneRegex) < 0) {
|
||||
_recipientDestinationErrors['phone'] = "Telefon mora biti ispravan";
|
||||
}
|
||||
|
||||
var placeRegex = /^\s{0,1}\d{5}$/i;
|
||||
if (Validation.safeString(_recipientDestinationErrors.get('place')).search(placeRegex) < 0) {
|
||||
_recipientDestinationErrors['place'] = "Mjesto mora biti izabrano";
|
||||
}
|
||||
|
||||
var requiredFields = ["name", "place", 'address', 'phone'];
|
||||
for (var i in requiredFields) {
|
||||
var value = _deliveryDestination.get(requiredFields[i]);
|
||||
if (value === undefined || value === null || value === "") {
|
||||
@@ -2833,9 +2809,6 @@ var isDeliveryDestinationValid = function() {
|
||||
return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
|
||||
}
|
||||
|
||||
var isRecipientDestinationValid = function() {
|
||||
return Object.getOwnPropertyNames(_recipientDestinationErrors).length === 0;
|
||||
}
|
||||
// Extend CartStore with EventEmitter to add eventing capabilities
|
||||
var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
@@ -2900,12 +2873,7 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
deliveryDestinationErrors: _deliveryDestinationErrors,
|
||||
isDeliveryDestinationValid: isDeliveryDestinationValid(),
|
||||
deliveryCosts: _deliveryCosts,
|
||||
destinationValid: isDeliveryDestinationValid(),
|
||||
recipientDestination: _recipientDestination,
|
||||
recipientDestinationErrors: _recipientDestinationErrors,
|
||||
isRecipientDestinationValid: isRecipientDestinationValid(),
|
||||
recipientCosts: _recipientCosts,
|
||||
recipientValid: isRecipientDestinationValid()
|
||||
destinationValid: isDeliveryDestinationValid()
|
||||
};
|
||||
return state;
|
||||
},
|
||||
@@ -2978,9 +2946,6 @@ AppDispatcher.register(function(payload) {
|
||||
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
|
||||
changeDeliveryDestinationProperty(action.propertyName, action.value)
|
||||
break;
|
||||
case CartConstants.CHANGE_RECIPIENT_DESTINATION_PROPERTY:
|
||||
changeRecipientDestinationProperty(action.propertyName, action.value)
|
||||
break;
|
||||
case CartConstants.CONFIRM_DELIVERY:
|
||||
saveDeliveryDestination();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user