mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge branch 'enterprise-form-confirmation'
This commit is contained in:
@@ -12,7 +12,8 @@ angular.module("admin.enterprises")
|
||||
# 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 = ->
|
||||
"You are editing an enterprise!"
|
||||
if $scope.enterprise.$dirty
|
||||
"Your changes to the enterprise are not saved yet."
|
||||
|
||||
for payment_method in $scope.PaymentMethods
|
||||
payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
angular.module("admin.utils").directive "navCheck", (NavigationCheck)->
|
||||
angular.module("admin.utils").directive "navCheckCallback", (NavigationCheck)->
|
||||
restrict: 'A'
|
||||
scope:
|
||||
navCallback: '&'
|
||||
navCheckCallback: '&'
|
||||
link: (scope,element,attributes) ->
|
||||
# Define navigationCallback on a controller in scope, otherwise this default will be used:
|
||||
scope.navCallback ||= ->
|
||||
# Provide a callback, otherwise this default will be used:
|
||||
callback = scope.navCheckCallback()
|
||||
callback ||= ->
|
||||
"You will lose any unsaved work!"
|
||||
NavigationCheck.register(scope.navCallback)
|
||||
NavigationCheck.register(callback)
|
||||
|
||||
@@ -15,7 +15,8 @@ angular.module("admin.utils")
|
||||
onBeforeUnloadHandler: ($event) =>
|
||||
message = @getMessage()
|
||||
if message
|
||||
($event or $window.event).preventDefault()
|
||||
# following: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
|
||||
($event or $window.event).returnValue = message
|
||||
message
|
||||
|
||||
# Action for angular navigation.
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
= form_for [main_app, :admin, @enterprise], html: { name: "enterprise", "ng-app" => 'admin.enterprises', "ng-submit" => "navClear()", "ng-controller" => 'enterpriseCtrl' , "nav-check" => '', "nav-callback" => 'enterpriseNavCallback()' } do |f|
|
||||
-# Not all inputs are ng inputs, they don't make the 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
|
||||
.sixteen.columns.alpha
|
||||
.eleven.columns.alpha.fullwidth_inputs
|
||||
|
||||
Reference in New Issue
Block a user