Files
old-ribica/front-ui/app/components/cart/checkoutPage.js

287 lines
14 KiB
JavaScript
Raw Normal View History

2015-02-19 07:17:31 +01:00
var React = require('react'),
CartStore = require('../../stores/cartStore'),
AddToCart = require('../cart/addToCart'),
CartActions = require('../../actions/cartActions'),
NavigationActions = require('../../actions/navigationActions'),
SingleItem = require('../items/singleItem'),
Globals = require('../../globals'),
2016-01-06 08:26:19 +01:00
CartTotal = require('./cartTotal'),
2015-03-29 12:46:51 +02:00
LinkBanner = require('../linkBanner/linkBanner'),
2015-11-14 04:39:05 +01:00
PaymentSelect = require('../payment/paymentSelect'),
2016-01-08 10:21:33 +01:00
RibicaFormError = require('../shared/ribicaFormError'),
2016-01-11 10:21:11 +01:00
PaypalButton = require('../payment/paypalButton'),
2016-01-11 10:52:18 +01:00
PikpayButton = require('../payment/pikpayButton'),
2016-01-11 10:21:11 +01:00
CashOnDeliveryButton = require('../payment/cashOnDeliveryButton');
2015-02-19 07:17:31 +01:00
var Router = require('react-router');
var CheckoutPage = React.createClass({
render: function() {
2016-01-06 08:26:19 +01:00
var choosePayment = (
<div className="payment-btn">
2016-01-11 08:53:03 +01:00
<PaymentSelect deliveryDestination={this.state.deliveryDestination}
amount={CartStore.getAmount()}
deliveryCost={CartStore.getDeliveryCost(false)}
disabled={!this.state.isDeliveryDestinationValid}
2016-01-12 15:18:27 +01:00
cashOnDeliveryDisabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')}
2016-01-11 08:53:03 +01:00
onCashClick={this._onOrderClick}
2016-01-13 09:26:28 +01:00
cartId={this.state.cart.get('id')}
2016-01-11 08:53:03 +01:00
/>
2015-11-14 04:39:05 +01:00
</div>
);
2016-01-08 10:21:33 +01:00
var last_used_payment;
2016-01-11 10:21:11 +01:00
if(this.state.deliveryDestination.get('payment_method') == 'paypal') {
2016-01-08 10:21:33 +01:00
last_used_payment = (
2016-01-13 09:26:28 +01:00
<PaypalButton disabled={!this.state.isDeliveryDestinationValid} onSubmitPaypal={this._handleOnSubmitPaypal} deliveryDestination={this.state.deliveryDestination} amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} cartId={this.state.cart.get('id')}/>
2016-01-08 10:21:33 +01:00
);
} else if(this.state.deliveryDestination.get('payment_method') == 'pikpay') {
2016-01-13 09:26:28 +01:00
last_used_payment = (
<PikpayButton amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} disabled={!this.state.isDeliveryDestinationValid} deliveryDestination={this.state.deliveryDestination} cartId={this.state.cart.get('id')}/>
);
2016-01-08 10:21:33 +01:00
} else {
last_used_payment = (
2016-01-13 09:26:28 +01:00
<CashOnDeliveryButton onCashClick={this._onOrderClick} disabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')} cartId={this.state.cart.get('id')}/>
2016-01-08 10:21:33 +01:00
);
}
2016-01-07 15:00:59 +01:00
2015-06-14 06:18:10 +02:00
var supportedPlaceOptions = CartStore.getSupportedPlaces().map ( function (p) { return (<option value={p.code}>{p.placeLabel}</option>)});
2016-01-06 08:26:19 +01:00
2015-06-14 06:18:10 +02:00
var content = (
<div className="checkout-page center">
<div className="form-horizontal checkout_form_margin">
2015-02-26 06:48:34 +01:00
<fieldset>
2016-01-11 16:03:53 +01:00
<legend>Podaci o naručiocu</legend>
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="name">Prezime i Ime</label>
<div className="col-md-4">
<RibicaFormError componentName="name" errorMessagesObject={this.state.deliveryDestinationErrors} />
2015-02-26 06:48:34 +01:00
<input id="name" name="name" type="text" placeholder="Prezime Ime" className="form-control input-md" required="" value={this.state.deliveryDestination.get('name')} onChange={this._onFieldChange} />
<span className="help-block">ime osobe koja prima pošiljku</span>
</div>
</div>
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="name">Adresa</label>
<div className="col-md-4">
<RibicaFormError componentName="address" errorMessagesObject={this.state.deliveryDestinationErrors} />
2015-02-26 06:48:34 +01:00
<input id="address" name="address" type="text" placeholder="Ulica i broj" className="form-control input-md" required="" value={this.state.deliveryDestination.get('address')} onChange={this._onFieldChange} />
<span className="help-block">adresa na koju će roba biti isporučena</span>
</div>
</div>
2016-01-06 08:26:19 +01:00
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="place">Mjesto</label>
<div className="col-md-4">
<RibicaFormError componentName="place" errorMessagesObject={this.state.deliveryDestinationErrors} />
2015-02-26 06:48:34 +01:00
<select id="place" name="place" className="form-control" value={this.state.deliveryDestination.get('place')} onChange={this._onFieldChange} >
2016-01-06 08:26:19 +01:00
{supportedPlaceOptions}
2015-02-26 06:48:34 +01:00
</select>
</div>
</div>
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="phone">Telefon</label>
<div className="col-md-4">
<RibicaFormError componentName="phone" errorMessagesObject={this.state.deliveryDestinationErrors} />
2015-02-26 06:48:34 +01:00
<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.deliveryDestination.get('phone')} onChange={this._onFieldChange} />
2015-02-26 06:48:34 +01:00
</div>
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
</div>
</div>
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="email">E - mail</label>
<div className="col-md-4">
<RibicaFormError componentName="email" errorMessagesObject={this.state.deliveryDestinationErrors} />
2015-02-26 06:48:34 +01:00
<input id="email" name="email" type="text" placeholder="ime@nekimail.com" className="form-control input-md" required="" value={this.state.deliveryDestination.get('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>
<div className="form-group ">
2015-02-26 06:48:34 +01:00
<label className="col-md-4 control-label" htmlFor="note">Napomena</label>
<div className="col-md-4">
<textarea className="form-control" id="note" name="note" value={this.state.deliveryDestination.get('note')} onChange={this._onFieldChange} ></textarea>
</div>
</div>
2016-01-11 08:53:03 +01:00
<div className="form-group">
<label className="col-md-4 control-label" htmlFor="order"></label>
<div className="col-md-8">
<div> Roba: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} /><br />
2016-01-12 15:18:27 +01:00
<span className={this.state.deliveryDestinationErrors[this.state.deliveryCostsTarget] ? 'hidden' : 'shown'}>
2016-01-11 08:53:03 +01:00
Dostava: <CartTotal deliveryCosts={this.state.deliveryCosts} /><br />
Ukupno: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} />
</span>
2016-01-11 08:53:03 +01:00
</div>
2016-01-11 16:03:53 +01:00
<br />
<div className="checkbox">
<label><input type="checkbox" name="gift" checked={this.state.deliveryDestination.get('gift')} onChange={this._onFieldChange} />Poklon</label>
2016-01-11 16:03:53 +01:00
</div>
2015-02-26 06:48:34 +01:00
</div>
2016-01-11 08:53:03 +01:00
</div>
2015-11-14 04:39:05 +01:00
2016-01-11 16:03:53 +01:00
2016-01-06 08:26:19 +01:00
</fieldset>
2015-11-14 04:39:05 +01:00
2016-01-11 16:03:53 +01:00
<fieldset className={this.state.deliveryDestination.get('gift') ? 'shown' : 'hidden'}>
<legend>Podaci o dostavi</legend>
2016-01-11 16:03:53 +01:00
<div className="form-group ">
2015-11-14 04:39:05 +01:00
2016-01-12 13:26:43 +01:00
<label className="col-md-4 control-label" htmlFor="recipient_name">Prezime i Ime</label>
2016-01-11 16:03:53 +01:00
<div className="col-md-4">
2016-01-12 13:26:43 +01:00
<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} />
2016-01-11 16:03:53 +01:00
<span className="help-block">ime osobe koja prima pošiljku</span>
</div>
</div>
<div className="form-group ">
2016-01-12 13:26:43 +01:00
<label className="col-md-4 control-label" htmlFor="recipient_address">Adresa</label>
2016-01-11 16:03:53 +01:00
<div className="col-md-4">
2016-01-12 13:26:43 +01:00
<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} />
2016-01-11 16:03:53 +01:00
<span className="help-block">adresa na koju će roba biti isporučena</span>
</div>
</div>
<div className="form-group ">
2016-01-12 13:26:43 +01:00
<label className="col-md-4 control-label" htmlFor="recipient_place">Mjesto</label>
<div className="col-md-4">
2016-01-12 13:26:43 +01:00
<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} >
2016-01-11 16:03:53 +01:00
{supportedPlaceOptions}
2016-01-11 16:03:53 +01:00
</select>
2016-01-11 16:03:53 +01:00
</div>
</div>
<div className="form-group ">
2016-01-12 13:26:43 +01:00
<label className="col-md-4 control-label" htmlFor="recipient_phone">Telefon</label>
<div className="col-md-4">
2016-01-12 13:26:43 +01:00
<RibicaFormError componentName="recipient_phone" errorMessagesObject={this.state.deliveryDestinationErrors} />
<div className="input-group">
<span className="input-group-addon">+387 </span>
2016-01-12 13:26:43 +01:00
<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} />
2016-01-11 16:03:53 +01:00
</div>
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
2016-01-11 16:03:53 +01:00
</div>
</div>
<div className="form-group ">
2016-01-12 13:26:43 +01:00
<label className="col-md-4 control-label" htmlFor="recipient_email">E - mail</label>
<div className="col-md-4">
2016-01-12 13:26:43 +01:00
<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>
2016-01-11 16:03:53 +01:00
</div>
</div>
2016-01-11 16:03:53 +01:00
</fieldset>
<div className="payment-select-container">
{choosePayment}
</div>
</div>
</div>
2016-01-06 08:26:19 +01:00
);
2015-06-14 06:18:10 +02:00
if(CartStore.isAddressColapsed()) {
var address = CartStore.getHumanReadableAddress().map(function (a) { return (<span>{a}<br /></span>)});
content = (
<div className="checkout-page center text-center" >
<h2> Roba će biti dostavljena na adresu: </h2>
<p className="lead">
{address}
<br />
2015-07-05 13:22:47 +02:00
Roba: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} /><br />
Dostava: <CartTotal deliveryCosts={this.state.deliveryCosts} /><br />
2015-06-14 06:18:10 +02:00
Ukupno: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} />
</p>
2016-01-12 14:23:40 +01:00
2016-01-13 09:51:36 +01:00
<div className="hidden-xs">
<button className="btn btn-default gift-btn" onClick={this._onGiftBtnClicked}>Poklon</button>
<br />
<p className="collapsed-address-container">{last_used_payment} ili <button className="btn btn-default" onClick={this._onUncolapseClick}>Promijeni način plaćanja ili adresu</button></p>
</div>
2016-01-12 14:23:40 +01:00
2016-01-13 09:51:36 +01:00
<div className="collapsed-address-container-mobile btn-group-vertical visible-xs">
<button className="btn btn-default" onClick={this._onGiftBtnClicked}>Poklon</button>
{last_used_payment}
<button className="btn btn-default" onClick={this._onUncolapseClick}>Promijeni način plaćanja ili adresu</button>
</div>
2016-01-12 14:23:40 +01:00
2015-06-14 06:18:10 +02:00
<div className="form-group">
<label className="col-md-4 control-label" htmlFor="order"></label>
<div className="col-md-8">
<div> </div>
<div></div>
</div>
2015-11-14 04:39:05 +01:00
</div>
2015-06-14 06:18:10 +02:00
</div>);
}
return content;
2015-02-19 07:17:31 +01:00
},
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
CartActions.load();
},
componentWillUnmount: function () {
CartStore.removeChangeListener(this._onChange);
},
_onChange: function () {
if (this.isMounted()) {
this.setState(CartStore.getWholeCartState());
}
},
_onFieldChange: function (event) {
2016-01-11 16:03:53 +01:00
if(event.target.name === "gift") {
CartActions.changeDeliveryDestinationProperty(event.target.name, $(event.target).is(':checked'));
} else {
CartActions.changeDeliveryDestinationProperty(event.target.name, event.target.value);
}
},
2015-02-26 06:48:34 +01:00
_onOrderClick: function (event) {
2016-01-11 10:52:18 +01:00
CartActions.changeDeliveryDestinationProperty("payment_method", "cash_on_delivery");
2015-02-26 06:48:34 +01:00
CartActions.confirmDelivery();
},
2015-02-19 07:17:31 +01:00
2015-06-14 06:18:10 +02:00
_onUncolapseClick: function (event) {
CartActions.setAddressColapsed(false);
},
2016-01-12 14:23:40 +01:00
_onGiftBtnClicked: function (event) {
CartActions.changeDeliveryDestinationProperty('gift', true);
CartActions.setAddressColapsed(false);
},
2016-01-08 10:21:33 +01:00
_handleOnSubmitPaypal: function(event) {
CartActions.changeDeliveryDestinationProperty('payment_method', 'paypal');
return false;
},
2015-02-19 07:17:31 +01:00
getInitialState: function () {
return CartStore.getWholeCartState();
}
});
2016-01-06 08:26:19 +01:00
module.exports = CheckoutPage;