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:
Maikel Linke
2017-01-11 15:54:00 +11:00
parent 27903ab744
commit b8622e95b7
5 changed files with 24 additions and 29 deletions

View File

@@ -1,3 +0,0 @@
angular.module('admin.utils').service 'FormState', ->
#Simple service to share form state across different controllers/scopes
{ isDirty: false }

View File

@@ -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