diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index 89e4b1d807..e94c975952 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -14,6 +14,7 @@ #= require ../shared/jquery.timeago #= require foundation #= require ./darkswarm +#= require ./overrides #= require_tree ./mixins #= require_tree . diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee index 2c07d96da5..33b9ed9184 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee @@ -1,3 +1,6 @@ Darkswarm.controller "BillingCtrl", ($scope) -> angular.extend(this, new FieldsetMixin($scope)) $scope.name = "billing" + $scope.nextPanel = "shipping" + + diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee index a218e123b1..dbf273e9e8 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee @@ -1,6 +1,7 @@ Darkswarm.controller "DetailsCtrl", ($scope) -> angular.extend(this, new FieldsetMixin($scope)) $scope.name = "details" + $scope.nextPanel = "billing" #$scope.$watch -> diff --git a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee index 7ad47f5398..3b91b5c44f 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee @@ -1,6 +1,6 @@ Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage) -> - $scope.Order = Order - $scope.order = Order.order + $scope.order = $scope.Order = Order + #$scope.order = Order.order $scope.accordion = {} $scope.show = (name)-> @@ -11,8 +11,9 @@ Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage) -> storage.bind $scope, "accordion.billing" storage.bind $scope, "accordion.shipping" storage.bind $scope, "accordion.payment" - storage.bind $scope, "order.ship_address_same_as_billing", { defaultValue: true} - storage.bind $scope, "order.shipping_method_id" + + storage.bind $scope, "Order.formstate.ship_address_same_as_billing", { defaultValue: true} + storage.bind $scope, "order", {storeName: "order_#{$scope.order.id}"} $scope.purchase = (event)-> event.preventDefault() diff --git a/app/assets/javascripts/darkswarm/mixins/fieldset_mixin.js.coffee b/app/assets/javascripts/darkswarm/mixins/fieldset_mixin.js.coffee index 96273ffaed..ff01db5483 100644 --- a/app/assets/javascripts/darkswarm/mixins/fieldset_mixin.js.coffee +++ b/app/assets/javascripts/darkswarm/mixins/fieldset_mixin.js.coffee @@ -1,4 +1,8 @@ window.FieldsetMixin = ($scope)-> + $scope.next = (event)-> + event.preventDefault() + $scope.show $scope.nextPanel + $scope.valid = -> $scope.form().$valid @@ -28,7 +32,7 @@ window.FieldsetMixin = ($scope)-> when "number" then "must be number" when "email" then "must be email address" - server_errors = $scope.Order.errors[path.replace('order.', '')] - errors.push server_errors if server_errors? - (errors.filter (error) -> error?).unique().join ", " + #server_errors = $scope.Order.errors[path.replace('order.', '')] + #errors.push server_errors if server_errors? + (errors.filter (error) -> error?).join ", " diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index 61604e3dbb..46274eb269 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -1,10 +1,12 @@ -Darkswarm.factory 'Order', ($resource, Product, order, $http)-> +Darkswarm.factory 'Order', ($resource, Product, order, $http, storage)-> new class Order errors: {} + form_state: {} + constructor: -> - @order = order + @[key] = val for key, val of order # zip the order data into our service # Default to first shipping method if none selected - @order.shipping_method_id ||= parseInt(Object.keys(@order.shipping_methods)[0]) + @shipping_method_id ||= parseInt(Object.keys(@shipping_methods)[0]) navigate: (path)-> window.location.pathname = path @@ -18,7 +20,7 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)-> # Rails wants our Spree::Address data to be provided with _attributes preprocess: -> munged_order = {} - for name, value of @order # Clone all data from the order JSON object + for name, value of @ # Clone all data from the order JSON object switch name when "bill_address" munged_order["bill_address_attributes"] = value @@ -34,7 +36,7 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)-> munged_order shippingMethod: -> - @order.shipping_methods[@order.shipping_method_id] + @shipping_methods[@shipping_method_id] requireShipAddress: -> @shippingMethod()?.require_ship_address @@ -43,7 +45,7 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)-> @shippingMethod()?.price paymentMethod: -> - @order.payment_methods[@order.payment_method_id] + @payment_methods[@payment_method_id] cartTotal: -> - @shippingPrice() + @order.display_total + @shippingPrice() + @display_total diff --git a/app/views/shared/_validated_input.html.haml b/app/views/shared/_validated_input.html.haml index eb4c524a65..251c60b975 100644 --- a/app/views/shared/_validated_input.html.haml +++ b/app/views/shared/_validated_input.html.haml @@ -3,6 +3,6 @@ "ng-model" => path, required: required, type: type, - "ng-class" => "{error: '!fieldValid(\"#{path}\")'}"} + "ng-class" => "{error: !fieldValid('#{path}')}"} %small.error.medium.input-text{"ng-show" => "!fieldValid('#{path}')"} = "{{ fieldErrors('#{path}') }}" diff --git a/app/views/shop/checkout/_billing.html.haml b/app/views/shop/checkout/_billing.html.haml index b32c0d2498..fe7232dfbd 100644 --- a/app/views/shop/checkout/_billing.html.haml +++ b/app/views/shop/checkout/_billing.html.haml @@ -30,3 +30,7 @@ .large-6.columns.right = ba.select :country_id, available_countries.map{|c|[c.name, c.id]}, {include_blank: false}, "ng-model" => "order.bill_address.country_id" + + .row + .large-12.columns.text-right + %button{"ng-disabled" => "details.$invalid", "ng-click" => "next($event)"} Next diff --git a/app/views/shop/checkout/_details.html.haml b/app/views/shop/checkout/_details.html.haml index 0faa40e858..3f3a815452 100644 --- a/app/views/shop/checkout/_details.html.haml +++ b/app/views/shop/checkout/_details.html.haml @@ -24,3 +24,7 @@ .large-6.columns = validated_input "Last Name", "order.bill_address.lastname" + + .row + .large-12.columns.text-right + %button{"ng-disabled" => "details.$invalid", "ng-click" => "next($event)"} Next diff --git a/app/views/shop/checkout/_shipping.html.haml b/app/views/shop/checkout/_shipping.html.haml index d5692b1bea..4bafd6ddf5 100644 --- a/app/views/shop/checkout/_shipping.html.haml +++ b/app/views/shop/checkout/_shipping.html.haml @@ -22,14 +22,14 @@ = @order.order_cycle.pickup_instructions_for(@order.distributor) = f.fields_for :ship_address, @order.ship_address do |sa| - #ship_address{"ng-show" => "Order.requireShipAddress()"} + #ship_address{"ng-if" => "Order.requireShipAddress()"} %label = hidden_field_tag "order[ship_address_same_as_billing]", "false" = check_box_tag "order[ship_address_same_as_billing]", true, @order.ship_address_same_as_billing, "ng-model" => "order.ship_address_same_as_billing" Shipping address same as billing address? - %div.visible{"ng-show" => "!order.ship_address_same_as_billing"} + %div.visible{"ng-if" => "!order.ship_address_same_as_billing"} .row .large-12.columns = validated_input "Address", "order.ship_address.address1" @@ -55,21 +55,3 @@ .row .large-6.columns = validated_input "Phone", "order.ship_address.phone" - - -##ship_address_hidden{"ng-show" => "order.ship_address_same_as_billing"} - -#= sa.hidden_field :address1, "ng-value" => "order.bill_address.address1", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :address2, "ng-value" => "order.bill_address.address2", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :city, "ng-value" => "order.bill_address.city", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :country_id, "ng-value" => "order.bill_address.country_id", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :zipcode, "ng-value" => "order.bill_address.zipcode", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :firstname, "ng-value" => "order.bill_address.firstname", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :lastname, "ng-value" => "order.bill_address.lastname", - -#"ng-disabled" => "!order.ship_address_same_as_billing" - -#= sa.hidden_field :phone, "ng-value" => "order.bill_address.phone", - -#"ng-disabled" => "!order.ship_address_same_as_billing" diff --git a/spec/javascripts/application_spec.js b/spec/javascripts/application_spec.js index ec5fef8832..cd070d79e9 100644 --- a/spec/javascripts/application_spec.js +++ b/spec/javascripts/application_spec.js @@ -3,3 +3,4 @@ //= require angular-animate //= require angular-mocks //= require angular-cookies +// diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee index a536988720..b2f4005199 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee @@ -23,9 +23,13 @@ describe "DetailsCtrl", -> expect(scope.fieldValid('path')).toEqual false it "returns errors by path", -> + scope.Order = + errors: -> scope.details = path: $error: email: true required: true - expect(scope.fieldErrors('path')).toEqual ["must be email address", "must not be blank"].join ", " + expect(scope.fieldErrors('path')).toEqual ["must be email address", "can't be blank"].join ", " + + diff --git a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee index 9559af0fd2..181d1acd31 100644 --- a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee @@ -29,26 +29,26 @@ describe 'Order service', -> spyOn(Order, "navigate") # Stubbing out writes to window.location it "defaults the shipping method to the first", -> - expect(Order.order.shipping_method_id).toEqual 7 + expect(Order.shipping_method_id).toEqual 7 expect(Order.shippingMethod()).toEqual { require_ship_address : true, price : 0 } # This is now handled via localStorage defaults xit "defaults to 'same as billing' for address", -> - expect(Order.order.ship_address_same_as_billing).toEqual true + expect(Order.ship_address_same_as_billing).toEqual true it 'Tracks whether a ship address is required', -> expect(Order.requireShipAddress()).toEqual true - Order.order.shipping_method_id = 25 + Order.shipping_method_id = 25 expect(Order.requireShipAddress()).toEqual false it 'Gets the current shipping price', -> expect(Order.shippingPrice()).toEqual 0.0 - Order.order.shipping_method_id = 25 + Order.shipping_method_id = 25 expect(Order.shippingPrice()).toEqual 13 it 'Gets the current payment method', -> expect(Order.paymentMethod()).toEqual null - Order.order.payment_method_id = 99 + Order.payment_method_id = 99 expect(Order.paymentMethod()).toEqual {test: "foo"} it "Posts the Order to the server", -> @@ -63,7 +63,7 @@ describe 'Order service', -> expect(Order.preprocess().ship_address).toBe(undefined) it "Munges the order attributes to clone ship address from bill address", -> - Order.order.ship_address_same_as_billing = false + Order.ship_address_same_as_billing = false expect(Order.preprocess().ship_address_attributes).toEqual(orderData.ship_address) - Order.order.ship_address_same_as_billing = true + Order.ship_address_same_as_billing = true expect(Order.preprocess().ship_address_attributes).toEqual(orderData.bill_address)