CRM-14843 - fixes for upgrade script including INSERT IGNORE usage.
[civicrm-core.git] / js / Common.js
index 68b06ce38d34170cb91934de71828576c863bec5..abc5cae3919372b766bb09156a5cef8341ce8d66 100644 (file)
@@ -245,15 +245,15 @@ CRM.validate = CRM.validate || {
  */
   CRM.utils.initialValueChanged = function(el) {
     var isDirty = false;
-    $(':input:visible, :input.select2-offscreen', el).each(function () {
+    $(':input:visible, .select2-container:visible+:input.select2-offscreen', el).not('[type=submit], [type=button], .crm-action-menu').each(function () {
       var initialValue = $(this).data('crm-initial-value');
       // skip change of value for submit buttons
-      if (initialValue !== undefined && !$(this).hasClass('form-submit') && initialValue != $(this).val()) {
+      if (initialValue !== undefined && !_.isEqual(initialValue, $(this).val())) {
         isDirty = true;
       }
     });
     return isDirty;
-  }
+  };
 
   /**
    * Wrapper for select2 initialization function; supplies defaults
@@ -452,13 +452,6 @@ CRM.validate = CRM.validate || {
   // Initialize widgets
   $(document)
     .on('crmLoad', function(e) {
-      $('table.form-layout-compressed')
-        .on('change', 'input.select-rows', function () {
-          if ($(this).prop('checked')) {
-            $('input#toggleSelect:checked').prop('checked', false);
-            $('input.select-row:checked').prop('checked', false);
-          }
-         })
       $('table.row-highlight', e.target)
         .off('.rowHighlight')
         .on('change.rowHighlight', 'input.select-row, input.select-rows', function (e, data) {
@@ -472,9 +465,6 @@ CRM.validate = CRM.validate || {
             if (data !== 'master-selected') {
               $('input.select-rows', $table).prop('checked', $(".select-row:not(':checked')", $table).length < 1);
             }
-           if ($(this).prop('checked')) {
-             $('input[value=ts_sel]:radio').prop('checked', true);
-           }
           }
         })
         .find('input.select-row:checked').parents('tr').addClass('crm-row-selected');
@@ -515,21 +505,22 @@ CRM.validate = CRM.validate || {
     })
     .on('dialogclose', function(e) {
       // Restore scrollbars when closing modal
-      if ($('.ui-dialog .modal-dialog').not(e.target).length < 1) {
+      if ($('.ui-dialog .modal-dialog:visible').not(e.target).length < 1) {
         $('body').css({overflow: ''});
       }
     })
     .on('submit', function(e) {
-      // CRM-14353 - disable changes warn when submitting the form
-      $('[data-warn-changes]').removeAttr('data-warn-changes');
+      // CRM-14353 - disable changes warn when submitting a form
+      $('[data-warn-changes]').attr('data-warn-changes', 'false');
     })
-    ;
-    
-    window.onbeforeunload = function() {
-      if (CRM.utils.initialValueChanged($('form[data-warn-changes=true]'))) {
-        return ts('You have unsaved changes.');
-       }
-    };
+   ;
+
+  // CRM-14353 - Warn of unsaved changes for forms which have opted in
+  window.onbeforeunload = function() {
+    if (CRM.utils.initialValueChanged($('form[data-warn-changes=true]:visible'))) {
+      return ts('You have unsaved changes.');
+     }
+  };
 
   /**
    * Function to make multiselect boxes behave as fields in small screens