CRM-14353 - Allow forms to opt-out of warnings
authorColeman Watts <coleman@civicrm.org>
Tue, 10 Jun 2014 13:01:48 +0000 (14:01 +0100)
committerColeman Watts <coleman@civicrm.org>
Tue, 10 Jun 2014 13:01:48 +0000 (14:01 +0100)
js/crm.ajax.js
templates/CRM/common/TabHeader.js

index 0fd7f4b3031b907e93022e1bf86793f39279b7fa..e2752785cadd9fed80adb2f00c4536b2dc24836e 100644 (file)
     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('<p>' + ts('%1 has not been saved.', {1: title}) + '</p><p><a href="#" id="' + id + '">' + ts('Restore') + '</a></p>', 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');
index e923eed2a7d875a2b5a2d8cf8c4234f584856277..82c19815e039c202bb7e671862d2df45570e7fa1 100644 (file)
@@ -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 <em>%1</em> tab have not been saved.', {1: ui.oldTab.text()}), ts('Unsaved Changes'), 'warning');
       }
     })