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' ) ,
2015-03-11 07:32:05 +01:00
CartTotal = require ( './cartTotal' ) ,
2015-03-29 12:46:51 +02:00
LinkBanner = require ( '../linkBanner/linkBanner' ) ,
2015-03-11 07:32:05 +01:00
RibicaFormError = require ( '../shared/ribicaFormError' ) ;
2015-02-19 07:17:31 +01:00
var Router = require ( 'react-router' ) ;
var CheckoutPage = React . createClass ( {
render : function ( ) {
2015-06-14 05:28:28 +02:00
2015-06-14 06:18:10 +02:00
var supportedPlaceOptions = CartStore . getSupportedPlaces ( ) . map ( function ( p ) { return ( < option value = { p . code } > { p . placeLabel } < / o p t i o n > ) } ) ;
2015-02-19 07:17:31 +01:00
2015-06-14 06:18:10 +02:00
var content = (
2015-02-23 07:08:23 +01:00
< div className = "checkout-page center" >
2015-07-05 13:44:38 +02:00
< div className = "form-horizontal checkout_form_margin" >
2015-02-26 06:48:34 +01:00
< fieldset >
< legend > Dostava < / l e g e n d >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-03-11 07:32:05 +01:00
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "name" > Prezime i Ime < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< 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 < / s p a n >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "name" > Adresa < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< 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 < / s p a n >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "place" > Mjesto < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< 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 } >
2015-06-14 05:28:28 +02:00
2015-07-05 13:44:38 +02:00
{ supportedPlaceOptions }
2015-06-14 05:28:28 +02:00
2015-02-26 06:48:34 +01:00
< / s e l e c t >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "phone" > Telefon < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "phone" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< div className = "input-group" >
2015-05-11 11:35:24 +02:00
< span className = "input-group-addon" > + 387 < / s p a n >
< 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
< / d i v >
< p className = "help-block" > broj mobitela - mora biti sa jedne od mreža u BiH < / p >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "email" > E - mail < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< 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 < / s p a n >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "note" > Napomena < / l a b e l >
< div className = "col-md-4" >
< textarea className = "form-control" id = "note" name = "note" value = { this . state . deliveryDestination . get ( 'note' ) } onChange = { this . _onFieldChange } > < / t e x t a r e a >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "order" > < / l a b e l >
< div className = "col-md-8" >
2015-07-05 13:22:47 +02:00
< div > Roba : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } / > < br / >
Dostava : < CartTotal deliveryCosts = { this . state . deliveryCosts } / > < br / >
Ukupno : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } deliveryCosts = { this . state . deliveryCosts } / > < / d i v >
2015-06-14 05:28:28 +02:00
< div > < button id = "order" name = "order" className = "mybutton" disabled = { ! this . state . isDeliveryDestinationValid } onClick = { this . _onOrderClick } > Završi narudžbu < / b u t t o n > < / d i v >
2015-02-26 06:48:34 +01:00
< / d i v >
< / d i v >
2015-03-13 07:04:44 +01:00
< / f i e l d s e t >
2015-02-26 06:48:34 +01:00
< / d i v >
2015-02-23 07:08:23 +01:00
< / d i v >
2015-06-14 06:18:10 +02:00
) ;
if ( CartStore . isAddressColapsed ( ) ) {
var address = CartStore . getHumanReadableAddress ( ) . map ( function ( a ) { return ( < span > { a } < br / > < / s p a n > ) } ) ;
content = (
< div className = "checkout-page center text-center" >
< h2 > Roba će biti dostavljena na adresu : < / h 2 >
< 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 >
< p >
< button id = "order" name = "order" className = "mybutton" disabled = { ! this . state . isDeliveryDestinationValid } onClick = { this . _onOrderClick } > Završi narudžbu < / b u t t o n > i l i < b u t t o n c l a s s N a m e = " b t n b t n - d e f a u l t " o n C l i c k = { t h i s . _ o n U n c o l a p s e C l i c k } > P r o m i j e n i a d r e s u < / b u t t o n >
< / p >
< div className = "form-group" >
< label className = "col-md-4 control-label" htmlFor = "order" > < / l a b e l >
< div className = "col-md-8" >
< div > < / d i v >
< div > < / d i v >
< / d i v >
< / d i v >
< / d i v > ) ;
}
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 ( ) ) ;
}
} ,
2015-02-23 07:08:23 +01:00
_onFieldChange : function ( event ) {
CartActions . changeDeliveryDestinationProperty ( event . target . name , event . target . value ) ;
2015-02-19 07:17:31 +01:00
} ,
2015-02-26 06:48:34 +01:00
_onOrderClick : function ( event ) {
CartActions . confirmDelivery ( ) ;
} ,
2015-02-19 07:17:31 +01:00
2015-06-14 06:18:10 +02:00
_onUncolapseClick : function ( event ) {
CartActions . setAddressColapsed ( false ) ;
} ,
2015-02-19 07:17:31 +01:00
getInitialState : function ( ) {
return CartStore . getWholeCartState ( ) ;
}
} ) ;
module . exports = CheckoutPage ;