application no longer thanks people for ordering nothing
This commit is contained in:
@@ -15,7 +15,7 @@ var CartPage = React.createClass({
|
||||
|
||||
render: function() {
|
||||
|
||||
var counts = this.state.itemCounts;
|
||||
var counts = this.state.itemCounts;
|
||||
|
||||
var displayedItems = this.state.items.map(function (i) {
|
||||
|
||||
@@ -35,6 +35,7 @@ var CartPage = React.createClass({
|
||||
)
|
||||
});
|
||||
|
||||
console.log("bla :" , this.state.items.length);
|
||||
var cartTotal = (
|
||||
<div className="row cart-total">
|
||||
<CartTotal items={this.state.items} itemCounts={this.state.itemCounts} />
|
||||
@@ -43,12 +44,23 @@ var CartPage = React.createClass({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
var buySomethingMessage = (<div></div>);
|
||||
|
||||
if (this.state.items.length <= 0) {
|
||||
cartTotal = (<div></div>)
|
||||
buySomethingMessage = (<div>Nemate ni jedan artikal u vašoj korpi. Kada vidite nešto što vam se sviđa - pritisnite dugme KUPI pored artikla kako biste ga dodali u korpu. </div>)
|
||||
|
||||
};
|
||||
|
||||
console.log("length :" , this.state.items.length);
|
||||
|
||||
return (
|
||||
|
||||
<div className="cart-page center">
|
||||
{cartTotal}
|
||||
{displayedItems}
|
||||
{buySomethingMessage}
|
||||
{cartTotal}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
@@ -63,7 +63,6 @@ var RibicaValidationMixin = {
|
||||
return Object.keys(errors).length === 0;
|
||||
},
|
||||
componentDidMount : function(){
|
||||
this.setState({errors: {}});
|
||||
if (this.validations) {
|
||||
var self = this;
|
||||
this.validations.getState = function() {
|
||||
|
||||
Reference in New Issue
Block a user