| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.4 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | This file is a part of CiviCRM. | |
| 8 | | | |
| 9 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 10 | | under the terms of the GNU Affero General Public License | |
| 11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 12 | | | |
| 13 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 16 | | See the GNU Affero General Public License for more details. | |
| 17 | | | |
| 18 | | You should have received a copy of the GNU Affero General Public | |
| 19 | | License and the CiviCRM Licensing Exception along | |
| 20 | | with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | *} |
| 26 | {* handle common enable/disable actions *} |
| 27 | {literal} |
| 28 | <script type="text/javascript"> |
| 29 | cj(function($) { |
| 30 | var $row, $table, info, enabled, fieldLabel; |
| 31 | |
| 32 | function refresh() { |
| 33 | // Call native refresh method on ajax datatables |
| 34 | if ($.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) { |
| 35 | $table.unblock().dataTable().fnDraw(); |
| 36 | } |
| 37 | // Otherwise refresh the content area using crmSnippet |
| 38 | else { |
| 39 | $row.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh'); |
| 40 | } |
| 41 | {/literal} {* client-side variable substitutions in smarty are AWKWARD! *} |
| 42 | var msg = enabled ? '{ts escape="js" 1="<em>%1</em>"}%1 Disabled{/ts}' : '{ts escape="js" 1="<em>%1</em>"}%1 Enabled{/ts}'{literal}; |
| 43 | CRM.alert('', ts(msg, {1: fieldLabel}), 'success'); |
| 44 | } |
| 45 | |
| 46 | function save() { |
| 47 | $table = $row.closest('table'); |
| 48 | $table.block(); |
| 49 | CRM.api(info.entity, 'setvalue', {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: refresh}); |
| 50 | if (enabled) { |
| 51 | $(this).dialog('close'); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | function confirmation() { |
| 56 | var conf = $(this); |
| 57 | $.getJSON(CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}), function(response) { |
| 58 | conf.html(response.content); |
| 59 | if (!response.illegal) { |
| 60 | conf.dialog('option', 'buttons', [ |
| 61 | {text: {/literal}'{ts escape="js"}Disable{/ts}'{literal}, click: save}, |
| 62 | {text: {/literal}'{ts escape="js"}Cancel{/ts}'{literal}, click: function() {$(this).dialog('close');}} |
| 63 | ]); |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | function enableDisable() { |
| 69 | $row = $(this).closest('.crm-entity'); |
| 70 | info = $(this).crmEditableEntity(); |
| 71 | fieldLabel = info.label || info.title || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal}; |
| 72 | enabled = !$row.hasClass('disabled'); |
| 73 | if (enabled) { |
| 74 | CRM.confirm({}, {{/literal} |
| 75 | message: '<div class="crm-loading-element">{ts escape="js"}Loading{/ts}...</div>', |
| 76 | {* client-side variable substitutions in smarty are AWKWARD! *} |
| 77 | title: ts('{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}), |
| 78 | width: 300, |
| 79 | open: confirmation |
| 80 | }); |
| 81 | } else { |
| 82 | save(); |
| 83 | } |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | // Because this is an inline script it may get added to the document more than once, so remove handler before adding |
| 88 | $('body') |
| 89 | .off('click', '.action-item.crm-enable-disable') |
| 90 | .on('click', '.action-item.crm-enable-disable', enableDisable); |
| 91 | }); |
| 92 | </script> |
| 93 | {/literal} |