CRM-13863 - Fix for save & new - buffer the crmPopupFormSuccess event
authorColeman Watts <coleman@civicrm.org>
Wed, 2 Apr 2014 15:41:13 +0000 (11:41 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 2 Apr 2014 15:41:13 +0000 (11:41 -0400)
js/crm.ajax.js

index 63c18b5503b0a62af4a07865df5eac491f6999d8..bd5834930974be795aeb1b53de9bc4fe0462f31a 100644 (file)
       url = $el.attr('href'),
       popup = $el.data('popup-type') === 'page' ? CRM.loadPage : CRM.loadForm,
       settings = $el.data('popup-settings') || {},
-      triggers = {dialogclose: 'crmPopupClose', crmLoad: 'crmPopupLoad', crmFormSuccess: 'crmPopupFormSuccess'};
+      formSuccess = false;
     settings.dialog = settings.dialog || {};
     if (e.isDefaultPrevented() || !CRM.config.ajaxPopupsEnabled || !url || $el.is(exclude)) {
       return;
     var dialog = popup(url, settings);
     // Trigger events from the dialog on the original link element
     $el.trigger('crmPopupOpen', [dialog]);
-    $.each(triggers, function(event, target) {
-      dialog.on(event, function(e, data) {
-        $el.trigger(target, [dialog, data]);
-      });
+    // Buffer this event so it only fires once
+    dialog.on('crmFormSuccess.crmPopup', function(e, data) {
+      formSuccess = true;
+    });
+    dialog.on('dialogclose.crmPopup', function(e, data) {
+      if (formSuccess) {
+        $el.trigger('crmPopupFormSuccess', [dialog, data]);
+      }
+      $el.trigger('crmPopupClose', [dialog, data]);
     });
     e.preventDefault();
   };