Gift support changes
This commit is contained in:
@@ -29,6 +29,16 @@ Bosna i Hercegovina<br /><br />
|
|||||||
</p>
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<% if dd.gift %>
|
||||||
|
<p><strong>Ovo je poklon</strong><br /><br />
|
||||||
|
<p><strong>Ime primaoca: </strong><%= dd.recipient_name %><br />
|
||||||
|
<p><strong>Adresa primaoca: </strong><%= dd.recipient_address %><br />
|
||||||
|
<p><strong>Postanski broj primaoca: </strong><%= dd.recipient_postal_code %><br />
|
||||||
|
<p><strong>Grad primaoca: </strong><%= dd.recipient_place %><br />
|
||||||
|
<p><strong>Email primaoca: </strong><%= dd.recipient_email %><br />
|
||||||
|
<p><strong>Telefon primaoca: </strong><%= dd.recipient_phone %><br /><br />
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Naručeno:</strong> <%= c.confirmed_at.in_time_zone("Europe/Sarajevo").strftime("%A %d.%m.%Y. %H:%M") %>
|
<strong>Naručeno:</strong> <%= c.confirmed_at.in_time_zone("Europe/Sarajevo").strftime("%A %d.%m.%Y. %H:%M") %>
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ end
|
|||||||
|
|
||||||
update_delivery_destination = ->() {
|
update_delivery_destination = ->() {
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method", "gift"]
|
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method", "gift",
|
||||||
|
"recipient_name", "recipient_address", "recipient_place", "recipient_postal_code", "recipient_phone", "recipient_email"]
|
||||||
|
|
||||||
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!
|
||||||
@@ -53,22 +55,6 @@ update_delivery_destination = ->() {
|
|||||||
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
|
||||||
|
|
||||||
get '/cart/recipient_destination' do
|
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
|
||||||
cart.recipient.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
|
||||||
end
|
|
||||||
|
|
||||||
update_recipient_destination = ->() {
|
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
|
||||||
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email"]
|
|
||||||
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
|
||||||
cart.recipient_destination.update_attributes(params)
|
|
||||||
cart.recipient_destination.save!
|
|
||||||
cart.recipient_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
|
||||||
}
|
|
||||||
put '/cart/recipient_destination', &update_delivery_destination
|
|
||||||
post '/cart/recipient_destination', &update_delivery_destination
|
|
||||||
|
|
||||||
def report_to_trello(cart)
|
def report_to_trello(cart)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
@cart = cart
|
@cart = cart
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class AddRecipientDestinationToDeliveryDestination < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :delivery_destinations, :recipient_name, :string
|
||||||
|
add_column :delivery_destinations, :recipient_address, :string
|
||||||
|
add_column :delivery_destinations, :recipient_place, :string
|
||||||
|
add_column :delivery_destinations, :recipient_postal_code, :string
|
||||||
|
add_column :delivery_destinations, :recipient_phone, :string
|
||||||
|
add_column :delivery_destinations, :recipient_email, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160111105607) do
|
ActiveRecord::Schema.define(version: 20160112091903) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -22,18 +22,17 @@ ActiveRecord::Schema.define(version: 20160111105607) do
|
|||||||
|
|
||||||
create_table "carts", force: :cascade do |t|
|
create_table "carts", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.boolean "ordered", default: false
|
t.boolean "ordered", default: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "anonymous_id_string"
|
t.string "anonymous_id_string"
|
||||||
t.integer "delivery_destination_id"
|
t.integer "delivery_destination_id"
|
||||||
t.boolean "confirmed", default: false
|
t.boolean "confirmed", default: false
|
||||||
t.boolean "packed", default: false
|
t.boolean "packed", default: false
|
||||||
t.boolean "canceled_on_check", default: false
|
t.boolean "canceled_on_check", default: false
|
||||||
t.boolean "canceled_on_delivery", default: false
|
t.boolean "canceled_on_delivery", default: false
|
||||||
t.boolean "delivered", default: false
|
t.boolean "delivered", default: false
|
||||||
t.text "internal_note"
|
t.text "internal_note"
|
||||||
t.integer "recipient_destination_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "categories", force: :cascade do |t|
|
create_table "categories", force: :cascade do |t|
|
||||||
@@ -70,6 +69,12 @@ ActiveRecord::Schema.define(version: 20160111105607) do
|
|||||||
t.boolean "instant_delivery", default: false
|
t.boolean "instant_delivery", default: false
|
||||||
t.string "payment_method"
|
t.string "payment_method"
|
||||||
t.boolean "gift", default: false
|
t.boolean "gift", default: false
|
||||||
|
t.string "recipient_name"
|
||||||
|
t.string "recipient_address"
|
||||||
|
t.string "recipient_place"
|
||||||
|
t.string "recipient_postal_code"
|
||||||
|
t.string "recipient_phone"
|
||||||
|
t.string "recipient_email"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "delivery_time_estimations", force: :cascade do |t|
|
create_table "delivery_time_estimations", force: :cascade do |t|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
class Cart < ActiveRecord::Base
|
class Cart < ActiveRecord::Base
|
||||||
has_many :item_in_carts, -> { order "created_at" }
|
has_many :item_in_carts, -> { order "created_at" }
|
||||||
|
belongs_to :delivery_destination
|
||||||
belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'delivery_destination_id'
|
|
||||||
belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'recipient_destination_id'
|
|
||||||
|
|
||||||
def self.find_or_create(anonymous_id, user_id)
|
def self.find_or_create(anonymous_id, user_id)
|
||||||
cart = nil
|
cart = nil
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
class DeliveryDestination < ActiveRecord::Base
|
class DeliveryDestination < ActiveRecord::Base
|
||||||
has_many :carts
|
has_one :cart
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
def self.create_from_last(anonymous_id, user_id)
|
def self.create_from_last(anonymous_id, user_id)
|
||||||
dd = DeliveryDestination.where(["user_id is not null and user_id = ?", user_id]).order("id desc").first
|
dd = DeliveryDestination.where(["user_id is not null and user_id = ?", user_id]).order("id desc").first
|
||||||
dd ||= DeliveryDestination.where(["anonymous_id_string is not null and anonymous_id_string = ?", anonymous_id]).order("id desc").first
|
dd ||= DeliveryDestination.where(["anonymous_id_string is not null and anonymous_id_string = ?", anonymous_id]).order("id desc").first
|
||||||
dd ||= DeliveryDestination.new({user_id: user_id, anonymous_id_string: anonymous_id })
|
dd ||= DeliveryDestination.new({user_id: user_id, anonymous_id_string: anonymous_id })
|
||||||
|
|
||||||
dd.payment_method ||= "cash_on_delivery"
|
dd.payment_method ||= "cash_on_delivery"
|
||||||
|
dd.gift = false
|
||||||
|
dd.recipient_name = ""
|
||||||
|
dd.recipient_phone = ""
|
||||||
|
dd.recipient_email = ""
|
||||||
|
dd.recipient_address = ""
|
||||||
|
dd.recipient_place = ""
|
||||||
|
dd.recipient_postal_code = ""
|
||||||
|
|
||||||
attributes = dd.as_json
|
attributes = dd.as_json
|
||||||
attributes.delete("id")
|
attributes.delete("id")
|
||||||
result = DeliveryDestination.create!(attributes)
|
result = DeliveryDestination.create!(attributes)
|
||||||
|
|||||||
@@ -47,13 +47,6 @@ var CartActions = {
|
|||||||
value: value
|
value: value
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
changeRecipientDestinationProperty: function(property, value) {
|
|
||||||
AppDispatcher.handleAction({
|
|
||||||
actionType: CartConstants.CHANGE_RECIPIENT_DESTINATION_PROPERTY,
|
|
||||||
propertyName: property,
|
|
||||||
value: value
|
|
||||||
});
|
|
||||||
},
|
|
||||||
confirmDelivery: function() {
|
confirmDelivery: function() {
|
||||||
AppDispatcher.handleAction({
|
AppDispatcher.handleAction({
|
||||||
actionType: CartConstants.CONFIRM_DELIVERY,
|
actionType: CartConstants.CONFIRM_DELIVERY,
|
||||||
|
|||||||
@@ -127,30 +127,29 @@ var CheckoutPage = React.createClass({
|
|||||||
<legend>Podaci o dostavi</legend>
|
<legend>Podaci o dostavi</legend>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div className="form-group ">
|
<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">
|
<div className="col-md-4">
|
||||||
<RibicaFormError componentName="name" errorMessagesObject={this.state.recipientDestinationErrors} />
|
<RibicaFormError componentName="recipient_name" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||||
<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} />
|
<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>
|
<span className="help-block">ime osobe koja prima pošiljku</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-group ">
|
<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">
|
<div className="col-md-4">
|
||||||
<RibicaFormError componentName="address" errorMessagesObject={this.state.recipientDestinationErrors} />
|
<RibicaFormError componentName="recipient_address" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||||
<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} />
|
<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>
|
<span className="help-block">adresa na koju će roba biti isporučena</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="form-group ">
|
<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">
|
<div className="col-md-4">
|
||||||
<RibicaFormError componentName="place" errorMessagesObject={this.state.recipientDestinationErrors} />
|
<RibicaFormError componentName="recipient_place" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||||
<select id="place" name="place" className="form-control" value={this.state.recipientDestination.get('place')} onChange={this._onFieldRecipientChange} >
|
<select id="recipient_place" name="recipient_place" className="form-control" value={this.state.deliveryDestination.get('recipient_place')} onChange={this._onFieldChange} >
|
||||||
|
|
||||||
{supportedPlaceOptions}
|
{supportedPlaceOptions}
|
||||||
|
|
||||||
@@ -158,21 +157,21 @@ var CheckoutPage = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-group ">
|
<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">
|
<div className="col-md-4">
|
||||||
<RibicaFormError componentName="phone" errorMessagesObject={this.state.recipientDestinationErrors} />
|
<RibicaFormError componentName="recipient_phone" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||||
<div className="input-group">
|
<div className="input-group">
|
||||||
<span className="input-group-addon">+387 </span>
|
<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>
|
</div>
|
||||||
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
|
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-group ">
|
<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">
|
<div className="col-md-4">
|
||||||
<RibicaFormError componentName="email" errorMessagesObject={this.state.recipientDestinationErrors} />
|
<RibicaFormError componentName="recipient_email" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||||
<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} />
|
<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>
|
<span className="help-block">E - mail adresa na koju će vam biti poslano obavještenje o narudžbi</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -243,10 +242,6 @@ var CheckoutPage = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_onFieldRecipientChange: function(event) {
|
|
||||||
CartActions.changeRecipientDestinationProperty(event.target.name, event.target.value);
|
|
||||||
},
|
|
||||||
|
|
||||||
_onOrderClick: function (event) {
|
_onOrderClick: function (event) {
|
||||||
CartActions.changeDeliveryDestinationProperty("payment_method", "cash_on_delivery");
|
CartActions.changeDeliveryDestinationProperty("payment_method", "cash_on_delivery");
|
||||||
CartActions.confirmDelivery();
|
CartActions.confirmDelivery();
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ module.exports = keyMirror({
|
|||||||
CART_DATA_LOADED: null,
|
CART_DATA_LOADED: null,
|
||||||
SAVE_CART_STATE_FOR_ITEM: null,
|
SAVE_CART_STATE_FOR_ITEM: null,
|
||||||
CHANGE_DELIVERY_DESTINATION_PROPERTY: null,
|
CHANGE_DELIVERY_DESTINATION_PROPERTY: null,
|
||||||
CHANGE_RECIPIENT_DESTINATION_PROPERTY: null,
|
|
||||||
CONFIRM_DELIVERY: null,
|
CONFIRM_DELIVERY: null,
|
||||||
SET_ITEM_COUNT: null,
|
SET_ITEM_COUNT: null,
|
||||||
ADD_N_ITEMS: null,
|
ADD_N_ITEMS: null,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var ItemInCart = require('../models/itemInCart');
|
|||||||
var ItemInCartCollection = require('../models/itemInCartCollection');
|
var ItemInCartCollection = require('../models/itemInCartCollection');
|
||||||
var ItemCollection = require('../models/itemCollection');
|
var ItemCollection = require('../models/itemCollection');
|
||||||
var DeliveryDestination = require('../models/deliveryDestination');
|
var DeliveryDestination = require('../models/deliveryDestination');
|
||||||
var RecipientDestination = require('../models/recipientDestination');
|
|
||||||
var OrderConfirmation = require('../models/orderConfirmation');
|
var OrderConfirmation = require('../models/orderConfirmation');
|
||||||
var Place = require('../models/place');
|
var Place = require('../models/place');
|
||||||
var Validation = require('../utils/validation');
|
var Validation = require('../utils/validation');
|
||||||
@@ -26,12 +25,6 @@ var _deliveryCosts = new Place({
|
|||||||
postalCode: _deliveryDestination.get('place')
|
postalCode: _deliveryDestination.get('place')
|
||||||
});
|
});
|
||||||
|
|
||||||
var _recipientDestination = new RecipientDestination();
|
|
||||||
var _recipientDestinationErrors = {};
|
|
||||||
var _recipientCosts = new Place({
|
|
||||||
postalCode: _recipientDestination.get('place')
|
|
||||||
});
|
|
||||||
|
|
||||||
var _addressColapsed = false;
|
var _addressColapsed = false;
|
||||||
|
|
||||||
var supportedPlaces = [{
|
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({
|
_deliveryCosts = new Place({
|
||||||
postalCode: _deliveryDestination.get('place')
|
postalCode: postalCode
|
||||||
})
|
})
|
||||||
_deliveryCosts.fetch({
|
_deliveryCosts.fetch({
|
||||||
success: function() {
|
success: function() {
|
||||||
@@ -2704,18 +2700,11 @@ var changeDeliveryDestinationProperty = function(property, value) {
|
|||||||
if (property === 'place') {
|
if (property === 'place') {
|
||||||
fetchPlace();
|
fetchPlace();
|
||||||
}
|
}
|
||||||
|
if (property === 'recipient_place') {
|
||||||
validateDeliveryDestinationForm();
|
fetchPlace(true);
|
||||||
};
|
|
||||||
|
|
||||||
var changeRecipientDestinationProperty = function(property, value) {
|
|
||||||
_recipientDestination.set(property, value);
|
|
||||||
|
|
||||||
if (property === 'place') {
|
|
||||||
fetchPlace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRecipientDestinationForm();
|
validateDeliveryDestinationForm();
|
||||||
};
|
};
|
||||||
|
|
||||||
var confirmOrder = function() {
|
var confirmOrder = function() {
|
||||||
@@ -2744,11 +2733,10 @@ var saveDeliveryDestinationAnd = function(successCallback) {
|
|||||||
|
|
||||||
var saveDeliveryDestination = function() {
|
var saveDeliveryDestination = function() {
|
||||||
_deliveryDestination.save(null, {
|
_deliveryDestination.save(null, {
|
||||||
success: function() {
|
success: function() {
|
||||||
|
confirmOrder();
|
||||||
confirmOrder();
|
}
|
||||||
}
|
});
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var validateDeliveryDestinationForm = function() {
|
var validateDeliveryDestinationForm = function() {
|
||||||
@@ -2779,46 +2767,34 @@ var validateDeliveryDestinationForm = function() {
|
|||||||
_deliveryDestinationErrors['place'] = "Mjesto mora biti izabrano";
|
_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'];
|
var requiredFields = ["name", "email", "place", 'address', 'phone'];
|
||||||
for (var i in requiredFields) {
|
|
||||||
var value = _deliveryDestination.get(requiredFields[i]);
|
if(_deliveryDestination.get('gift')) {
|
||||||
if (value === undefined || value === null || value === "") {
|
requiredFields = requiredFields.concat(["recipient_name", "recipient_place", 'recipient_address', 'recipient_phone']);
|
||||||
// if it's required there will be a star there
|
|
||||||
_deliveryDestinationErrors[requiredFields[i]] = "*";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
for (var i in requiredFields) {
|
||||||
var value = _deliveryDestination.get(requiredFields[i]);
|
var value = _deliveryDestination.get(requiredFields[i]);
|
||||||
if (value === undefined || value === null || value === "") {
|
if (value === undefined || value === null || value === "") {
|
||||||
@@ -2833,9 +2809,6 @@ var isDeliveryDestinationValid = function() {
|
|||||||
return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
|
return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRecipientDestinationValid = function() {
|
|
||||||
return Object.getOwnPropertyNames(_recipientDestinationErrors).length === 0;
|
|
||||||
}
|
|
||||||
// Extend CartStore with EventEmitter to add eventing capabilities
|
// Extend CartStore with EventEmitter to add eventing capabilities
|
||||||
var CartStore = _.extend({}, EventEmitter.prototype, {
|
var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||||
|
|
||||||
@@ -2900,12 +2873,7 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
|||||||
deliveryDestinationErrors: _deliveryDestinationErrors,
|
deliveryDestinationErrors: _deliveryDestinationErrors,
|
||||||
isDeliveryDestinationValid: isDeliveryDestinationValid(),
|
isDeliveryDestinationValid: isDeliveryDestinationValid(),
|
||||||
deliveryCosts: _deliveryCosts,
|
deliveryCosts: _deliveryCosts,
|
||||||
destinationValid: isDeliveryDestinationValid(),
|
destinationValid: isDeliveryDestinationValid()
|
||||||
recipientDestination: _recipientDestination,
|
|
||||||
recipientDestinationErrors: _recipientDestinationErrors,
|
|
||||||
isRecipientDestinationValid: isRecipientDestinationValid(),
|
|
||||||
recipientCosts: _recipientCosts,
|
|
||||||
recipientValid: isRecipientDestinationValid()
|
|
||||||
};
|
};
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
@@ -2978,9 +2946,6 @@ AppDispatcher.register(function(payload) {
|
|||||||
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
|
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
|
||||||
changeDeliveryDestinationProperty(action.propertyName, action.value)
|
changeDeliveryDestinationProperty(action.propertyName, action.value)
|
||||||
break;
|
break;
|
||||||
case CartConstants.CHANGE_RECIPIENT_DESTINATION_PROPERTY:
|
|
||||||
changeRecipientDestinationProperty(action.propertyName, action.value)
|
|
||||||
break;
|
|
||||||
case CartConstants.CONFIRM_DELIVERY:
|
case CartConstants.CONFIRM_DELIVERY:
|
||||||
saveDeliveryDestination();
|
saveDeliveryDestination();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user