mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Automatically closing the accordion if the form is already valid
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user