Gift support changes

This commit is contained in:
adam.harbas@a-net.ba
2016-01-12 13:26:43 +01:00
parent aca81d97ec
commit 9142e0c4db
10 changed files with 103 additions and 133 deletions

View File

@@ -47,13 +47,6 @@ var CartActions = {
value: value
});
},
changeRecipientDestinationProperty: function(property, value) {
AppDispatcher.handleAction({
actionType: CartConstants.CHANGE_RECIPIENT_DESTINATION_PROPERTY,
propertyName: property,
value: value
});
},
confirmDelivery: function() {
AppDispatcher.handleAction({
actionType: CartConstants.CONFIRM_DELIVERY,

View File

@@ -127,30 +127,29 @@ var CheckoutPage = React.createClass({
<legend>Podaci o dostavi</legend>
<div className="form-group ">
<label className="col-md-4 control-label" htmlFor="name">Prezime i Ime</label>
<label className="col-md-4 control-label" htmlFor="recipient_name">Prezime i Ime</label>
<div className="col-md-4">
<RibicaFormError componentName="name" errorMessagesObject={this.state.recipientDestinationErrors} />
<input id="name" name="name" type="text" placeholder="Prezime Ime" className="form-control input-md" required="" value={this.state.recipientDestination.get('name')} onChange={this._onFieldRecipientChange} />
<RibicaFormError componentName="recipient_name" errorMessagesObject={this.state.deliveryDestinationErrors} />
<input id="recipient_name" name="recipient_name" type="text" placeholder="Prezime Ime" className="form-control input-md" required="" value={this.state.deliveryDestination.get('recipient_name')} onChange={this._onFieldChange} />
<span className="help-block">ime osobe koja prima pošiljku</span>
</div>
</div>
<div className="form-group ">
<label className="col-md-4 control-label" htmlFor="name">Adresa</label>
<label className="col-md-4 control-label" htmlFor="recipient_address">Adresa</label>
<div className="col-md-4">
<RibicaFormError componentName="address" errorMessagesObject={this.state.recipientDestinationErrors} />
<input id="address" name="address" type="text" placeholder="Ulica i broj" className="form-control input-md" required="" value={this.state.recipientDestination.get('address')} onChange={this._onFieldRecipientChange} />
<RibicaFormError componentName="recipient_address" errorMessagesObject={this.state.deliveryDestinationErrors} />
<input id="recipient_address" name="recipient_address" type="text" placeholder="Ulica i broj" className="form-control input-md" required="" value={this.state.deliveryDestination.get('recipient_address')} onChange={this._onFieldChange} />
<span className="help-block">adresa na koju će roba biti isporučena</span>
</div>
</div>
<div className="form-group ">
<label className="col-md-4 control-label" htmlFor="place">Mjesto</label>
<label className="col-md-4 control-label" htmlFor="recipient_place">Mjesto</label>
<div className="col-md-4">
<RibicaFormError componentName="place" errorMessagesObject={this.state.recipientDestinationErrors} />
<select id="place" name="place" className="form-control" value={this.state.recipientDestination.get('place')} onChange={this._onFieldRecipientChange} >
<RibicaFormError componentName="recipient_place" errorMessagesObject={this.state.deliveryDestinationErrors} />
<select id="recipient_place" name="recipient_place" className="form-control" value={this.state.deliveryDestination.get('recipient_place')} onChange={this._onFieldChange} >
{supportedPlaceOptions}
@@ -158,21 +157,21 @@ var CheckoutPage = React.createClass({
</div>
</div>
<div className="form-group ">
<label className="col-md-4 control-label" htmlFor="phone">Telefon</label>
<label className="col-md-4 control-label" htmlFor="recipient_phone">Telefon</label>
<div className="col-md-4">
<RibicaFormError componentName="phone" errorMessagesObject={this.state.recipientDestinationErrors} />
<RibicaFormError componentName="recipient_phone" errorMessagesObject={this.state.deliveryDestinationErrors} />
<div className="input-group">
<span className="input-group-addon">+387 </span>
<input id="phone" name="phone" className="form-control" placeholder="061 222 333" type="text" required="" value={this.state.recipientDestination.get('phone')} onChange={this._onFieldRecipientChange} />
<input id="recipient_phone" name="recipient_phone" className="form-control" placeholder="061 222 333" type="text" required="" value={this.state.deliveryDestination.get('recipient_phone')} onChange={this._onFieldChange} />
</div>
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
</div>
</div>
<div className="form-group ">
<label className="col-md-4 control-label" htmlFor="email">E - mail</label>
<label className="col-md-4 control-label" htmlFor="recipient_email">E - mail</label>
<div className="col-md-4">
<RibicaFormError componentName="email" errorMessagesObject={this.state.recipientDestinationErrors} />
<input id="email" name="email" type="text" placeholder="ime@nekimail.com" className="form-control input-md" required="" value={this.state.recipientDestination.get('email')} onChange={this._onFieldRecipientChange} />
<RibicaFormError componentName="recipient_email" errorMessagesObject={this.state.deliveryDestinationErrors} />
<input id="recipient_email" name="recipient_email" type="text" placeholder="ime@nekimail.com" className="form-control input-md" required="" value={this.state.deliveryDestination.get('recipient_email')} onChange={this._onFieldChange} />
<span className="help-block">E - mail adresa na koju će vam biti poslano obavještenje o narudžbi</span>
</div>
</div>
@@ -243,10 +242,6 @@ var CheckoutPage = React.createClass({
}
},
_onFieldRecipientChange: function(event) {
CartActions.changeRecipientDestinationProperty(event.target.name, event.target.value);
},
_onOrderClick: function (event) {
CartActions.changeDeliveryDestinationProperty("payment_method", "cash_on_delivery");
CartActions.confirmDelivery();

View File

@@ -6,7 +6,6 @@ module.exports = keyMirror({
CART_DATA_LOADED: null,
SAVE_CART_STATE_FOR_ITEM: null,
CHANGE_DELIVERY_DESTINATION_PROPERTY: null,
CHANGE_RECIPIENT_DESTINATION_PROPERTY: null,
CONFIRM_DELIVERY: null,
SET_ITEM_COUNT: null,
ADD_N_ITEMS: null,

View File

@@ -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;