mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Remove window unload event listener from edit order cycle cancel link
This commit is contained in:
committed by
Sigmund Petersen
parent
a11873559b
commit
37ab832b86
@@ -9,6 +9,7 @@ angular.module("admin.utils")
|
||||
$window.onbeforeunload = @onBeforeUnloadHandler
|
||||
|
||||
$rootScope.$on "$locationChangeStart", @locationChangeStartHandler
|
||||
$window.onBeforeUnloadHandler = @onBeforeUnloadHandler
|
||||
|
||||
# Action for regular browser navigation.
|
||||
onBeforeUnloadHandler: ($event) =>
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
= t('.proceed')
|
||||
%button.button.secondary{ "ng-click": "submit($event, '#{main_app.admin_order_cycles_path}')", type: "button", style: "display: none;", data: { action: 'click->modal#close', 'trigger-action': 'saveAndBack' } }
|
||||
= t('.proceed')
|
||||
= link_to t('.cancel'), admin_order_cycles_path, id: 'cancel', class: 'button primary'
|
||||
|
||||
= link_to t('.cancel'), admin_order_cycles_path, id: 'cancel', class: 'button primary', data: { 'order-cycle-form-target': 'cancel' }
|
||||
- if action == 'bulk_update'
|
||||
%button.button.secondary{ "ng-click": "saveAll($event)", type: "button", style: "display: none;", data: { action: 'click->modal#close', trigger_action: 'bulk_save' } }
|
||||
= t('.proceed')
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['statusMessage']
|
||||
static targets = ['statusMessage', 'cancel']
|
||||
connect() {
|
||||
this.observer = new MutationObserver(this.updateCallback);
|
||||
this.observer.observe(
|
||||
this.statusMessageTarget,
|
||||
{ attributes: true, attributeOldValue: true, attributeFilter: ['data-type'] }
|
||||
);
|
||||
|
||||
if (this.hasCancelTarget) {
|
||||
this.cancelTarget.addEventListener('click', this.removeUnloadEvent)
|
||||
}
|
||||
}
|
||||
|
||||
// Callback to trigger warning modal
|
||||
@@ -38,7 +42,14 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
removeUnloadEvent() {
|
||||
window.removeEventListener('beforeunload', window.onBeforeUnloadHandler)
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.observer.disconnect();
|
||||
if (this.hasCancelTarget) {
|
||||
this.cancelTarget.removeEventListener('click', this.removeUnloadEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user