From c4e00dbb474c8dfd663d6c56a79b5fe435cdcca8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 30 Jul 2014 10:00:27 +0100 Subject: [PATCH] CRM-14353 CRM-15053 - Better handler for dialog close events which accounts for esc key --- js/crm.ajax.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index b647e370c8..417e62296b 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -344,9 +344,7 @@ // CRM-14353 - Warn of unsaved changes for all forms except those which have opted out function cancelAction() { var dirty = CRM.utils.initialValueChanged($('form:not([data-warn-changes=false])', widget)); - widget - .attr('data-unsaved-changes', dirty ? 'true' : 'false') - .dialog('close'); + widget.attr('data-unsaved-changes', dirty ? 'true' : 'false'); if (dirty) { var id = widget.attr('id') + '-unsaved-alert', title = widget.dialog('option', 'title'), @@ -357,10 +355,13 @@ }); } } - if (widget.data('uiDialog')) { - // CRM-14353 - This is a bit harsh but we are removing jQuery UI's event handler from the close button and adding our own - widget.parent().find('.ui-dialog-titlebar-close').first().off().click(cancelAction); - } + + widget.data('uiDialog') && widget.on('dialogbeforeclose', function(e) { + // CRM-14353 - Warn unsaved changes if user clicks close button or presses "esc" + if (e.originalEvent) { + cancelAction(); + } + }); widget.on('crmFormLoad.crmForm', function(event, data) { var $el = $(this) @@ -373,6 +374,7 @@ $el.trigger('crmFormCancel', e); if ($el.data('uiDialog') && settings.autoClose) { cancelAction(); + $el.dialog('close'); } else if (!settings.autoClose) { $el.crmSnippet('resetUrl').crmSnippet('refresh'); -- 2.25.1