CRM-16725 - Remove global download behavior from popups
authorColeman Watts <coleman@civicrm.org>
Thu, 8 Oct 2015 01:38:41 +0000 (21:38 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 8 Oct 2015 01:55:53 +0000 (21:55 -0400)
It was problematic to have the button change run globally.
Now it's just in the spot that needs it.
If other spots need something similar it would be good to find a way to reuse the code.

js/crm.ajax.js
templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl

index 3ea776c4f834190e1cd261bae28f1c509a8a3f9b..6f0f244553fb3eea19344822cd5fe57f186d73a7 100644 (file)
           $el.parents(buttonContainers).css({height: 0, padding: 0, margin: 0, overflow: 'hidden'}).find('.crm-button-icon').hide();
         });
         $el.dialog('option', 'buttons', buttons);
-
-        // Show done button for non-ajax dialogs (e.g. file downloads)
-        $(this).on('submit', "form[data-no-ajax-submit=true]", function() {
-          $el.dialog('option', 'buttons', [{
-            text: ts('Done'),
-            icons: {primary: 'ui-icon-close'},
-            click: function() {$(this).dialog('close');}
-          }]);
-        });
       }
       // Allow a button to prevent ajax submit
       $('input[data-no-ajax-submit=true]').click(function() {
index 5439af0fba57d1a9f6bce980a603dac7c193e140..65a473d0d928b7bc5b1fd54fb85ff12b954d5889 100644 (file)
@@ -127,8 +127,18 @@ CRM.$(function($) {
   });
   // After the pdf downloads, the user has to manually close the dialog (which would be nice to fix)
   // But at least we can trigger the underlying list of activities to refresh
-  $form.closest('.ui-dialog-content.crm-ajax-container').on('dialogbeforeclose', function() {
-    $(this).trigger('crmFormSuccess');
+  $('[name=_qf_PDF_submit]', $form).click(function() {
+    var $dialog = $(this).closest('.ui-dialog-content.crm-ajax-container');
+    if ($dialog.length) {
+      $dialog.on('dialogbeforeclose', function () {
+        $(this).trigger('crmFormSuccess');
+      });
+      $dialog.dialog('option', 'buttons', [{
+        text: {/literal}"{ts escape='js'}Done{/ts}"{literal},
+        icons: {primary: 'ui-icon-close'},
+        click: function() {$(this).dialog('close');}
+      }]);
+    }
   });
   showSaveDetails($('input[name=saveTemplate]', $form)[0]);