Ian province abbreviation patch - issue 724
[civicrm-core.git] / templates / CRM / Core / Form / RecurringEntity.tpl
CommitLineData
e8cca51a 1{*\r
2 +--------------------------------------------------------------------+\r
2c4c49ca 3 | CiviCRM version 4.7 |\r
e8cca51a 4 +--------------------------------------------------------------------+\r
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |\r
e8cca51a 6 +--------------------------------------------------------------------+\r
7 | This file is a part of CiviCRM. |\r
8 | |\r
9 | CiviCRM is free software; you can copy, modify, and distribute it |\r
10 | under the terms of the GNU Affero General Public License |\r
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |\r
12 | |\r
13 | CiviCRM is distributed in the hope that it will be useful, but |\r
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |\r
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |\r
16 | See the GNU Affero General Public License for more details. |\r
17 | |\r
18 | You should have received a copy of the GNU Affero General Public |\r
19 | License and the CiviCRM Licensing Exception along |\r
20 | with this program; if not, contact CiviCRM LLC |\r
21 | at info[AT]civicrm[DOT]org. If you have questions about the |\r
22 | GNU Affero General Public License or the licensing of CiviCRM, |\r
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |\r
24 +--------------------------------------------------------------------+\r
25*}\r
26\r
d2a4c29b 27<div class="crm-core-form-recurringentity-block crm-accordion-wrapper{if $recurringFormIsEmbedded && !$scheduleReminderId} collapsed{/if}" id="recurring-entity-block">\r
6635d7ad 28 <div class="crm-accordion-header">\r
b1e18356 29 {ts 1=$recurringEntityType}Repeat %1{/ts}\r
6635d7ad
CW
30 </div>\r
31 <div class="crm-accordion-body">\r
d2a4c29b
CW
32 {if !$recurringFormIsEmbedded}\r
33 <div class="crm-submit-buttons">\r
34 {include file="CRM/common/formButtons.tpl" location="top"}\r
35 </div>\r
36 {/if}\r
6635d7ad
CW
37 <table class="form-layout-compressed">\r
38 <tr class="crm-core-form-recurringentity-block-repetition_start_date" id="tr-repetition_start_date">\r
39 <td class="label">{$form.repetition_start_date.label}</td>\r
40 <td>{include file="CRM/common/jcalendar.tpl" elementName=repetition_start_date}</td>\r
41 </tr>\r
b1e18356
CW
42 <tr class="crm-core-form-recurringentity-block-repetition_frequency">\r
43 <td class="label">{$form.repetition_frequency_unit.label}&nbsp;<span class="crm-marker">*</span> {help id="id-repeats" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
44 <td>{$form.repetition_frequency_interval.html} {$form.repetition_frequency_unit.html}</td>\r
6635d7ad
CW
45 </tr>\r
46 <tr class="crm-core-form-recurringentity-block-start_action_condition">\r
47 <td class="label">\r
b1e18356 48 <label for="repeats_on">{$form.start_action_condition.label} {help id="id-repeats-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</label>\r
6635d7ad
CW
49 </td>\r
50 <td>\r
51 {$form.start_action_condition.html}\r
52 </td>\r
53 </tr>\r
54 <tr class="crm-core-form-recurringentity-block-repeats_by">\r
b1e18356
CW
55 <td class="label">{$form.repeats_by.label} {help id="id-repeats-by-month" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
56 <td>{$form.repeats_by.1.html}&nbsp;&nbsp;{$form.limit_to.html}\r
6635d7ad
CW
57 </td>\r
58 </tr>\r
59 <tr class="crm-core-form-recurringentity-block-repeats_by">\r
b1e18356 60 <td class="label">{help id="id-repeats-by-week" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
6635d7ad
CW
61 <td>{$form.repeats_by.2.html}&nbsp;&nbsp;{$form.entity_status_1.html}&nbsp;&nbsp;{$form.entity_status_2.html}\r
62 </td>\r
63 </tr>\r
64 <tr class="crm-core-form-recurringentity-block-ends">\r
d2a4c29b 65 <td class="label">{$form.ends.label}&nbsp;<span class="crm-marker">*</span> {help id="id-ends-after" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
b1e18356 66 <td>{$form.ends.1.html}&nbsp;{$form.start_action_offset.html} {ts}occurrences{/ts}</td>\r
6635d7ad
CW
67 </tr>\r
68 <tr class="crm-core-form-recurringentity-block-absolute_date">\r
b1e18356 69 <td class="label"> {help id="id-ends-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
6635d7ad
CW
70 <td>{$form.ends.2.html}&nbsp;{include file="CRM/common/jcalendar.tpl" elementName=repeat_absolute_date}\r
71 </td>\r
72 </tr>\r
73 <tr class="crm-core-form-recurringentity-block-exclude_date">\r
b1e18356 74 <td class="label">{$form.exclude_date_list.label} {help id="id-exclude-date" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
530dd28b 75 <td>{$form.exclude_date_list.html}</td>\r
6635d7ad 76 </tr>\r
6635d7ad 77 </table>\r
d2a4c29b
CW
78 {if !$recurringFormIsEmbedded}\r
79 <div class="crm-submit-buttons">\r
80 {include file="CRM/common/formButtons.tpl" location="bottom"}\r
81 </div>\r
82 {/if}\r
6635d7ad 83 </div>\r
e8cca51a 84</div>\r
e8cca51a 85{literal}\r
86<script type="text/javascript">\r
94ca4ab4 87(function (_) {\r
6635d7ad 88 CRM.$(function($) {\r
94ca4ab4
CW
89 var $form = $('form.{/literal}{$form.formClass}{literal}'),\r
90 defaultDate = null;\r
3c7bb1b1 91\r
d2a4c29b
CW
92 // Prevent html5 errors\r
93 $form.attr('novalidate', 'novalidate');\r
e8cca51a 94\r
d2a4c29b 95 function changeFrequencyUnit() {\r
6635d7ad 96 switch ($(this).val()) {\r
6635d7ad 97 case 'week':\r
6635d7ad 98 //Show "Repeats On" block when week is selected\r
d2a4c29b
CW
99 $('.crm-core-form-recurringentity-block-start_action_condition', $form).show();\r
100 $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r
6635d7ad
CW
101 break;\r
102 case 'month':\r
6635d7ad 103 //Show "Repeats By" block when month is selected\r
d2a4c29b
CW
104 $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r
105 $('.crm-core-form-recurringentity-block-repeats_by td', $form).show();\r
6635d7ad
CW
106 break;\r
107 default:\r
d2a4c29b
CW
108 $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r
109 $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r
e8cca51a 110 }\r
d2a4c29b
CW
111 }\r
112 $('#repetition_frequency_unit', $form).each(changeFrequencyUnit).change(changeFrequencyUnit);\r
e8cca51a 113\r
d2a4c29b 114 function disableUnselected() {\r
485f505c 115 $('input:radio[name=ends], input[name=repeats_by]', $form).not(':checked').siblings(':input').prop('disabled', true).removeClass('required');\r
d2a4c29b
CW
116 }\r
117 disableUnselected();\r
e8cca51a 118\r
d2a4c29b
CW
119 $('input:radio[name=ends], input[name=repeats_by]', $form).click(function() {\r
120 $(this).siblings(':input').prop('disabled', false).filter(':visible').addClass('required').focus();\r
121 disableUnselected();\r
e8cca51a 122 });\r
123\r
485f505c
CW
124 $('input:radio[name=ends]').siblings('.crm-clear-link').click(function() {\r
125 $('input:radio[name=ends][value=1]').prop('checked', true).trigger('click');\r
126 });\r
127\r
d2a4c29b
CW
128 function validate() {\r
129 var valid = $(':input', '#recurring-entity-block').valid(),\r
130 modified = CRM.utils.initialValueChanged('#recurring-entity-block');\r
131 $('#allowRepeatConfigToSubmit', $form).val(valid && modified ? '1' : '0');\r
132 return valid;\r
133 }\r
134\r
530dd28b
CW
135 function getDisplayDate(date) {\r
136 return $.datepicker.formatDate(CRM.config.dateInputFormat, $.datepicker.parseDate('yy-mm-dd', date));\r
137 }\r
138\r
139 // Combine select2 and datepicker into a multi-select-date widget\r
d2a4c29b 140 $('#exclude_date_list', $form).crmSelect2({\r
530dd28b
CW
141 multiple: true,\r
142 data: [],\r
143 initSelection: function(element, callback) {\r
144 var values = [];\r
145 $.each($(element).val().split(','), function(k, v) {\r
146 values.push({\r
147 text: getDisplayDate(v),\r
148 id: v\r
149 });\r
150 });\r
151 callback(values);\r
152 }\r
153 })\r
530dd28b 154 .on('select2-opening', function(e) {\r
94ca4ab4 155 var $el = $(this),\r
d6a6eecf 156 $input = $('.select2-search-field input', $el.select2('container'));\r
d2a4c29b 157 // Prevent select2 from opening and show a datepicker instead\r
530dd28b 158 e.preventDefault();\r
d6a6eecf
CW
159 if (!$input.data('datepicker')) {\r
160 $input\r
161 .datepicker({\r
162 beforeShow: function() {\r
163 var existingSelections = _.pluck($el.select2('data') || [], 'id');\r
164 return {\r
165 changeMonth: true,\r
166 changeYear: true,\r
167 defaultDate: defaultDate,\r
168 beforeShowDay: function(date) {\r
169 // Don't allow the same date to be selected twice\r
170 var dateStr = $.datepicker.formatDate('yy-mm-dd', date);\r
171 if (_.includes(existingSelections, dateStr)) {\r
172 return [false, '', '{/literal}{ts escape='js'}Already selected{/ts}{literal}'];\r
173 }\r
174 return [true, '', ''];\r
175 }\r
176 };\r
177 }\r
178 })\r
179 .datepicker('show')\r
180 .on('change.crmDate', function() {\r
181 if ($(this).val()) {\r
182 var date = defaultDate = $(this).datepicker('getDate'),\r
183 data = $el.select2('data') || [];\r
184 data.push({\r
185 text: $.datepicker.formatDate(CRM.config.dateInputFormat, date),\r
186 id: $.datepicker.formatDate('yy-mm-dd', date)\r
187 });\r
188 $el.select2('data', data, true);\r
189 }\r
190 })\r
191 .on('keyup', function() {\r
192 $(this).val('').datepicker('show');\r
193 });\r
94ca4ab4 194 }\r
d6a6eecf
CW
195 })\r
196 // Don't leave datepicker open when clearing selections\r
197 .on('select2-removed', function() {\r
198 $('input.hasDatepicker', $(this).select2('container'))\r
199 .datepicker('hide');\r
530dd28b
CW
200 });\r
201\r
94ca4ab4 202\r
a8a8ddac 203 // Dialog for preview repeat Configuration dates\r
e8cca51a 204 function previewDialog() {\r
343e507a
CW
205 // Set default value for start date on activity forms before generating preview\r
206 if (!$('#repetition_start_date', $form).val() && $('#activity_date_time', $form).val()) {\r
207 $('#repetition_start_date', $form)\r
208 .val($('#activity_date_time', $form).val())\r
209 .next().val($('#activity_date_time', $form).next().val())\r
210 .siblings('.hasTimeEntry').val($('#activity_date_time', $form).siblings('.hasTimeEntry').val());\r
211 }\r
a8a8ddac
CW
212 var payload = $form.serialize() + '{/literal}&entity_table={$entityTable}&entity_id={$currentEntityId}{literal}';\r
213 CRM.confirm({\r
214 width: '50%',\r
215 url: CRM.url("civicrm/recurringentity/preview", payload)\r
216 }).on('crmConfirm:yes', function() {\r
3c7bb1b1
CW
217 $form.submit();\r
218 });\r
e8cca51a 219 }\r
220\r
3c7bb1b1 221 $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click(function (e) {\r
d2a4c29b
CW
222 if (validate()) {\r
223 previewDialog();\r
224 }\r
3c7bb1b1 225 e.preventDefault();\r
e8cca51a 226 });\r
227\r
d2a4c29b
CW
228 $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click(function (e) {\r
229 if (CRM.utils.initialValueChanged('#recurring-entity-block')) {\r
0e2d8aaf 230 e.preventDefault();\r
d2a4c29b
CW
231 if (validate()) {\r
232 previewDialog();\r
233 }\r
e8cca51a 234 }\r
235 });\r
236\r
6e7c9fdc
CW
237 // Enable/disable form buttons when not embedded in another form\r
238 $form.on('change', function() {\r
239 $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').prop('disabled', !CRM.utils.initialValueChanged('#recurring-entity-block'));\r
240 });\r
241\r
8fe4b69f
CW
242 // Pluralize frequency options\r
243 var recurringFrequencyOptions = {/literal}{$recurringFrequencyOptions|@json_encode}{literal};\r
244 function pluralizeUnits() {\r
245 CRM.utils.setOptions($('[name=repetition_frequency_unit]', $form),\r
246 $(this).val() === '1' ? recurringFrequencyOptions.single : recurringFrequencyOptions.plural);\r
247 }\r
248 $('[name=repetition_frequency_interval]', $form).each(pluralizeUnits).change(pluralizeUnits);\r
249\r
6635d7ad 250 });\r
94ca4ab4 251})(CRM._);\r
e8cca51a 252</script>\r
253{/literal}\r