Commit | Line | Data |
---|---|---|
12798ddc CW |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
12798ddc | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
12798ddc CW |
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"> | |
3cc60a06 | 29 | CRM.$(function($) { |
554b1768 | 30 | var $row, 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() { |
554b1768 | 39 | CRM.refreshParent($row); |
12798ddc CW |
40 | } |
41 | ||
42 | function save() { | |
554b1768 | 43 | $row.closest('table').block(); |
4f1c81da | 44 | CRM.api3(info.entity, info.action, {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh); |
4d17a233 CW |
45 | if (enabled) { |
46 | $(this).dialog('close'); | |
47 | } | |
12798ddc CW |
48 | } |
49 | ||
50 | function confirmation() { | |
4d17a233 | 51 | var conf = $(this); |
d4838efc | 52 | $.getJSON(CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}), function(response) { |
4d17a233 CW |
53 | conf.html(response.content); |
54 | if (!response.illegal) { | |
55 | conf.dialog('option', 'buttons', [ | |
cd4cc953 CW |
56 | {text: {/literal}'{ts escape="js"}Yes{/ts}'{literal}, click: save}, |
57 | {text: {/literal}'{ts escape="js"}No{/ts}'{literal}, click: function() {$(this).dialog('close');}} | |
4d17a233 CW |
58 | ]); |
59 | } | |
12798ddc CW |
60 | }); |
61 | } | |
62 | ||
63 | function enableDisable() { | |
d4838efc CW |
64 | $row = $(this).closest('.crm-entity'); |
65 | info = $(this).crmEditableEntity(); | |
e2046b33 | 66 | fieldLabel = info.label || info.title || info.display_name || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal}; |
12798ddc CW |
67 | enabled = !$row.hasClass('disabled'); |
68 | if (enabled) { | |
5fb83680 | 69 | CRM.confirm({{/literal} |
12798ddc | 70 | message: '<div class="crm-loading-element">{ts escape="js"}Loading{/ts}...</div>', |
d4838efc CW |
71 | {* client-side variable substitutions in smarty are AWKWARD! *} |
72 | title: ts('{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}), | |
12798ddc | 73 | width: 300, |
5fb83680 | 74 | options: null, |
12798ddc | 75 | open: confirmation |
d4838efc | 76 | }); |
12798ddc CW |
77 | } else { |
78 | save(); | |
79 | } | |
80 | return false; | |
81 | } | |
82 | ||
83 | // Because this is an inline script it may get added to the document more than once, so remove handler before adding | |
84 | $('body') | |
fdf3f783 CW |
85 | .off('.crmEnableDisable') |
86 | .on('click.crmEnableDisable', '.action-item.crm-enable-disable', enableDisable); | |
12798ddc CW |
87 | }); |
88 | </script> | |
89 | {/literal} |