CRM-16996 fix regression on form rule
[civicrm-core.git] / js / crm.ajax.js
index 8d266e38bd41186d4539f0b1288d15fcd4347fe0..3ea776c4f834190e1cd261bae28f1c509a8a3f9b 100644 (file)
         that._handleOrderLinks();
         that.element.trigger('crmLoad', data);
         if (that.options.crmForm) that.element.trigger('crmFormLoad', data);
+        // This is only needed by forms that load via ajax but submit without ajax, e.g. configure contribution page tabs
+        // TODO: remove this when those forms have been converted to use ajax submit
+        if (data.status === 'form_error' && $.isPlainObject(data.errors)) {
+          that.element.trigger('crmFormError', data);
+          $.each(data.errors, function(formElement, msg) {
+            $('[name="'+formElement+'"]', that.element).crmError(msg);
+          });
+        }
       }).fail(function(data, msg, status) {
         that._onFailure(data, status);
       });
             }
           }
         },
-        beforeSerialize: function(form, options) {
-          if (window.CKEDITOR && window.CKEDITOR.instances) {
-            $.each(CKEDITOR.instances, function() {
-              if (this.updateElement) this.updateElement();
-            });
-          }
-          if (window.tinyMCE && tinyMCE.editors) {
-            $.each(tinyMCE.editors, function() {
-              this.save();
-            });
-          }
-        },
         beforeSubmit: function(submission) {
           $.each(formErrors, function() {
             if (this && this.close) this.close();
       }, settings.ajaxForm));
       if (settings.openInline) {
         settings.autoClose = $el.crmSnippet('isOriginalUrl');
-        $(settings.openInline, this).not(exclude + ', .crm-popup').click(function(event) {
+        $(this).on('click', settings.openInline, function(e) {
+          if ($(this).is(exclude + ', .crm-popup')) {
+            return;
+          }
           if ($(this).hasClass('open-inline-noreturn')) {
             // Force reset of original url
             $el.data('civiCrmSnippet')._originalUrl = $(this).attr('href');
           }
           $el.crmSnippet('option', 'url', $(this).attr('href')).crmSnippet('refresh');
-          return false;
+          e.preventDefault();
         });
       }
-      // Show form buttons as part of the dialog
       if ($el.data('uiDialog')) {
+        // Show form buttons as part of the dialog
         var buttonContainers = '.crm-submit-buttons, .action-link',
           buttons = [],
           added = [];
           $el.parents(buttonContainers).css({height: 0, padding: 0, margin: 0, overflow: 'hidden'}).find('.crm-button-icon').hide();
         });
         $el.dialog('option', 'buttons', buttons);
+
+        // Show done button for non-ajax dialogs (e.g. file downloads)
+        $(this).on('submit', "form[data-no-ajax-submit=true]", function() {
+          $el.dialog('option', 'buttons', [{
+            text: ts('Done'),
+            icons: {primary: 'ui-icon-close'},
+            click: function() {$(this).dialog('close');}
+          }]);
+        });
       }
       // Allow a button to prevent ajax submit
       $('input[data-no-ajax-submit=true]').click(function() {
       .on('dialogcreate', function(e) {
         $('.ui-dialog-content.crm-ajax-container:hidden[data-unsaved-changes=true]').crmSnippet('destroy').dialog('destroy').remove();
       })
+      // Ensure wysiwyg content is updated prior to ajax submit
+      .on('form-pre-serialize', function(e) {
+        $('.crm-wysiwyg-enabled', e.target).each(function() {
+          CRM.wysiwyg.updateElement(this);
+        });
+      })
       // Auto-resize dialogs when loading content
       .on('crmLoad dialogopen', 'div.ui-dialog.ui-resizable.crm-container', function(e) {
         var