mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
Re-use NavigationCheck logic
The enterprise switcher now uses the same code as NavigationCheck to confirm leaving a changed form. This makes FormState obsolete. Conflicts: app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
angular.module('admin.utils').service 'FormState', ->
|
||||
#Simple service to share form state across different controllers/scopes
|
||||
{ isDirty: false }
|
||||
@@ -20,13 +20,17 @@ angular.module("admin.utils")
|
||||
|
||||
# Action for angular navigation.
|
||||
locationChangeStartHandler: ($event) =>
|
||||
message = @getMessage()
|
||||
if message and not $window.confirm(message)
|
||||
if not @confirmLeave()
|
||||
$event.stopPropagation() if $event.stopPropagation
|
||||
$event.preventDefault() if $event.preventDefault
|
||||
$event.cancelBubble = true
|
||||
$event.returnValue = false
|
||||
|
||||
# Check if leaving is okay
|
||||
confirmLeave: =>
|
||||
message = @getMessage()
|
||||
!message or $window.confirm(message)
|
||||
|
||||
# Runs callback functions to retreive most recently added non-empty message.
|
||||
getMessage: ->
|
||||
message = null
|
||||
|
||||
Reference in New Issue
Block a user