From 3487ee444a885de558c8586f137cd7d477e27d65 Mon Sep 17 00:00:00 2001 From: Valerio Bozzolan Date: Tue, 14 Mar 2023 20:24:32 +0100 Subject: [PATCH] Fix regression in new confirmation Dialog Summary: Fix a JavaScript regression encapsulating the problematic part into an `if`. Other minor changes: - dedicate a variable for the confirmation messages to improve i18n in the future (but also to avoid 80 characters and make lint happy) - replace `confirm` with `window.confirm` (to make lint happy) Ref T15034 Ref D25015 Test Plan: - surf on your local Phorge - no JavaScript errors in console Reviewers: bekay, Ekubischta, O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: speck, tobiaswiese, Matthew, Cigaryno Maniphest Tasks: T15034 Differential Revision: https://we.phorge.it/D25076 --- .../rsrc/externals/javelin/lib/Workflow.js | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/webroot/rsrc/externals/javelin/lib/Workflow.js b/webroot/rsrc/externals/javelin/lib/Workflow.js index 7d63a3408a..6d91682dbc 100644 --- a/webroot/rsrc/externals/javelin/lib/Workflow.js +++ b/webroot/rsrc/externals/javelin/lib/Workflow.js @@ -404,14 +404,18 @@ JX.install('Workflow', { } } - var form = JX.DOM.scry(this._root, 'form', 'jx-dialog'); - if (form.length) { - JX.DOM.listen(form[0], 'keydown', null, function(e) { - if (e.getSpecialKey()) { - return; - } - JX.Stratcom.addSigil(form[0], 'dialog-keydown'); - }); + // Only when the response is a Dialog, check if the user + // is quitting with pending changes + if (this._root) { + var form = JX.DOM.scry(this._root, 'form', 'jx-dialog'); + if (form.length) { + JX.DOM.listen(form[0], 'keydown', null, function(e) { + if (e.getSpecialKey()) { + return; + } + JX.Stratcom.addSigil(form[0], 'dialog-keydown'); + }); + } } }, _push : function() { @@ -546,13 +550,20 @@ JX.install('Workflow', { return; } - var form = JX.DOM.scry(active._root, 'form', 'jx-dialog'); - if ( - form.length && - JX.Stratcom.hasSigil(form[0], 'dialog-keydown') && - !confirm('Form data may have changed. Are you sure you want to close this dialog?') - ) { - return; + // Only when the response is a Dialog, check if the user + // is quitting with pending changes + if (active._root) { + var form = JX.DOM.scry(active._root, 'form', 'jx-dialog'); + var confirmMsg = + 'Form data may have changed. ' + + 'Are you sure you want to close this dialog?'; + if ( + form.length && + JX.Stratcom.hasSigil(form[0], 'dialog-keydown') && + !window.confirm(confirmMsg) + ) { + return; + } } JX.Workflow._pop();