From e9a3e05466a94cf58c27a17f8c71630fbbd804d7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 10 Jun 2014 14:01:48 +0100 Subject: [PATCH] CRM-14353 - Allow forms to opt-out of warnings --- js/crm.ajax.js | 8 +++++--- templates/CRM/common/TabHeader.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 0fd7f4b303..e2752785ca 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -341,11 +341,13 @@ var widget = CRM.loadPage(url, settings).off('.crmForm'); function cancelAction() { - var dirty = CRM.utils.initialValueChanged(widget), - title = widget.dialog('option', 'title'); - widget.attr('data-unsaved-changes', dirty ? 'true' : 'false').dialog('close'); + var dirty = CRM.utils.initialValueChanged($('form:not([data-warn-changes=false])', widget)); + widget + .attr('data-unsaved-changes', dirty ? 'true' : 'false') + .dialog('close'); if (dirty) { var id = widget.attr('id') + '-unsaved-alert', + title = widget.dialog('option', 'title'), alert = CRM.alert('

' + ts('%1 has not been saved.', {1: title}) + '

' + ts('Restore') + '

', ts('Unsaved Changes'), 'alert unsaved-dialog', {expires: 60000}); $('#' + id).button({icons: {primary: 'ui-icon-arrowreturnthick-1-w'}}).click(function(e) { widget.attr('data-unsaved-changes', 'false').dialog('open'); diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index e923eed2a7..82c19815e0 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -9,8 +9,8 @@ CRM.$(function($) { tabSettings.active = tabSettings.active ? $('#tab_' + tabSettings.active).prevAll().length : 0; $("#mainTabContainer") .on('tabsbeforeactivate', function(e, ui) { - // Warn of unsaved changes - requires formNavigate.tpl to be included in each tab - if (CRM.utils.initialValueChanged(ui.oldPanel)) { + // CRM-14353 - Warn of unsaved changes for all forms except those which have opted out + if (CRM.utils.initialValueChanged($('form:not([data-warn-changes=false])', ui.oldPanel))) { CRM.alert(ts('Your changes in the %1 tab have not been saved.', {1: ui.oldTab.text()}), ts('Unsaved Changes'), 'warning'); } }) -- 2.25.1