Renaming some methods in our experimental

This commit is contained in:
Will Marshall
2014-04-09 11:51:12 +10:00
parent b293efd110
commit 09d22f74ec
5 changed files with 19 additions and 17 deletions

View File

@@ -3,24 +3,24 @@ Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage) ->
$scope.order = $scope.Order = Order
$scope.accordion = {}
storage.bind $scope, "user", { defaultValue: true}
$scope.disable = ->
$scope.user = false
$scope.details = true
$scope.show = (name)->
$scope.accordion[name] = true
storage.bind $scope, "accordion.user", { defaultValue: true}
storage.bind $scope, "accordion.details"
storage.bind $scope, "accordion.billing"
storage.bind $scope, "accordion.shipping"
storage.bind $scope, "accordion.payment"
# Validation utilities to keep things DRY
$scope.dirtyValid = (name)->
$scope.dirty(name) and $scope.valid(name)
$scope.dirtyInvalid = (name)->
$scope.dirty(name) and $scope.invalid(name)
$scope.dirty = (name)->
$scope.checkout[name].$dirty
$scope.valid = (name)->
$scope.invalid = (name)->
$scope.checkout[name].$invalid
# Validations
$scope.error = (name)->
$scope.checkout[name].$error
$scope.required = (name)->
@@ -43,10 +43,12 @@ Darkswarm.controller "DetailsSubCtrl", ($scope) ->
$scope.detailsValid()
, (valid)->
if valid
$scope.accordion.details = false
$scope.accordion.billing = true
$scope.show("billing")
$scope.detailsFields = ->
{"order[email]" : {email: "must be email", required: "field required"}}
["order[email]",
"order[bill_address_attributes][phone]",
"order[bill_address_attributes][firstname]",
@@ -54,14 +56,14 @@ Darkswarm.controller "DetailsSubCtrl", ($scope) ->
$scope.emailName = 'order[email]'
$scope.emailValid = ->
$scope.dirtyValid($scope.emailName)
$scope.dirtyInvalid($scope.emailName)
$scope.emailError = ->
return "can't be blank" if $scope.required($scope.emailName)
return "must be valid" if $scope.email($scope.emailName)
$scope.phoneName = "order[bill_address_attributes][phone]"
$scope.phoneValid = ->
$scope.dirtyValid($scope.phoneName)
$scope.dirtyInvalid($scope.phoneName)
$scope.phoneError = ->
"must be a number"

View File

@@ -6,4 +6,4 @@
.large-4.columns.text-center{"ng-controller" => "AuthenticationActionsCtrl"}
%button{"ng-click" => "toggle('/signup')"} Signup
.large-4.columns.text-center
%button{"ng-click" => "disable()"} Checkout as guest
%button{"ng-click" => "show('details')"} Checkout as guest

View File

@@ -1,7 +1,6 @@
%fieldset#details
%accordion-group{"is-open" => "accordion.details"}
%div{"ng-controller" => "DetailsSubCtrl"}
{{ detailsValid() }}
%accordion-heading
.row
.large-6.columns
@@ -12,8 +11,8 @@
.row
.large-6.columns
= f.email_field :email, required: "", "ng-model" => "order.email",
"ng-change" => "next()",
"ng-class" => "{error: '!emailValid()'}"
%small.error.medium.input-text{"ng-show" => "emailValid()"}
{{ emailError() }}
@@ -31,4 +30,3 @@
.large-6.columns
= ba.text_field :lastname, "ng-model" => "order.bill_address.lastname"

View File

@@ -6,7 +6,7 @@
= render partial: "shop/details"
%accordion.row{"close-others" => "false"}
%accordion.row{"close-others" => "true"}
%checkout{"ng-controller" => "CheckoutCtrl"}
.large-9.columns
- unless spree_current_user

View File

@@ -8,6 +8,7 @@ describe Shop::CheckoutController do
order.stub(:checkout_allowed?).and_return true
controller.stub(:check_authorization).and_return true
end
it "redirects home when no distributor is selected" do
get :edit
response.should redirect_to root_path
@@ -46,6 +47,7 @@ describe Shop::CheckoutController do
end
describe "building the order" do
before do
controller.stub(:current_distributor).and_return(distributor)
controller.stub(:current_order_cycle).and_return(order_cycle)