From 4b472ff2bb8003f18b17e306a7511b999a2fa630 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 3 Apr 2014 15:11:52 -0400 Subject: [PATCH] CRM-13863 - Improve buffering of crmPopup events --- js/crm.ajax.js | 4 ++-- js/crm.optionEdit.js | 24 +++++++++--------------- templates/CRM/Form/attachmentjs.tpl | 5 +++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 597e77bfc0..e198881ba3 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -434,8 +434,8 @@ var dialog = popup(url, settings); // Trigger events from the dialog on the original link element $el.trigger('crmPopupOpen', [dialog]); - // Buffer this event so it only fires once - dialog.on('crmFormSuccess.crmPopup', function(e, data) { + // Listen for success events and buffer them so we only trigger once + dialog.on('crmFormSuccess.crmPopup crmPopupFormSuccess.crmPopup', function() { formSuccess = true; }); dialog.on('dialogclose.crmPopup', function(e, data) { diff --git a/js/crm.optionEdit.js b/js/crm.optionEdit.js index 7a343e2154..82fa4793a8 100644 --- a/js/crm.optionEdit.js +++ b/js/crm.optionEdit.js @@ -1,23 +1,17 @@ // https://civicrm.org/licensing // Enable administrators to edit option lists in a dialog jQuery(function($) { - var optionsChanged; $('body') // Edit option lists .on('click', 'a.crm-option-edit-link', CRM.popup) - .on('crmPopupOpen crmPopupFormSuccess', 'a.crm-option-edit-link', function(e) { - optionsChanged = e.type === 'crmPopupFormSuccess'; - }) - .on('crmPopupClose', 'a.crm-option-edit-link', function() { - if (optionsChanged) { - $(this).trigger('crmOptionsEdited'); - var $elects = $('select[data-option-edit-path="' + $(this).data('option-edit-path') + '"]'); - if ($elects.data('api-entity') && $elects.data('api-field')) { - CRM.api3($elects.data('api-entity'), 'getoptions', {sequential: 1, field: $elects.data('api-field')}) - .done(function (data) { - CRM.utils.setOptions($elects, data.values); - }); - } + .on('crmPopupFormSuccess', 'a.crm-option-edit-link', function() { + $(this).trigger('crmOptionsEdited'); + var $elects = $('select[data-option-edit-path="' + $(this).data('option-edit-path') + '"]'); + if ($elects.data('api-entity') && $elects.data('api-field')) { + CRM.api3($elects.data('api-entity'), 'getoptions', {sequential: 1, field: $elects.data('api-field')}) + .done(function (data) { + CRM.utils.setOptions($elects, data.values); + }); } - }) + }); }); diff --git a/templates/CRM/Form/attachmentjs.tpl b/templates/CRM/Form/attachmentjs.tpl index f626b779ce..098a15b270 100644 --- a/templates/CRM/Form/attachmentjs.tpl +++ b/templates/CRM/Form/attachmentjs.tpl @@ -1,7 +1,7 @@