Merge branch 'master' of https://github.com/senaduka/ribica
This commit is contained in:
@@ -5,9 +5,9 @@ helpers do
|
||||
auid = cookies[:anonymous_user_id]
|
||||
if auid.nil?
|
||||
auid = AnonymousUser.uid
|
||||
response.set_cookie('anonymous_user_id', :path=> '/', :httponly => true, :value=>auid, :expires=>Time.now+100.year)
|
||||
response.set_cookie('anonymous_user_id', :path=> '/', :httponly => true, :value=>auid, :expires=> Time.now + 100.year)
|
||||
end
|
||||
auid
|
||||
return auid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,6 @@ get '/cart/item' do
|
||||
Cart.find_or_create(anonymous_id, -1).item_in_carts.to_json
|
||||
end
|
||||
|
||||
|
||||
update_cart_item = ->() {
|
||||
cart_id = Cart.find_or_create(anonymous_id, -1).id
|
||||
item_id = @json_params["item_id"].to_i
|
||||
@@ -58,4 +57,13 @@ update_delivery_destination = ->() {
|
||||
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
||||
}
|
||||
put '/cart/delivery_destination', &update_delivery_destination
|
||||
post '/cart/delivery_destination', &update_delivery_destination
|
||||
post '/cart/delivery_destination', &update_delivery_destination
|
||||
|
||||
|
||||
post '/cart/confirmation' do
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
if cart.item_in_carts.length > 0
|
||||
cart.ordered = true
|
||||
cart.save!
|
||||
end
|
||||
end
|
||||
@@ -7,7 +7,7 @@ class Cart < ActiveRecord::Base
|
||||
cart ||= Cart.where(anonymous_id_string: anonymous_id).where(ordered: false).first
|
||||
safe_user_id = (user_id > 0) ? user_id : nil
|
||||
cart ||= Cart.create!(anonymous_id_string: anonymous_id, user_id: safe_user_id, ordered: false )
|
||||
cart.delivery_destination ||= DeliveryDestination.create!
|
||||
cart.delivery_destination ||= DeliveryDestination.find_or_create(anonymous_id, user_id);
|
||||
return cart
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,11 @@
|
||||
class DeliveryDestination < ActiveRecord::Base
|
||||
has_one :cart
|
||||
belongs_to :user
|
||||
|
||||
def self.find_or_create(anonymous_id, user_id)
|
||||
dd = DeliveryDestination.where(user_id: user_id).order("id desc").first
|
||||
dd ||= DeliveryDestination.where(anonymous_id_string: anonymous_id).order("id desc").first
|
||||
dd ||= DeliveryDestination.create!({user_id: user_id, anonymous_id_string: anonymous_id })
|
||||
return dd
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,9 +78,17 @@ var NavigationActions = {
|
||||
actionType: NavigationConstants.CHANGE_URL,
|
||||
url: '/'
|
||||
});
|
||||
},
|
||||
|
||||
goToThankYou: function() {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: NavigationConstants.CHANGE_URL,
|
||||
url: '/hvala'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = NavigationActions;
|
||||
|
||||
@@ -12,15 +12,25 @@ var AddToCart = React.createClass({
|
||||
|
||||
render: function() {
|
||||
|
||||
return (
|
||||
var itemCount = this.state.item.get('count');
|
||||
|
||||
var moreThanZeroItems = (
|
||||
<div className="row-fluid add-to-cart">
|
||||
<div className="span12">
|
||||
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onIncreaseClick}>+</button></div>
|
||||
<div style={buttonHolderStyle}><button className="btn"> { this.state.item.get('count') } </button></div>
|
||||
<div style={buttonHolderStyle}><button className="btn"> { itemCount } </button></div>
|
||||
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onDecreaseClick}>-</button></div>
|
||||
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onIncreaseClick}>+</button></div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
var zeroItems = (<div className="row-fluid add-to-cart">
|
||||
<div className="span12">
|
||||
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onIncreaseClick}>Kupi</button></div>
|
||||
</div>
|
||||
</div> );
|
||||
|
||||
return (itemCount <= 0) ? zeroItems : moreThanZeroItems;
|
||||
},
|
||||
|
||||
// Add change listeners to stores
|
||||
|
||||
60
front-ui/app/components/thankyou/thankYouPage.js
Normal file
60
front-ui/app/components/thankyou/thankYouPage.js
Normal file
@@ -0,0 +1,60 @@
|
||||
var React = require('react'),
|
||||
CartStore = require('../../stores/cartStore'),
|
||||
AddToCart = require('../cart/addToCart'),
|
||||
CartActions = require('../../actions/cartActions'),
|
||||
NavigationActions = require('../../actions/navigationActions'),
|
||||
Globals = require('../../globals')
|
||||
Router = require("react-router"),
|
||||
Link = Router.Link;
|
||||
|
||||
|
||||
var ThankYouPage = React.createClass({
|
||||
|
||||
render: function() {
|
||||
|
||||
return (
|
||||
|
||||
<div className="thank-you-page center">
|
||||
<h1>Roba je naručena!</h1>
|
||||
<p>Hvala na narudžbi. Naša zaposlenica će vas kontaktirati da ugovori detalje o preuzimanju. </p>
|
||||
|
||||
<p>Registrujte se kako biste dobili informaciju o popustima, imali pregled svih vaših narudžbi,
|
||||
koristili Baby Shower, Predlagač poklona te kalendar događaja.</p>
|
||||
|
||||
<p>
|
||||
Registracija je jednostavna - samo jedan klik. <Link to="registracija">Klikni ovdje</Link>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
);
|
||||
|
||||
},
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
getInitialState: function () {
|
||||
return CartStore.getWholeCartState();
|
||||
}*/
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = ThankYouPage;
|
||||
20
front-ui/app/models/orderConfirmation.js
Normal file
20
front-ui/app/models/orderConfirmation.js
Normal file
@@ -0,0 +1,20 @@
|
||||
var Backbone = require('backbone');
|
||||
var Globals = require('../globals');
|
||||
|
||||
var orderConfirmation = Backbone.Model.extend({
|
||||
|
||||
initialize: function() {
|
||||
$.ajaxPrefilter(
|
||||
function(options, originalOptions, jqXHR) {
|
||||
options.xhrFields = {
|
||||
withCredentials: true
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
url: Globals.ApiUrl + '/cart/confirmation',
|
||||
defaults: { }
|
||||
});
|
||||
|
||||
module.exports = orderConfirmation;
|
||||
@@ -14,6 +14,7 @@ var RootApp = require('./components/rootApp');
|
||||
var StartPage = require('./components/startPage/startPage');
|
||||
var ByCategory = require('./components/browsing/byCategory');
|
||||
var BySection = require('./components/browsing/bySection');
|
||||
var ThankYouPage = require('./components/thankyou/thankYouPage');
|
||||
|
||||
var Register = require('./components/account/register');
|
||||
var Login = require('./components/account/login');
|
||||
@@ -28,6 +29,7 @@ var routes = (
|
||||
<Route name='registracija' path="/registracija" handler={Register} />
|
||||
<Route name='login' path="/login" handler={Login} />
|
||||
<Route name='byCat' path="sekcija/:sekcijaName/kategorija/:id/*" handler={ByCategory} />
|
||||
<Route name='hvala' path="/hvala" handler={ThankYouPage} />
|
||||
<DefaultRoute handler={StartPage}/>
|
||||
</Route>
|
||||
);
|
||||
|
||||
@@ -2,10 +2,12 @@ var AppDispatcher = require('../dispatcher/appDispatcher');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var CartConstants = require('../constants/cartConstants');
|
||||
var CartActions = require('../actions/cartActions');
|
||||
var NavigationActions = require('../actions/navigationActions');
|
||||
var ItemInCart = require('../models/itemInCart');
|
||||
var ItemInCartCollection = require('../models/itemInCartCollection');
|
||||
var ItemCollection = require('../models/itemCollection');
|
||||
var DeliveryDestination = require('../models/deliveryDestination');
|
||||
var OrderConfirmation = require('../models/orderConfirmation');
|
||||
|
||||
var _ = require('underscore');
|
||||
|
||||
@@ -44,6 +46,15 @@ var loadCart = function() {
|
||||
};
|
||||
|
||||
|
||||
var saveCartStateForItem = function(itemId) {
|
||||
var item = CartStore.getStateFor(itemId);
|
||||
item.save({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var addItem = function(itemId) {
|
||||
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
@@ -53,6 +64,7 @@ var addItem = function(itemId) {
|
||||
state.set('count', state.get('count') + 1);
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
|
||||
};
|
||||
|
||||
var takeItemOut = function(itemId) {
|
||||
@@ -68,23 +80,29 @@ var takeItemOut = function(itemId) {
|
||||
saveCartStateForItem(itemId);
|
||||
};
|
||||
|
||||
var saveCartStateForItem = function(itemId) {
|
||||
var item = CartStore.getStateFor(itemId);
|
||||
item.save({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var changeDeliveryDestinationProperty = function(property, value) {
|
||||
_deliveryDestination.set(property, value);
|
||||
};
|
||||
|
||||
|
||||
var confirmOrder = function () {
|
||||
console.log("confirming");
|
||||
var oc = new OrderConfirmation({ hamo: 'meho' });
|
||||
oc.save({b:'b'}, {
|
||||
success: function () {
|
||||
console.log("done");
|
||||
NavigationActions.goToThankYou();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var saveDeliveryDestination = function() {
|
||||
_deliveryDestination.save({
|
||||
console.log("saving delivery destination");
|
||||
_deliveryDestination.save(null,{
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
console.log("saved delivery destination");
|
||||
confirmOrder();
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user