From 7fe745d1a0d626996d8cc7dd72b6f9f976954e03 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 2 Apr 2014 11:41:13 -0400 Subject: [PATCH] CRM-13863 - Fix for save & new - buffer the crmPopupFormSuccess event --- js/crm.ajax.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 63c18b5503..bd58349309 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -413,7 +413,7 @@ 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; @@ -432,10 +432,15 @@ 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(); }; -- 2.25.1