Commit | Line | Data |
---|---|---|
a90a5a4f | 1 | {* |
2 | +--------------------------------------------------------------------+ | |
fee14197 | 3 | | CiviCRM version 5 | |
a90a5a4f | 4 | +--------------------------------------------------------------------+ |
f299f7db | 5 | | Copyright CiviCRM LLC (c) 2004-2020 | |
a90a5a4f | 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 | ||
27 | <div class="crm-core-form-recurringentity-block crm-accordion-wrapper{if $recurringFormIsEmbedded && !$scheduleReminderId} collapsed{/if}" id="recurring-entity-block"> | |
28 | <div class="crm-accordion-header"> | |
29 | {ts 1=$recurringEntityType}Repeat %1{/ts} | |
30 | </div> | |
31 | <div class="crm-accordion-body"> | |
32 | {if !$recurringFormIsEmbedded} | |
33 | <div class="crm-submit-buttons"> | |
34 | {include file="CRM/common/formButtons.tpl" location="top"} | |
35 | </div> | |
36 | {/if} | |
37 | <table class="form-layout-compressed"> | |
a90a5a4f | 38 | <tr class="crm-core-form-recurringentity-block-repetition_frequency"> |
39 | <td class="label">{$form.repetition_frequency_unit.label} <span class="crm-marker">*</span> {help id="id-repeats" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td> | |
40 | <td>{$form.repetition_frequency_interval.html} {$form.repetition_frequency_unit.html}</td> | |
41 | </tr> | |
42 | <tr class="crm-core-form-recurringentity-block-start_action_condition"> | |
43 | <td class="label"> | |
44 | <label for="repeats_on">{$form.start_action_condition.label} {help id="id-repeats-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</label> | |
45 | </td> | |
46 | <td> | |
47 | {$form.start_action_condition.html} | |
48 | </td> | |
49 | </tr> | |
50 | <tr class="crm-core-form-recurringentity-block-repeats_by"> | |
aff91e50 MWMC |
51 | <td class="label">{$form.repeats_by.label} <span class="crm-marker">*</span></td> |
52 | <td>{help id="id-repeats-by-month" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"} {$form.repeats_by.1.html} {$form.limit_to.html} | |
a90a5a4f | 53 | </td> |
54 | </tr> | |
55 | <tr class="crm-core-form-recurringentity-block-repeats_by"> | |
aff91e50 MWMC |
56 | <td class="label"></td> |
57 | <td>{help id="id-repeats-by-week" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"} {$form.repeats_by.2.html} {$form.entity_status_1.html} {$form.entity_status_2.html} | |
a90a5a4f | 58 | </td> |
59 | </tr> | |
aff91e50 MWMC |
60 | <tr><td> </td><td> </td></tr> |
61 | <tr class="crm-core-form-recurringentity-block-repetition_start_date" id="tr-repetition_start_date"> | |
62 | <td class="label">{$form.repetition_start_date.label}</td> | |
63 | <td>{$form.repetition_start_date.html}</td> | |
64 | </tr> | |
a90a5a4f | 65 | <tr class="crm-core-form-recurringentity-block-ends"> |
aff91e50 MWMC |
66 | <td class="label">{$form.ends.label} <span class="crm-marker">*</span></td> |
67 | <td>{help id="id-ends-after" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"} {$form.ends.1.html} {$form.start_action_offset.html} {ts}occurrences{/ts}</td> | |
a90a5a4f | 68 | </tr> |
69 | <tr class="crm-core-form-recurringentity-block-absolute_date"> | |
aff91e50 MWMC |
70 | <td class="label"> </td> |
71 | <td>{help id="id-ends-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"} {$form.ends.2.html} {$form.repeat_absolute_date.html}</td> | |
a90a5a4f | 72 | </tr> |
73 | <tr class="crm-core-form-recurringentity-block-exclude_date"> | |
74 | <td class="label">{$form.exclude_date_list.label} {help id="id-exclude-date" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td> | |
75 | <td>{$form.exclude_date_list.html}</td> | |
76 | </tr> | |
77 | </table> | |
78 | {if !$recurringFormIsEmbedded} | |
79 | <div class="crm-submit-buttons"> | |
80 | {include file="CRM/common/formButtons.tpl" location="bottom"} | |
81 | </div> | |
82 | {/if} | |
83 | </div> | |
84 | </div> | |
85 | {literal} | |
86 | <script type="text/javascript"> | |
87 | (function (_) { | |
88 | CRM.$(function($) { | |
89 | var $form = $('form.{/literal}{$form.formClass}{literal}'), | |
90 | defaultDate = null; | |
91 | ||
92 | // Prevent html5 errors | |
93 | $form.attr('novalidate', 'novalidate'); | |
94 | ||
95 | function changeFrequencyUnit() { | |
96 | switch ($(this).val()) { | |
97 | case 'week': | |
98 | //Show "Repeats On" block when week is selected | |
99 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).show(); | |
100 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide(); | |
101 | break; | |
102 | case 'month': | |
103 | //Show "Repeats By" block when month is selected | |
104 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide(); | |
105 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).show(); | |
106 | break; | |
107 | default: | |
108 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide(); | |
109 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide(); | |
110 | } | |
111 | } | |
112 | $('#repetition_frequency_unit', $form).each(changeFrequencyUnit).change(changeFrequencyUnit); | |
113 | ||
aff91e50 MWMC |
114 | function disableEnds() { |
115 | $("#repeat_absolute_date, #start_action_offset").prop('disabled', true).removeClass('required'); | |
a90a5a4f | 116 | |
aff91e50 MWMC |
117 | if ($('input[name=ends][value=2]').prop('checked')) { |
118 | $("#repeat_absolute_date").prop('disabled', false).addClass('required').focus(); | |
119 | } | |
120 | else if ($('input[name=ends][value=1]').prop('checked')) { | |
121 | $('#start_action_offset').prop('disabled', false).addClass('required').focus(); | |
122 | } | |
123 | } | |
a90a5a4f | 124 | |
aff91e50 MWMC |
125 | $('input[name=ends]').click(function() { |
126 | disableEnds(); | |
a90a5a4f | 127 | }); |
aff91e50 | 128 | disableEnds(); |
a90a5a4f | 129 | |
130 | function validate() { | |
131 | var valid = $(':input', '#recurring-entity-block').valid(), | |
132 | modified = CRM.utils.initialValueChanged('#recurring-entity-block'); | |
133 | $('#allowRepeatConfigToSubmit', $form).val(valid && modified ? '1' : '0'); | |
134 | return valid; | |
135 | } | |
136 | ||
137 | function getDisplayDate(date) { | |
138 | return $.datepicker.formatDate(CRM.config.dateInputFormat, $.datepicker.parseDate('yy-mm-dd', date)); | |
139 | } | |
140 | ||
141 | // Combine select2 and datepicker into a multi-select-date widget | |
142 | $('#exclude_date_list', $form).crmSelect2({ | |
143 | multiple: true, | |
144 | data: [], | |
145 | initSelection: function(element, callback) { | |
146 | var values = []; | |
147 | $.each($(element).val().split(','), function(k, v) { | |
148 | values.push({ | |
149 | text: getDisplayDate(v), | |
150 | id: v | |
151 | }); | |
152 | }); | |
153 | callback(values); | |
154 | } | |
155 | }) | |
156 | .on('select2-opening', function(e) { | |
157 | var $el = $(this), | |
158 | $input = $('.select2-search-field input', $el.select2('container')); | |
159 | // Prevent select2 from opening and show a datepicker instead | |
160 | e.preventDefault(); | |
161 | if (!$input.data('datepicker')) { | |
162 | $input | |
163 | .datepicker({ | |
164 | beforeShow: function() { | |
165 | var existingSelections = _.pluck($el.select2('data') || [], 'id'); | |
166 | return { | |
167 | changeMonth: true, | |
168 | changeYear: true, | |
169 | defaultDate: defaultDate, | |
170 | beforeShowDay: function(date) { | |
171 | // Don't allow the same date to be selected twice | |
172 | var dateStr = $.datepicker.formatDate('yy-mm-dd', date); | |
173 | if (_.includes(existingSelections, dateStr)) { | |
174 | return [false, '', '{/literal}{ts escape='js'}Already selected{/ts}{literal}']; | |
175 | } | |
176 | return [true, '', '']; | |
177 | } | |
178 | }; | |
179 | } | |
180 | }) | |
181 | .datepicker('show') | |
182 | .on('change.crmDate', function() { | |
183 | if ($(this).val()) { | |
184 | var date = defaultDate = $(this).datepicker('getDate'), | |
185 | data = $el.select2('data') || []; | |
186 | data.push({ | |
187 | text: $.datepicker.formatDate(CRM.config.dateInputFormat, date), | |
188 | id: $.datepicker.formatDate('yy-mm-dd', date) | |
189 | }); | |
190 | $el.select2('data', data, true); | |
191 | } | |
192 | }) | |
193 | .on('keyup', function() { | |
194 | $(this).val('').datepicker('show'); | |
195 | }); | |
196 | } | |
197 | }) | |
198 | // Don't leave datepicker open when clearing selections | |
199 | .on('select2-removed', function() { | |
200 | $('input.hasDatepicker', $(this).select2('container')) | |
201 | .datepicker('hide'); | |
202 | }); | |
203 | ||
204 | ||
205 | // Dialog for preview repeat Configuration dates | |
206 | function previewDialog() { | |
207 | // Set default value for start date on activity forms before generating preview | |
208 | if (!$('#repetition_start_date', $form).val() && $('#activity_date_time', $form).val()) { | |
209 | $('#repetition_start_date', $form) | |
210 | .val($('#activity_date_time', $form).val()) | |
211 | .next().val($('#activity_date_time', $form).next().val()) | |
212 | .siblings('.hasTimeEntry').val($('#activity_date_time', $form).siblings('.hasTimeEntry').val()); | |
213 | } | |
214 | var payload = $form.serialize() + '{/literal}&entity_table={$entityTable}&entity_id={$currentEntityId}{literal}'; | |
215 | CRM.confirm({ | |
216 | width: '50%', | |
217 | url: CRM.url("civicrm/recurringentity/preview", payload) | |
218 | }).on('crmConfirm:yes', function() { | |
219 | $form.submit(); | |
220 | }); | |
221 | } | |
222 | ||
223 | $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click(function (e) { | |
224 | if (validate()) { | |
225 | previewDialog(); | |
226 | } | |
227 | e.preventDefault(); | |
228 | }); | |
229 | ||
230 | $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click(function (e) { | |
231 | if (CRM.utils.initialValueChanged('#recurring-entity-block')) { | |
232 | e.preventDefault(); | |
233 | if (validate()) { | |
234 | previewDialog(); | |
235 | } | |
236 | } | |
237 | }); | |
238 | ||
239 | // Enable/disable form buttons when not embedded in another form | |
240 | $form.on('change', function() { | |
241 | $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').prop('disabled', !CRM.utils.initialValueChanged('#recurring-entity-block')); | |
242 | }); | |
243 | ||
244 | // Pluralize frequency options | |
245 | var recurringFrequencyOptions = {/literal}{$recurringFrequencyOptions|@json_encode}{literal}; | |
246 | function pluralizeUnits() { | |
247 | CRM.utils.setOptions($('[name=repetition_frequency_unit]', $form), | |
248 | $(this).val() === '1' ? recurringFrequencyOptions.single : recurringFrequencyOptions.plural); | |
249 | } | |
250 | $('[name=repetition_frequency_interval]', $form).each(pluralizeUnits).change(pluralizeUnits); | |
251 | ||
252 | }); | |
253 | })(CRM._); | |
254 | </script> | |
255 | {/literal} |