Moving navigation check to controller

This commit is contained in:
Rob Harrington
2015-01-20 09:00:17 +11:00
parent 585c061fb0
commit a0990c107f
3 changed files with 5 additions and 14 deletions

View File

@@ -11,10 +11,13 @@ angular.module("admin.enterprises")
# Provide a callback for generating warning messages displayed before leaving the page. This is passed in
# from a directive "nav-check" in the page - if we pass it here it will be called in the test suite,
# and on all new uses of this contoller, and we might not want that .
$scope.enterpriseNavCallback = ->
enterpriseNavCallback = ->
if $scope.enterprise.$dirty
"Your changes to the enterprise are not saved yet."
# Register the NavigationCheck callback
NavigationCheck.register(enterpriseNavCallback)
for payment_method in $scope.PaymentMethods
payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids

View File

@@ -1,10 +0,0 @@
angular.module("admin.utils").directive "navCheckCallback", (NavigationCheck)->
restrict: 'A'
scope:
navCheckCallback: '&'
link: (scope,element,attributes) ->
# Provide a callback, otherwise this default will be used:
callback = scope.navCheckCallback()
callback ||= ->
"You will lose any unsaved work!"
NavigationCheck.register(callback)

View File

@@ -1,12 +1,10 @@
-# Not all inputs are ng inputs, they don't make the form dirty on change.
-# Not all inputs are ng inputs, they don't make the ng-form dirty on change.
-# ng-change is only valid for inputs, not for a form.
-# So we use onchange and have to get the scope to access the ng controller
-# The nav-check-callback is warning on leave if the form is dirty.
= form_for [main_app, :admin, @enterprise], html: { name: "enterprise",
"ng-app" => 'admin.enterprises',
"ng-submit" => "navClear()",
"ng-controller" => 'enterpriseCtrl',
"nav-check-callback" => 'enterpriseNavCallback',
'onchange' => 'angular.element(enterprise).scope().enterprise.$setDirty()',
} do |f|
.row