diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index d218f7caea..147c08943d 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -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 diff --git a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee b/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee deleted file mode 100644 index fee80e9acf..0000000000 --- a/app/assets/javascripts/admin/utils/directives/navigation_check.js.coffee +++ /dev/null @@ -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) diff --git a/app/views/admin/enterprises/_ng_form.html.haml b/app/views/admin/enterprises/_ng_form.html.haml index 76ec768a3a..91a3c4e3aa 100644 --- a/app/views/admin/enterprises/_ng_form.html.haml +++ b/app/views/admin/enterprises/_ng_form.html.haml @@ -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