Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change components in order model

  • Loading branch information...
commit 8cfed05a4314f00368f863e3e29f81cb00619681 1 parent 05d383b
@pfeffer authored
View
5 app/assets/javascripts/application.js.erb
@@ -23,10 +23,5 @@
bread.prepare = function(){
- bread.F_RAISINS = <%=F_RAISINS %>
- bread.F_CHOC_CHIPS = <%=F_CHOC_CHIPS %>
- bread.F_WALNUTS = <%=F_WALNUTS %>
- bread.F_FLAX_SEEDS = <%=F_FLAX_SEEDS %>
- bread.F_CINNAMON = <%=F_CINNAMON %>
bread.orderStart();
};
View
31 app/assets/javascripts/order_bb.js
@@ -1,13 +1,13 @@
bread.initOrderBackbone = function() {
- bread.OrderModel = Backbone.Model.extend({
- defaults: {
- quantity: 1,
- components: {
- "raisins": false,
- "chocolate chips": false,
- "walnuts": false,
- "flax seeds": false,
- "cinnamon": false
+ bread.OrderModel = Backbone.Model.extend({
+ defaults: {
+ quantity: 1,
+ components: {
+ "raisins": false,
+ "chocolate chips": false,
+ "walnuts": false,
+ "flax seeds": false,
+ "cinnamon": false
},
step: 1,
max_step: 1,
@@ -20,7 +20,6 @@ bread.initOrderBackbone = function() {
user_email: '',
user_comment: '',
user_phone: '',
- order_validity_mask: 0xf,
valid_fields: {
"user_name": "",
"user_email": "",
@@ -80,16 +79,8 @@ bread.initOrderBackbone = function() {
//curl -d "txn_id=2H507847F71659449&order_id=1&payment_status=Completed" http://localhost:3000/payment_notifications
//<input type="hidden" name="notify_url" value=<%= payment_notifications_url%>>
var model = this;
-
- var components = this.get("components");
- var msk = 0;
- msk |= components["raisins"] ? bread.F_RAISINS : 0;
- msk |= components["chocolate chips"] ? bread.F_CHOC_CHIPS : 0;
- msk |= components["walnuts"] ? bread.F_WALNUTS : 0;
- msk |= components["flax seeds"] ? bread.F_FLAX_SEEDS : 0;
- msk |= components["cinnamon"] ? bread.F_CINNAMON : 0;
-
- _.extend(model.attributes, {components_mask: msk});
+
+ //_.extend(model.attributes, {components_json: model.get("components").toJSON()});
$.ajax({url: "/orders",
data: this.attributes,
type: 'POST',
View
8 app/controllers/orders_controller.rb
@@ -41,7 +41,7 @@ def edit
# POST /orders.json
def create
if request.xhr?
- comp_mask = params[:components_mask]
+ comps = params[:components]
is_delivery = params[:delivery_type] == 'delivery'
delivery_address = params[:delivery_address]
quantity = params[:quantity]
@@ -49,8 +49,10 @@ def create
user_email = params[:user_email]
user_phone = params[:user_phone]
user_comment = params[:user_comment]
-
- @order = Order.create!( components_mask: comp_mask, is_delivery: is_delivery, delivery_address: delivery_address, quantity: quantity, user_name: user_name, user_email: user_email, user_phone: user_phone, user_comment: user_comment)
+
+ @order = Order.create!( raisins: comps['raisins'] == 'true', chocolate_chips: comps['chocolate_chips'] == 'true', walnuts: comps['walnuts'] == 'true', flax_seeds: comps['flax seeds'], cinnamon: comps['cinnamon'],
+ is_delivery: is_delivery, delivery_address: delivery_address, quantity: quantity,
+ user_name: user_name, user_email: user_email, user_phone: user_phone, user_comment: user_comment)
#render :json => {order_id: @order.id, paypal_encrypted_str: @order.encrypt_paypal(thank_you_url, payment_notifications_url)}
render :json => {order_id: @order.id, paypal_encrypted_str: @order.encrypt_paypal(thank_you_url, 'http://marakujja.zapto.org/payment_notifications')}
View
27 app/helpers/orders_helper.rb
@@ -1,2 +1,29 @@
module OrdersHelper
+
+ def get_components_str_from_order(order)
+ selected_components = order.get_selected_components
+
+ if selected_components.any?
+ txt = componentName(selected_components[selected_components.length-1]);
+
+ #b and c
+ #a, b and c
+ second_last_component = selected_components.length-2;
+ second_last_component.downto(0) {|i|
+ if i == second_last_component
+ componentText = componentName(selected_components[i]) + " and " + txt
+ else
+ componentText = componentName(selected_components[i]) + ", " + txt
+ end
+ }
+ componentText = " with " + componentText
+ end
+ return componentText
+ end
+
+ def componentName(comp_name)
+ return "<span class='selected-component'>" + comp_name + "</span>"
+ end
+
+
end
View
36 app/models/order.rb
@@ -32,6 +32,7 @@ def paypal_form(return_url, notify_url)
end
def encrypt_paypal(return_url, notify_url)
+ #24.212.225.107
values = {
:business => 'mkmk_1335799555_biz@mail.ru',
:cmd => '_xclick',
@@ -58,34 +59,11 @@ def encrypt_for_paypal(values)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
- def getComponentsStr
- selected_components = Array.new
-
- (self.components_mask && F_RAISINS) && selected_components.push("raisins")
- (self.components_mask && F_CHOC_CHIPS) && selected_components.push("chocolate chips")
- (self.components_mask && F_WALNUTS) && selected_components.push("walnuts")
- (self.components_mask && F_FLAX_SEEDS) && selected_components.push("flax seeds")
- (self.components_mask && F_CINNAMON) && selected_components.push("cinamon")
-
- if selected_components.length > 0
- txt = componentName(selected_components[selected_components.length-1]);
-
- #b and c
- #a, b and c
- second_last_component = selected_components.length-2;
- second_last_component.downto(0) {|i|
- if i == second_last_component
- componentText = componentName(selected_components[i]) + " and " + txt
- else
- componentText = componentName(selected_components[i]) + ", " + txt
- end
- }
- componentText = " with " + componentText
- end
- return componentText
- end
-
- def componentName(comp_name)
- return "<span class='selected-component'>" + comp_name + "</span>"
+ def get_selected_components
+ components.push('raisins') && self.raisins
+ components.push('chocolate chips') && self.chocolate_chips
+ components.push('walnuts') && self.walnuts
+ components.push('flax seeds') && self.flax_seeds
+ components.push('cinnamon') && self.cinnamon
end
end
View
4 app/views/order_mailer/email_order.html.erb
@@ -9,8 +9,8 @@
<p>
Thank you for placing an order with us!
- You ordered Banana Bread <%= order.getComponentsStr %>.
- Your order # <%= @order.id %> is going to be delivered soon.
+ You ordered Banana Bread <%= order.get_components_str %>.
+ Your order # <%= @order.id %> is going to be delivered soon.
</p>
</body>
</html>
View
6 config/initializers/constants.rb
@@ -1,6 +0,0 @@
-#flags for components mask
-F_RAISINS = 16
-F_CHOC_CHIPS = 8
-F_WALNUTS = 4
-F_FLAX_SEEDS = 2
-F_CINNAMON = 1
View
10 db/migrate/20120421033448_create_orders.rb
@@ -1,15 +1,21 @@
class CreateOrders < ActiveRecord::Migration
def change
create_table :orders do |t|
- t.integer :components_mask
+ #t.string :components
t.integer :quantity
- t.integer :is_delivery
+ t.boolean :is_delivery
t.string :delivery_address
t.datetime :purchased_at
t.string :user_name
t.string :user_email
t.string :user_phone
t.string :user_comment
+
+ t.boolean :raisins
+ t.boolean :chocolate_chips
+ t.boolean :walnuts
+ t.boolean :flax_seeds
+ t.boolean :cinnamon
t.timestamps
end
View
8 db/schema.rb
@@ -14,15 +14,19 @@
ActiveRecord::Schema.define(:version => 20120509181340) do
create_table "orders", :force => true do |t|
- t.integer "components_mask"
t.integer "quantity"
- t.integer "is_delivery"
+ t.boolean "is_delivery"
t.string "delivery_address"
t.datetime "purchased_at"
t.string "user_name"
t.string "user_email"
t.string "user_phone"
t.string "user_comment"
+ t.boolean "raisins"
+ t.boolean "chocolate_chips"
+ t.boolean "walnuts"
+ t.boolean "flax_seeds"
+ t.boolean "cinnamon"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Please sign in to comment.
Something went wrong with that request. Please try again.