Commit | Line | Data |
---|---|---|
12798ddc CW |
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($) { | |
d4838efc | 30 | var $row, $table, info, enabled, fieldLabel; |
12798ddc | 31 | |
e11b84ce CW |
32 | function successMsg() { |
33 | {/literal} {* client-side variable substitutions in smarty are AWKWARD! *} | |
34 | var msg = enabled ? '{ts escape="js" 1="<em>%1</em>"}%1 Disabled{/ts}' : '{ts escape="js" 1="<em>%1</em>"}%1 Enabled{/ts}'{literal}; | |
35 | return ts(msg, {1: fieldLabel}); | |
36 | } | |
37 | ||
12798ddc | 38 | function refresh() { |
7d644ac8 CW |
39 | // Call native refresh method on ajax datatables |
40 | if ($.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) { | |
3e150793 | 41 | $.each($.fn.dataTable.fnTables(), function() { |
42 | $(this).dataTable().fnSettings().sAjaxSource && $(this).unblock().dataTable().fnDraw(); | |
0cb182f6 | 43 | }); |
7d644ac8 CW |
44 | } |
45 | // Otherwise refresh the content area using crmSnippet | |
46 | else { | |
1fe97a01 CW |
47 | $row.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh'); |
48 | } | |
12798ddc CW |
49 | } |
50 | ||
51 | function save() { | |
1fe97a01 CW |
52 | $table = $row.closest('table'); |
53 | $table.block(); | |
e11b84ce | 54 | CRM.api3(info.entity, 'setvalue', {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh); |
4d17a233 CW |
55 | if (enabled) { |
56 | $(this).dialog('close'); | |
57 | } | |
12798ddc CW |
58 | } |
59 | ||
60 | function confirmation() { | |
4d17a233 | 61 | var conf = $(this); |
d4838efc | 62 | $.getJSON(CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}), function(response) { |
4d17a233 CW |
63 | conf.html(response.content); |
64 | if (!response.illegal) { | |
65 | conf.dialog('option', 'buttons', [ | |
66 | {text: {/literal}'{ts escape="js"}Disable{/ts}'{literal}, click: save}, | |
67 | {text: {/literal}'{ts escape="js"}Cancel{/ts}'{literal}, click: function() {$(this).dialog('close');}} | |
68 | ]); | |
69 | } | |
12798ddc CW |
70 | }); |
71 | } | |
72 | ||
73 | function enableDisable() { | |
d4838efc CW |
74 | $row = $(this).closest('.crm-entity'); |
75 | info = $(this).crmEditableEntity(); | |
76 | fieldLabel = info.label || info.title || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal}; | |
12798ddc CW |
77 | enabled = !$row.hasClass('disabled'); |
78 | if (enabled) { | |
4d17a233 | 79 | CRM.confirm({}, {{/literal} |
12798ddc | 80 | message: '<div class="crm-loading-element">{ts escape="js"}Loading{/ts}...</div>', |
d4838efc CW |
81 | {* client-side variable substitutions in smarty are AWKWARD! *} |
82 | title: ts('{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}), | |
12798ddc CW |
83 | width: 300, |
84 | open: confirmation | |
d4838efc | 85 | }); |
12798ddc CW |
86 | } else { |
87 | save(); | |
88 | } | |
89 | return false; | |
90 | } | |
91 | ||
92 | // Because this is an inline script it may get added to the document more than once, so remove handler before adding | |
93 | $('body') | |
fdf3f783 CW |
94 | .off('.crmEnableDisable') |
95 | .on('click.crmEnableDisable', '.action-item.crm-enable-disable', enableDisable); | |
12798ddc CW |
96 | }); |
97 | </script> | |
98 | {/literal} |