Merge pull request #3601 from atif-shaikh/CRM-14942
[civicrm-core.git] / templates / CRM / common / enableDisableApi.tpl
index d1b3cb1cb9d8f080101c7369175f67ae4728ad46..83a9964c39e27e9e75e596aba4c42a2f66d361ed 100644 (file)
@@ -1,8 +1,8 @@
 {*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 {* handle common enable/disable actions *}
 {literal}
 <script type="text/javascript">
-  cj(function($) {
-    var $row, $table, info, enabled, fieldLabel;
+  CRM.$(function($) {
+    var $row, info, enabled, fieldLabel;
 
-    function refresh() {
-      // Call native refresh method on ajax datatables
-      if ($.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) {
-        $.each($.fn.dataTable.fnTables(), function() {
-          $(this).dataTable().fnSettings().sAjaxSource && $(this).unblock().dataTable().fnDraw();
-        });
-      }
-      // Otherwise refresh the content area using crmSnippet
-      else {
-        $row.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh');
-      }
+    function successMsg() {
       {/literal} {* client-side variable substitutions in smarty are AWKWARD! *}
       var msg = enabled ? '{ts escape="js" 1="<em>%1</em>"}%1 Disabled{/ts}' : '{ts escape="js" 1="<em>%1</em>"}%1 Enabled{/ts}'{literal};
-      CRM.alert('', ts(msg, {1: fieldLabel}), 'success');
+      return ts(msg, {1: fieldLabel});
+    }
+
+    function refresh() {
+      CRM.refreshParent($row);
     }
 
     function save() {
-      $table = $row.closest('table');
-      $table.block();
-      CRM.api(info.entity, 'setvalue', {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: refresh});
+      $row.closest('table').block();
+      CRM.api3(info.entity, 'setvalue', {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh);
       if (enabled) {
         $(this).dialog('close');
       }
       fieldLabel = info.label || info.title || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal};
       enabled = !$row.hasClass('disabled');
       if (enabled) {
-        CRM.confirm({}, {{/literal}
+        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
         });
       } else {
@@ -88,8 +82,8 @@
 
     // Because this is an inline script it may get added to the document more than once, so remove handler before adding
     $('body')
-      .off('click', '.action-item.crm-enable-disable')
-      .on('click', '.action-item.crm-enable-disable', enableDisable);
+      .off('.crmEnableDisable')
+      .on('click.crmEnableDisable', '.action-item.crm-enable-disable', enableDisable);
   });
 </script>
 {/literal}