CRM-13863 - Improve buffering of crmPopup events
authorColeman Watts <coleman@civicrm.org>
Thu, 3 Apr 2014 19:11:52 +0000 (15:11 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 3 Apr 2014 19:11:52 +0000 (15:11 -0400)
js/crm.ajax.js
js/crm.optionEdit.js
templates/CRM/Form/attachmentjs.tpl

index 597e77bfc048c04637fa6b4d126336a04efd5561..e198881ba33784b96dbd71d9150368074bdc38cb 100644 (file)
     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) {
index 7a343e2154ba6a3c91a4a9291210e1ea74b07ddd..82fa4793a8d5b0c72f0063e61925b7d71554f9ae 100644 (file)
@@ -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);
+          });
       }
-    })
+    });
 });
index f626b779cecdd97cd385c178b49ec328b5482095..098a15b270a03cc8e7c037ad864fbefecf1bb4e1 100644 (file)
@@ -1,7 +1,7 @@
 <script type="text/javascript">
 {literal}
   CRM.$(function($) {
-    $('a.delete-attachment').click(function() {
+    $('a.delete-attachment').click(function(e) {
       var $el = $(this),
         $row = $el.closest('.crm-attachment-wrapper'),
         msg = '{/literal}{ts escape="js" 1="%1"}This will immediately delete the file %1. This action cannot be undone.{/ts}{literal}';
         var request = $.post(postUrl, $el.data('args'));
         CRM.status({success: '{/literal}{ts escape="js"}Removed{/ts}{literal}'}, request);
         request.done(function() {
+          $el.trigger('crmPopupFormSuccess');
           $row.remove();
         });
       });
-      return false;
+      e.preventDefault();
     });
   });
 {/literal}