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