Fix enableDisableApi to fire crmPopupFormSuccess event
authorColeman Watts <coleman@civicrm.org>
Fri, 26 Sep 2014 13:07:19 +0000 (09:07 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 26 Sep 2014 13:07:19 +0000 (09:07 -0400)
js/crm.livePage.js
js/crm.searchForm.js
templates/CRM/common/TabHeader.js
templates/CRM/common/enableDisableApi.tpl

index 5133f5d37113e9ceda5e863f35304059ed47402a..35c8b39312dd7cc3a333c4d5dc255b364798e929 100644 (file)
@@ -1,7 +1,7 @@
 // http://civicrm.org/licensing
 // Adds ajaxy behavior to a simple CiviCRM page
 CRM.$(function($) {
-  var active = 'a.button, a.action-item, a.crm-popup';
+  var active = 'a.button, a.action-item:not(.crm-enable-disable), a.crm-popup';
   $('#crm-main-content-wrapper')
     // Widgetize the content area
     .crmSnippet()
index 4b4ad2e7fea220082b7d37a8289d195f83b7df4b..dc3a9cb637299b9e441aa37716a6797a950a4a53 100644 (file)
@@ -3,7 +3,7 @@
   "use strict";
   var selected = 0,
     form = 'form.crm-search-form',
-    active = 'a.button, a.action-item, a.crm-popup';
+    active = 'a.button, a.action-item:not(.crm-enable-disable), a.crm-popup';
 
   function clearTaskMenu() {
     $('select#task', form).val('').select2('val', '').prop('disabled', true).select2('disable');
index f6aa5f398a15fca944cdca224d5c346903ad7519..f45929ff931f149d25abe14fa9657af050c07903 100644 (file)
@@ -32,7 +32,7 @@ CRM.$(function($) {
           ui.panel
             .off('click.crmLivePage')
             .on('click.crmLivePage', 'a.button, a.action-item', CRM.popup)
-            .on('crmPopupFormSuccess.crmLivePage', 'a.button, a.action-item', CRM.refreshParent);
+            .on('crmPopupFormSuccess.crmLivePage', 'a.button, a.action-item:not(.crm-enable-disable)', CRM.refreshParent);
         }
         ui.panel
           .off('.tabInfo')
index 2396685fee02f7e1532a0ae24ef045819380a17b..5db3c7418658771c4844addd2b7473702765c44c 100644 (file)
@@ -27,7 +27,7 @@
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {
-    var $row, info, enabled, fieldLabel;
+    var $a, $row, info, enabled, fieldLabel;
 
     function successMsg() {
       {/literal} {* client-side variable substitutions in smarty are AWKWARD! *}
     }
 
     function refresh() {
+      $a.trigger('crmPopupFormSuccess');
       CRM.refreshParent($row);
     }
 
     function save() {
       $row.closest('table').block();
       CRM.api3(info.entity, info.action, {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh);
-      if (enabled) {
-        $(this).dialog('close');
-      }
     }
 
-    function confirmation() {
-      var conf = $(this);
-      $.getJSON(CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}), function(response) {
-        conf.html(response.content);
-        if (!response.illegal) {
-          conf.dialog('option', 'buttons', [
-            {text: {/literal}'{ts escape="js"}Yes{/ts}'{literal}, click: save, icons: {primary: 'ui-icon-check'}},
-            {text: {/literal}'{ts escape="js"}No{/ts}'{literal}, click: function() {$(this).dialog('close');}, icons: {primary: 'ui-icon-close'}}
-          ]);
-        }
-      });
+    function checkResponse(e, response) {
+      if (response.illegal) {
+        $(this).dialog('option', 'buttons', [
+          {text: {/literal}'{ts escape="js"}Close{/ts}'{literal}, click: function() {$(this).dialog('close');}, icons: {primary: 'ui-icon-close'}}
+        ]);
+      }
     }
 
     function enableDisable() {
-      $row = $(this).closest('.crm-entity');
-      info = $(this).crmEditableEntity();
+      $a = $(this);
+      $row = $a.closest('.crm-entity');
+      info = $a.crmEditableEntity();
       fieldLabel = info.label || info.title || info.display_name || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal};
       enabled = !$row.hasClass('disabled');
       if (enabled) {
-        CRM.confirm({{/literal}
-          message: '<div class="crm-loading-element">{ts escape="js"}Loading{/ts}...</div>',
-          {* client-side variable substitutions in smarty are AWKWARD! *}
-          title: ts('{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}),
-          width: 300,
-          options: null,
-          open: confirmation
-        });
+        CRM.confirm({
+          url: CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}),
+          title: ts('{/literal}{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}),
+          options: {{/literal}yes: '{ts escape="js"}Yes{/ts}', no: '{ts escape="js"}No{/ts}'{literal}},
+          width: 300
+        })
+          .on('crmLoad', checkResponse)
+          .on('crmConfirm:yes', save);
       } else {
         save();
       }