+
E - mail adresa na koju će vam biti poslano obavještenje o narudžbi
@@ -592,7 +599,7 @@ var CheckoutPage = React.createClass({
diff --git a/front-ui/app/components/items/singleItem.js b/front-ui/app/components/items/singleItem.js
index 7be62c0..4a56217 100644
--- a/front-ui/app/components/items/singleItem.js
+++ b/front-ui/app/components/items/singleItem.js
@@ -33,8 +33,7 @@ var SingleItem = React.createClass({
itemClick: function(e) {
NavigationActions.goToItemDetails(this.props.item);
- console.log(this.props.item)
-
+ console.log(this.props.item)
}
});
diff --git a/front-ui/app/components/shared/mixins/ribicaValidationMixin (mehmedpasa's conflicted copy 2015-03-07).js b/front-ui/app/components/shared/mixins/ribicaValidationMixin (mehmedpasa's conflicted copy 2015-03-07).js
deleted file mode 100644
index fc9809b..0000000
--- a/front-ui/app/components/shared/mixins/ribicaValidationMixin (mehmedpasa's conflicted copy 2015-03-07).js
+++ /dev/null
@@ -1,76 +0,0 @@
-var RibicaValidationMixin = {
- _updateState: function(prop, value, callback) {
- var newState = {};
- newState[prop] = value;
- this.setState(newState, function(){
- if(callback) {
- callback();
- }
- }.bind(this));
- },
- _validate: function(prop, value) {
- if(this.validations && this.validations[prop]) {
- var cb = function(err, revalidateFields) {
- var errors = this.state.errors || {};
- if (err !== undefined) {
- if(err.length > 0) {
- errors[prop] = err;
- } else {
- delete errors[prop];
- }
- } else {
- delete errors[prop];
- }
- this.setState({errors: errors});
- if (revalidateFields) {
- for(var i = 0; i < revalidateFields.length; i++) {
- this.validateField(revalidateFields[i], this.state[revalidateFields[i]]);
- }
- }
- }.bind(this);
-
- var immediateErrors = this.validations[prop](value, cb);
- cb(immediateErrors);
- }
- },
- handleChange: function(prop) {
- return function(event) {
- event.preventDefault();
- var target = event.target;
- this._updateState(prop, target.value, function(){
- this._validate(prop, target.value);
- }.bind(this));
- }.bind(this);
-
- },
- getValidationMessages:function(prop) {
- var errors = this.state.errors || {};
- return (errors[prop] || []);
- },
- validateField: function(field) {
- this._validate(field, this.state[field]);
- },
- validate: function() {
- for (var key in this.state) {
- if (this.state.hasOwnProperty(key)) {
- this._validate(key, this.state[key]);
- }
- }
- return this.isValid();
- },
- isValid: function() {
- var errors = this.state.errors || {};
- return Object.keys(errors).length === 0;
- },
- componentDidMount : function(){
- this.setState({errors: {}});
- if (this.validations) {
- var self = this;
- this.validations.getState = function() {
- return self.state;
- };
- }
- },
-};
-
-module.exports = RibicaValidationMixin;
diff --git a/front-ui/app/components/shared/ribicaFormError.js b/front-ui/app/components/shared/ribicaFormError.js
new file mode 100644
index 0000000..0514817
--- /dev/null
+++ b/front-ui/app/components/shared/ribicaFormError.js
@@ -0,0 +1,17 @@
+var React = require('react');
+
+
+var RibicaFormError = React.createClass({
+ render: function() {
+ var errorMessages = this.props.errorMessagesObject || {};
+ var componentName = this.props.componentName;
+ var message = errorMessages[componentName];
+ if (message !== undefined && message !== null && message !== "") {
+ return(
{message}
)
+ }
+ else return (
);
+ }
+});
+
+
+module.exports = RibicaFormError;
diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js
index 8638266..afe5e7f 100644
--- a/front-ui/app/stores/cartStore.js
+++ b/front-ui/app/stores/cartStore.js
@@ -17,6 +17,7 @@ var _itemsInCart = new ItemInCartCollection();
var _itemsForDisplay = new ItemCollection();
_itemsForDisplay.setFromCart(true);
var _deliveryDestination = new DeliveryDestination();
+var _deliveryDestinationErrors = {};
var loadCart = function() {
@@ -39,6 +40,7 @@ var loadCart = function() {
if (!_deliveryDestination.get('id')) {
_deliveryDestination.fetch({
success: function() {
+ validateDeliveryDestinationForm();
CartActions.dataLoaded();
}
});
@@ -82,6 +84,7 @@ var takeItemOut = function(itemId) {
var changeDeliveryDestinationProperty = function(property, value) {
_deliveryDestination.set(property, value);
+ validateDeliveryDestinationForm();
};
@@ -107,7 +110,49 @@ var saveDeliveryDestination = function() {
})
};
+var validateDeliveryDestinationForm = function () {
+ _deliveryDestinationErrors = {};
+
+ var nameRegex = /.+\s+.+/i;
+ if(_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) {
+ _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) {
+ _deliveryDestinationErrors['email'] = "Email mora biti ispravno upisan";
+ }
+
+ var phoneRegex = /[\d\s-]{7,8}/i;
+ if(_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) {
+ _deliveryDestinationErrors['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]] = "*";
+ }
+ }
+
+}
+
+
+var isDeliveryDestinationValid = function () {
+ return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
+}
// Extend CartStore with EventEmitter to add eventing capabilities
var CartStore = _.extend({}, EventEmitter.prototype, {
@@ -137,7 +182,10 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
count: numberOfItems,
items: _itemsForDisplay,
itemCounts: states,
- deliveryDestination: _deliveryDestination
+ deliveryDestination: _deliveryDestination,
+ deliveryDestinationErrors: _deliveryDestinationErrors,
+ isDeliveryDestinationValid: isDeliveryDestinationValid()
+
};
return state;
},
@@ -156,7 +204,11 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
// Remove change listener
removeChangeListener: function(callback) {
this.removeListener('change', callback);
- }
+ },
+
+ isDeliveryDestinationValid: isDeliveryDestinationValid
+
+
});