Merge pull request #12949 from eileenmcnaughton/activity_extract
[civicrm-core.git] / templates / CRM / Event / Form / ManageEvent / ConfirmRepeatMode.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 {if $hasParent || $isRepeatingEntity || $scheduleReminderId}
27 {capture assign='entity_type'}{$recurringEntityType|lower}{/capture}
28 <script type="text/template" id="recurring-dialog-tpl">
29 <div class="recurring-dialog">
30 <h4>{ts}How should this change affect others in the series?{/ts}</h4>
31 <div>
32 <input type="radio" id="recur-only-this-entity" name="recur_mode" value="1">
33 <label for="recur-only-this-entity">{ts 1=$entity_type}Only this %1{/ts}</label>
34 <div class="description">{ts}All others in the series will remain unchanged.{/ts}</div>
35
36 <input type="radio" id="recur-this-and-all-following-entity" name="recur_mode" value="2">
37 <label for="recur-this-and-all-following-entity">{ts 1=$entity_type}This %1 onwards{/ts}</label>
38 <div class="description">{ts 1=$entity_type}Change applies to this %1 and all that come after it.{/ts}</div>
39
40 <input type="radio" id="recur-all-entity" name="recur_mode" value="3">
41 <label for="recur-all-entity">{ts 1=$entity_type}Every %1{/ts}</label>
42 <div class="description">{ts 1=$entity_type}Change applies to every %1 in the series.{/ts}</div>
43 </div>
44 <div class="status help"><i class="crm-i fa-info-circle"></i> {ts}Changes to date or time will <em>not</em> be applied to others in the series.{/ts}</div>
45 </div>
46 </script>
47 {literal}
48 <script type="text/javascript">
49 CRM.$(function($) {
50 var $form, formClass,
51 /** Add your linked entity mapper here **/
52 mapper = {
53 'CRM_Event_Form_ManageEvent_EventInfo': '',
54 'CRM_Event_Form_ManageEvent_Location': '',
55 'CRM_Event_Form_ManageEvent_Fee': '',
56 'CRM_Event_Form_ManageEvent_Registration': '',
57 'CRM_Friend_Form_Event': 'civicrm_tell_friend',
58 'CRM_PCP_Form_Event': 'civicrm_pcp_block',
59 'CRM_Activity_Form_Activity': ''
60 };
61
62 function cascadeChangesDialog() {
63 CRM.confirm({
64 title: "{/literal}{ts escape='js' 1=$entity_type}Update repeating %1{/ts}{literal}",
65 message: $('#recurring-dialog-tpl').html()
66 })
67 .on('crmConfirm:yes', updateMode)
68 .on('click change', 'input[name=recur_mode]', function() {
69 $('button[data-op=yes]').prop('disabled', false);
70 })
71 .parent().find('button[data-op=yes]').prop('disabled', true)
72 }
73
74 // Intercept form submissions and check if they will impact the recurring entity
75 // This ought to attach the handler to the the dialog if we're in a popup, or the page wrapper if we're not
76 $('#recurring-dialog-tpl').closest('.crm-container').on('click', '.crm-form-submit.validate', function(e) {
77 $form = $(this).closest('form');
78 var className = ($form.attr('class') || '').match(/CRM_\S*/);
79 formClass = className && className[0];
80 if (formClass && mapper.hasOwnProperty(formClass) &&
81 // For activities, only show this if the changes were not made to the recurring settings
82 (formClass !== 'CRM_Activity_Form_Activity' || !CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block'))
83 ) {
84 cascadeChangesDialog();
85 e.preventDefault();
86 }
87 });
88
89 function updateMode() {
90 var mode = $('input[name=recur_mode]:checked', this).val(),
91 entityID = parseInt('{/literal}{$entityID}{literal}'),
92 entityTable = '{/literal}{$entityTable}{literal}',
93 priceSet = $('#price_set_id').val();
94 if (entityID != "" && mode && mapper.hasOwnProperty(formClass) && entityTable !="") {
95 $.getJSON(CRM.url("civicrm/ajax/recurringentity/update-mode",
96 {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable: mapper[formClass], priceSet: priceSet})
97 ).done(function (result) {
98 if (result.status != "" && result.status == 'Done') {
99 $form.submit();
100 } else if (result.status != "" && result.status == 'Error') {
101 if (confirm("{/literal}{ts escape='js' 1=$entity_type}Mode could not be updated, save only this %1?{/ts}{literal}")) {
102 $form.submit();
103 }
104 }
105 });
106 }
107 }
108 });
109 </script>
110 {/literal}
111 {/if}