Commit | Line | Data |
---|---|---|
12798ddc CW |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
39de6fd5 | 3 | | CiviCRM version 4.6 | |
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($) { |
369f685e | 30 | var $a, $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() { |
369f685e | 39 | $a.trigger('crmPopupFormSuccess'); |
554b1768 | 40 | CRM.refreshParent($row); |
12798ddc CW |
41 | } |
42 | ||
43 | function save() { | |
554b1768 | 44 | $row.closest('table').block(); |
4f1c81da | 45 | CRM.api3(info.entity, info.action, {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh); |
12798ddc CW |
46 | } |
47 | ||
369f685e CW |
48 | function checkResponse(e, response) { |
49 | if (response.illegal) { | |
50 | $(this).dialog('option', 'buttons', [ | |
51 | {text: {/literal}'{ts escape="js"}Close{/ts}'{literal}, click: function() {$(this).dialog('close');}, icons: {primary: 'ui-icon-close'}} | |
52 | ]); | |
53 | } | |
12798ddc CW |
54 | } |
55 | ||
56 | function enableDisable() { | |
369f685e CW |
57 | $a = $(this); |
58 | $row = $a.closest('.crm-entity'); | |
59 | info = $a.crmEditableEntity(); | |
e2046b33 | 60 | fieldLabel = info.label || info.title || info.display_name || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal}; |
12798ddc CW |
61 | enabled = !$row.hasClass('disabled'); |
62 | if (enabled) { | |
369f685e CW |
63 | CRM.confirm({ |
64 | url: CRM.url('civicrm/ajax/statusmsg', {entity: info.entity, id: info.id}), | |
65 | title: ts('{/literal}{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}), | |
66 | options: {{/literal}yes: '{ts escape="js"}Yes{/ts}', no: '{ts escape="js"}No{/ts}'{literal}}, | |
67 | width: 300 | |
68 | }) | |
69 | .on('crmLoad', checkResponse) | |
70 | .on('crmConfirm:yes', save); | |
12798ddc CW |
71 | } else { |
72 | save(); | |
73 | } | |
74 | return false; | |
75 | } | |
76 | ||
77 | // Because this is an inline script it may get added to the document more than once, so remove handler before adding | |
78 | $('body') | |
fdf3f783 CW |
79 | .off('.crmEnableDisable') |
80 | .on('click.crmEnableDisable', '.action-item.crm-enable-disable', enableDisable); | |
12798ddc CW |
81 | }); |
82 | </script> | |
83 | {/literal} |