mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Moving navigation check to controller
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user