2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
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 |
8 +--------------------------------------------------------------------+
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}
15 <div class="crm-accordion-body">
16 {if !$recurringFormIsEmbedded}
17 <div class="crm-submit-buttons">
18 {include file="CRM/common/formButtons.tpl" location="top"}
21 <table class="form-layout-compressed">
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>
26 <tr class="crm-core-form-recurringentity-block-start_action_condition">
28 <label for="repeats_on">{$form.start_action_condition.label} {help id="id-repeats-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</label>
31 {$form.start_action_condition.html}
34 <tr class="crm-core-form-recurringentity-block-repeats_by">
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}
39 <tr class="crm-core-form-recurringentity-block-repeats_by">
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}
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>
49 <tr class="crm-core-form-recurringentity-block-ends">
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>
53 <tr class="crm-core-form-recurringentity-block-absolute_date">
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>
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>
62 {if !$recurringFormIsEmbedded}
63 <div class="crm-submit-buttons">
64 {include file="CRM/common/formButtons.tpl" location="bottom"}
70 <script type="text/javascript">
73 var $form = $('form.{/literal}{$form.formClass}{literal}'),
76 // Prevent html5 errors
77 $form.attr('novalidate', 'novalidate');
79 function changeFrequencyUnit() {
80 switch ($(this).val()) {
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();
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();
92 $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();
93 $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();
96 $('#repetition_frequency_unit', $form).each(changeFrequencyUnit).change(changeFrequencyUnit);
98 function disableEnds() {
99 $("#repeat_absolute_date, #start_action_offset").prop('disabled', true).removeClass('required');
101 if ($('input[name=ends][value=2]').prop('checked')) {
102 $("#repeat_absolute_date").prop('disabled', false).addClass('required').focus();
104 else if ($('input[name=ends][value=1]').prop('checked')) {
105 $('#start_action_offset').prop('disabled', false).addClass('required').focus();
109 $('input[name=ends]').click(function() {
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');
121 function getDisplayDate(date) {
122 return $.datepicker.formatDate(CRM.config.dateInputFormat, $.datepicker.parseDate('yy-mm-dd', date));
125 // Combine select2 and datepicker into a multi-select-date widget
126 $('#exclude_date_list', $form).crmSelect2({
129 initSelection: function(element, callback) {
131 $.each($(element).val().split(','), function(k, v) {
133 text: getDisplayDate(v),
140 .on('select2-opening', function(e) {
142 $input = $('.select2-search-field input', $el.select2('container'));
143 // Prevent select2 from opening and show a datepicker instead
145 if (!$input.data('datepicker')) {
148 beforeShow: function() {
149 var existingSelections = _.pluck($el.select2('data') || [], 'id');
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}'];
160 return [true, '', ''];
166 .on('change.crmDate', function() {
168 var date = defaultDate = $(this).datepicker('getDate'),
169 data = $el.select2('data') || [];
171 text: $.datepicker.formatDate(CRM.config.dateInputFormat, date),
172 id: $.datepicker.formatDate('yy-mm-dd', date)
174 $el.select2('data', data, true);
177 .on('keyup', function() {
178 $(this).val('').datepicker('show');
182 // Don't leave datepicker open when clearing selections
183 .on('select2-removed', function() {
184 $('input.hasDatepicker', $(this).select2('container'))
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());
198 var payload = $form.serialize() + '{/literal}&entity_table={$entityTable}&entity_id={$currentEntityId}{literal}';
201 url: CRM.url("civicrm/recurringentity/preview", payload)
202 }).on('crmConfirm:yes', function() {
207 $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click(function (e) {
214 $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click(function (e) {
215 if (CRM.utils.initialValueChanged('#recurring-entity-block')) {
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'));
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);
234 $('[name=repetition_frequency_interval]', $form).each(pluralizeUnits).change(pluralizeUnits);