Merge pull request #11264 from seanmadsen/CRM-21419-activity-separation
[civicrm-core.git] / js / crm.ajax.js
index 91565ef6030ff35b0dbb79c59ad9cfd51964f473..9cb5eb601e0985c32784f8fa7724f2657be552b4 100644 (file)
       if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
       if (this.options.block) this.element.block();
       $.getJSON(url, function(data) {
+        if (data.status === 'redirect') {
+          that.options.url = data.userContext;
+          return that.refresh();
+        }
         if (that.options.block) that.element.unblock();
         if (!$.isPlainObject(data)) {
           that._onFailure(data);
         $('.blockUI', this.element).remove();
         this._originalContent = this.element.contents().detach();
       }
-      if (window.tinyMCE && tinyMCE.editors) {
-        $.each(tinyMCE.editors, function(k) {
-          if ($.contains(that.element[0], this.getElement())) {
-            this.remove();
-          }
-        });
-      }
       if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
     },
     _destroy: function() {
       }, settings.ajaxForm));
       if (settings.openInline) {
         settings.autoClose = $el.crmSnippet('isOriginalUrl');
-        $(this).on('click', settings.openInline, function(e) {
+        $(this).off('.openInline').on('click.openInline', settings.openInline, function(e) {
           if ($(this).is(exclude + ', .crm-popup')) {
             return;
           }
       url = $el.attr('href'),
       popup = $el.data('popup-type') === 'page' ? CRM.loadPage : CRM.loadForm,
       settings = $el.data('popup-settings') || {},
-      formSuccess = false;
+      formData = false;
     settings.dialog = settings.dialog || {};
-    if (e.isDefaultPrevented() || !CRM.config.ajaxPopupsEnabled || !url || $el.is(exclude)) {
+    if (e.isDefaultPrevented() || !CRM.config.ajaxPopupsEnabled || !url || $el.is(exclude + ', .open-inline, .open-inline-noreturn')) {
       return;
     }
     // Sized based on css class
     // Trigger events from the dialog on the original link element
     $el.trigger('crmPopupOpen', [dialog]);
     // Listen for success events and buffer them so we only trigger once
-    dialog.on('crmFormSuccess.crmPopup crmPopupFormSuccess.crmPopup', function() {
-      formSuccess = true;
+    dialog.on('crmFormSuccess.crmPopup crmPopupFormSuccess.crmPopup', function(e, data) {
+      formData = data;
     });
     dialog.on('dialogclose.crmPopup', function(e, data) {
-      if (formSuccess) {
-        $el.trigger('crmPopupFormSuccess', [dialog, data]);
+      if (formData) {
+        $el.trigger('crmPopupFormSuccess', [dialog, formData]);
       }
       $el.trigger('crmPopupClose', [dialog, data]);
     });