Standing Orders: form split into ngForm elements with staggered validation

This commit is contained in:
Rob Harrington
2016-09-23 16:58:58 +10:00
parent ac5fe6a9fb
commit 897eb11512
9 changed files with 66 additions and 47 deletions

View File

@@ -0,0 +1,10 @@
angular.module("admin.standingOrders").controller "DetailsController", ($scope, StatusMessage) ->
$scope.submitted = false
$scope.next = ->
$scope.submitted = true
if $scope.standing_order_details_form.$valid
StatusMessage.clear()
$scope.setView('products')
else
StatusMessage.display 'failure', 'Oops! There seems to be a problem...'

View File

@@ -0,0 +1,9 @@
angular.module("admin.standingOrders").controller "ProductsController", ($scope, StatusMessage) ->
$scope.next = ->
if $scope.standingOrder.standing_line_items.length > 0
StatusMessage.clear()
$scope.setView('review')
else
StatusMessage.display 'failure', 'Please add at least one product'
$scope.back = -> $scope.setView('details')

View File

@@ -7,20 +7,13 @@ angular.module("admin.standingOrders").controller "StandingOrderController", ($s
$scope.errors = StandingOrder.errors
$scope.newItem = { variant_id: 0, quantity: 1 }
$scope.distributor_id = $scope.standingOrder.shop_id # variant selector requires distributor_id
$scope.views = ['details','products','review']
$scope.view = if $scope.standingOrder.id? then $scope.views[$scope.views.length-1] else $scope.views[0]
$scope.view = if $scope.standingOrder.id? then 'review' else 'details'
$scope.save = ->
$scope.standing_order_form.$setPristine()
StandingOrder.save()
$scope.next = ->
viewIndex = $scope.views.indexOf($scope.view)
$scope.view = $scope.views[viewIndex+1]
$scope.back = ->
viewIndex = $scope.views.indexOf($scope.view)
$scope.view = $scope.views[viewIndex-1]
$scope.setView = (view) -> $scope.view = view
$scope.addStandingLineItem = ->
StandingOrder.buildItem($scope.newItem)