mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
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
17 lines
634 B
CoffeeScript
17 lines
634 B
CoffeeScript
angular.module('admin.enterprises').directive 'enterpriseSwitcher', (NavigationCheck) ->
|
|
restrict: 'A'
|
|
require: 'ngModel'
|
|
link: (scope, element, attr, ngModel) ->
|
|
initial = element[0].getAttribute('data-initial')
|
|
|
|
element.on 'change', ->
|
|
if not NavigationCheck.confirmLeave()
|
|
# Reset the current dropdown selection if staying on page
|
|
ngModel.$setViewValue initial
|
|
ngModel.$render()
|
|
element.select2 'val', initial
|
|
return
|
|
|
|
NavigationCheck.clear() # Don't ask twice if leaving
|
|
window.location = element[0].querySelector('option[selected]').getAttribute('data-url')
|