Automatically closing the accordion if the form is already valid

This commit is contained in:
Will Marshall
2014-05-30 11:58:22 +10:00
parent dd0907addd
commit 1a47a7486e
5 changed files with 41 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
Darkswarm.controller "AccordionCtrl", ($scope, storage) ->
Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout) ->
$scope.accordion =
details: true
shipping: false
@@ -9,3 +9,8 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage) ->
$scope.show = (name)->
$scope.accordion[name] = true
$timeout =>
if $scope.checkout.$valid
for k, v of $scope.accordion
$scope.accordion[k] = false

View File

@@ -1,5 +1,6 @@
Darkswarm.controller "DetailsCtrl", ($scope) ->
angular.extend(this, new FieldsetMixin($scope))
$scope.name = "details"
$scope.nextPanel = "billing"
@@ -11,11 +12,3 @@ Darkswarm.controller "DetailsCtrl", ($scope) ->
$scope.fullName = ->
[$scope.order.bill_address.firstname ? null,
$scope.order.bill_address.lastname ? null].join(" ").trim()
#$scope.$watch ->
#$scope.detailsValid()
#, (valid)->
#if valid
#$scope.show("billing")

View File

@@ -1,3 +1,3 @@
Darkswarm.factory 'CheckoutFormState', ()->
# Just a singleton place to store data about the form statr
# Just a singleton place to store data about the form state
new class CheckoutFormState

View File

@@ -15,11 +15,10 @@ Spree::Admin::OrdersController.class_eval do
per(params[:per_page] || Spree::Config[:orders_per_page])
} } }
private
def load_spree_api_key
current_user.generate_spree_api_key! unless spree_current_user.spree_api_key
@spree_api_key = spree_current_user.spree_api_key
end
end
end

View File

@@ -1,19 +1,40 @@
describe "AccordionCtrl", ->
ctrl = null
scope = scope
scope = null
beforeEach ->
module "Darkswarm"
localStorage.clear()
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
scope.order =
id: 129
ctrl = $controller 'AccordionCtrl', {$scope: scope}
it "defaults the details accordion to visible", ->
expect(scope.accordion.details).toEqual true
describe "loading incomplete form", ->
beforeEach ->
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
scope.order =
id: 129
ctrl = $controller 'AccordionCtrl', {$scope: scope}
it "changes accordion", ->
scope.show "shipping"
expect(scope.accordion["shipping"]).toEqual true
it "defaults the details accordion to visible", ->
expect(scope.accordion.details).toEqual true
it "changes accordion", ->
scope.show "shipping"
expect(scope.accordion["shipping"]).toEqual true
describe "loading complete form", ->
beforeEach ->
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
scope.checkout =
$valid: true
scope.order =
id: 129
ctrl = $controller 'AccordionCtrl', {$scope: scope}
it "automatically closes all sections if the entire form is valid", ->
waitsFor ->
(scope.accordion.details and
scope.accordion.shipping and
scope.accordion.payment and
scope.accordion.billing) == false
, "the accordion to close", 100