fixed problem with multiple carts and a whole load of problems with crazy delivery destination logic / if I didn't write it i would have thought it was written by a drug abuser during high

This commit is contained in:
Senad Uka
2015-03-14 08:17:06 +01:00
parent e7793f0884
commit 8815267a79
12 changed files with 195 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ var ItemCollection = require('../models/itemCollection');
var DeliveryDestination = require('../models/deliveryDestination');
var OrderConfirmation = require('../models/orderConfirmation');
var Place = require('../models/place');
var Validation = require('../utils/validation');
var _ = require('underscore');
@@ -141,27 +142,27 @@ var validateDeliveryDestinationForm = function() {
_deliveryDestinationErrors = {};
var nameRegex = /.+\s+.+/i;
if (_deliveryDestination.get('name').search(nameRegex) < 0) {
if (Validation.safeString(_deliveryDestination.get('name')).search(nameRegex) < 0) {
_deliveryDestinationErrors['name'] = "I prezime i ime su obavezni";
}
var addressRegex = /.+\s+.+/i;
if (_deliveryDestination.get('address').search(addressRegex) < 0) {
if (Validation.safeString(_deliveryDestination.get('address')).search(addressRegex) < 0) {
_deliveryDestinationErrors['address'] = "Adresa mora biti ispravna";
}
var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/i;
if (_deliveryDestination.get('email').search(emailRegex) < 0) {
if (Validation.safeString(_deliveryDestination.get('email')).search(emailRegex) < 0) {
_deliveryDestinationErrors['email'] = "Email mora biti ispravno upisan";
}
var phoneRegex = /[\d\s-]{7,8}/i;
if (_deliveryDestination.get('phone').search(phoneRegex) < 0) {
if (Validation.safeString(_deliveryDestination.get('phone')).search(phoneRegex) < 0) {
_deliveryDestinationErrors['phone'] = "Telefon mora biti ispravan";
}
var placeRegex = /^\s{0,1}\d{5}$/i;
if (_deliveryDestination.get('place').search(placeRegex) < 0) {
if (Validation.safeString(_deliveryDestination.get('place')).search(placeRegex) < 0){
_deliveryDestinationErrors['place'] = "Mjesto mora biti izabrano";
}

View File

@@ -0,0 +1,69 @@
var AppDispatcher = require('../dispatcher/appDispatcher');
var EventEmitter = require('events').EventEmitter;
var Cart = require('../models/cart');
var InitializationConstants = require('../constants/initializationConstants')
var _ = require('underscore');
var state = {
isEverythingReadyToStartTheShow: false
}
var initializeTheShop = function () {
// for now only guarantee that cart is created
var cart = new Cart();
cart.save(null, {
success: function () {
state.isEverythingReadyToStartTheShow = true;
InitializationStore.emitChange();
}
})
}
// Extend ItemStore with EventEmitter to add eventing capabilities
var InitializationStore = _.extend({}, EventEmitter.prototype, {
getState: function() {
return state;
},
// Emit Change event
emitChange: function() {
console.log("InitializationStore change!");
this.emit('change');
},
// Add change listener
addChangeListener: function(callback) {
this.on('change', callback);
},
// Remove change listener
removeChangeListener: function(callback) {
this.removeListener('change', callback);
}
});
// Register callback with AppDispatcher
InitializationStore.dispatchToken = AppDispatcher.register(function(payload) {
var action = payload.action;
switch (action.actionType) {
case InitializationConstants.INITIALIZE:
initializeTheShop();
break;
default:
return true;
}
// If action was responded to, emit change event
InitializationStore.emitChange();
return true;
});
module.exports = InitializationStore;