Merge pull request #4715 from davecivicrm/CRM-14696
[civicrm-core.git] / templates / CRM / Core / Form / RecurringEntity.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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-block crm-form-block crm-core-form-recurringentity-block crm-accordion-wrapper" id="recurring-entity-block">
28 <div class="crm-accordion-header">
29 Repeat {if $entityType}{$entityType}{/if}
30 </div>
31 <div class="crm-accordion-body">
32 <div class="crm-submit-buttons">
33 {include file="CRM/common/formButtons.tpl" location="top"}
34 </div>
35 <table class="form-layout-compressed">
36 <tr class="crm-core-form-recurringentity-block-repetition_start_date" id="tr-repetition_start_date">
37 <td class="label">{$form.repetition_start_date.label}</td>
38 <td>{include file="CRM/common/jcalendar.tpl" elementName=repetition_start_date}</td>
39 </tr>
40 <tr class="crm-core-form-recurringentity-block-repetition_frequency_unit">
41 <td class="label">{$form.repetition_frequency_unit.label}&nbsp;<span class="crm-marker" title="This field is required.">*</span></td>
42 <td>{$form.repetition_frequency_unit.html} {help id="id-repeats" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>
43 </tr>
44 <tr class="crm-core-form-recurringentity-block-repetition_frequency_interval">
45 <td class="label">{$form.repetition_frequency_interval.label}&nbsp;<span class="crm-marker" title="This field is required.">*</span></td>
46 <td>{$form.repetition_frequency_interval.html} &nbsp;<span id="repeats-every-text">hour(s)</span> {help id="id-repeats-every" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>
47 </td>
48 </tr>
49 <tr class="crm-core-form-recurringentity-block-start_action_condition">
50 <td class="label">
51 <label for="repeats_on">{$form.start_action_condition.label}: </label>
52 </td>
53 <td>
54 {$form.start_action_condition.html} {help id="id-repeats-on" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>
55 </td>
56 </tr>
57 <tr class="crm-core-form-recurringentity-block-repeats_by">
58 <td class="label">{$form.repeats_by.label}</td>
59 <td>{$form.repeats_by.1.html}&nbsp;&nbsp;{$form.limit_to.html} {help id="id-repeats-by-month" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}
60 </td>
61 </tr>
62 <tr class="crm-core-form-recurringentity-block-repeats_by">
63 <td class="label"></td>
64 <td>{$form.repeats_by.2.html}&nbsp;&nbsp;{$form.entity_status_1.html}&nbsp;&nbsp;{$form.entity_status_2.html} {help id="id-repeats-by-week" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}
65 </td>
66 </tr>
67 <tr class="crm-core-form-recurringentity-block-ends">
68 <td class="label">{$form.ends.label}&nbsp;<span class="crm-marker" title="This field is required.">*</span></td>
69 <td>{$form.ends.1.html}&nbsp;{$form.start_action_offset.html}&nbsp;occurrences&nbsp;{help id="id-ends-after" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>
70 </tr>
71 <tr class="crm-core-form-recurringentity-block-absolute_date">
72 <td class="label"></td>
73 <td>{$form.ends.2.html}&nbsp;{include file="CRM/common/jcalendar.tpl" elementName=repeat_absolute_date} {help id="id-ends-on" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}
74 </td>
75 </tr>
76 <tr class="crm-core-form-recurringentity-block-exclude_date">
77 <td class="label">{$form.exclude_date.label}</td>
78 <td>&nbsp;{include file="CRM/common/jcalendar.tpl" elementName=exclude_date}
79 &nbsp;{$form.add_to_exclude_list.html}&nbsp;{$form.remove_from_exclude_list.html}
80 {$form.exclude_date_list.html} {help id="id-exclude-date" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}
81 </td>
82 </tr>
83 <tr>
84 <td class="label bold">{ts}Summary:{/ts}</td>
85 <td><span id="rec-summary"></span></td>
86 </tr>
87 </table>
88 <div class="crm-submit-buttons">
89 {include file="CRM/common/formButtons.tpl" location="bottom"}
90 </div>
91 </div>
92 </div>
93 <div id="preview-dialog" class="hide-block">
94 <div id="generated_dates" class="show-block"></div>
95 </div>
96 {literal}
97 <script type="text/javascript">
98 cj(document).ready(function() {
99 cj('#repetition_start_date_display').closest("tr").hide();
100 /****** On load "Repeats By" and "Repeats On" blocks should be hidden if dropdown value is not week or month****** (Edit Mode)***/
101 if (cj('#repetition_frequency_unit').val() == "week") {
102 cj('.crm-core-form-recurringentity-block-start_action_condition').show();
103 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
104 } else if (cj('#repetition_frequency_unit').val() == "month") {
105 cj('.crm-core-form-recurringentity-block-repeats_by td').show();
106 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
107 } else {
108 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
109 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
110 }
111 cj("#repeats-every-text").html(cj('#repetition_frequency_unit').val()+'(s)');
112
113 /***********On Load Set Ends Value (Edit Mode) **********/
114 if (cj('input:radio[name=ends]:checked').val() == 1) {
115 cj('#start_action_offset').removeAttr('disabled').attr('enabled','enabled');
116 cj('#repeat_absolute_date_display').removeAttr("enabled").attr('disabled','disabled');
117 cj('#repeat_absolute_date_display').val('');
118 } else if (cj('input:radio[name=ends]:checked').val() == 2) {
119 cj('#repeat_absolute_date_display').removeAttr("disabled").attr('enabled','enabled');
120 cj('#start_action_offset').removeAttr('enabled').attr('disabled','disabled');
121 cj('#start_action_offset').val('');
122 } else {
123 cj('#start_action_offset').removeAttr('enabled').attr('disabled','disabled');
124 cj('#repeat_absolute_date_display').removeAttr('enabled').attr('disabled','disabled');
125 }
126
127 /******On Load set Repeats by section******************/
128 if (cj('input:radio[name=repeats_by]:checked').val() == 1) {
129 cj('#limit_to').removeAttr('disabled').attr('enabled','enabled');
130 cj('#entity_status_1, #entity_status_2').removeAttr("enabled").attr('disabled','disabled');
131 } else if (cj('input:radio[name=repeats_by]:checked').val() == 2) {
132 cj('#entity_status_1, #entity_status_2').removeAttr("disabled").attr('enabled','enabled');
133 cj('#limit_to').removeAttr('enabled').attr('disabled','disabled');
134 } else {
135 //Just in-case block shows up, disable it
136 cj('#limit_to, #entity_status_1, #entity_status_2').removeAttr('enabled').attr('disabled','disabled');
137 }
138
139 cj('#repetition_frequency_unit').change(function () {
140 if (cj(this).val()==='hour') {
141 cj('#repeats-every-text').html(cj(this).val()+'(s)');
142 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
143 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
144 } else if (cj(this).val()==='day') {
145 cj('#repeats-every-text').html(cj(this).val()+'(s)');
146 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
147 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
148 } else if (cj(this).val()==='week') {
149 cj('#repeats-every-text').html(cj(this).val()+'(s)');
150 //Show "Repeats On" block when week is selected
151 cj('.crm-core-form-recurringentity-block-start_action_condition').show();
152 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
153 } else if (cj(this).val()==='month') {
154 cj('#repeats-every-text').html(cj(this).val()+'(s)');
155 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
156 //Show "Repeats By" block when month is selected
157 cj('.crm-core-form-recurringentity-block-repeats_by td').show();
158 } else if (cj(this).val()==='year') {
159 cj('#repeats-every-text').html(cj(this).val()+'(s)');
160 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
161 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
162 }
163 });
164
165 // For "Ends" block
166 cj('input:radio[name=ends]').click(function() {
167 if (cj(this).val() == 1) {
168 cj('#start_action_offset').removeAttr('disabled').attr('enabled','enabled');
169 cj('#repeat_absolute_date_display').val('');
170 } else if (cj(this).val() == 2) {
171 cj('#repeat_absolute_date_display').removeAttr('disabled').attr('enabled','enabled');
172 cj('#start_action_offset').val('');
173 } else {
174 cj('#repeat_absolute_date_display').removeAttr('enabled').attr('disabled','disabled');
175 }
176 });
177
178 //For "Repeats By" block
179 cj('input:radio[name=repeats_by]').click(function() {
180 if (cj(this).val() == 1) {
181 cj('#limit_to').removeAttr('disabled').attr('enabled','enabled');
182 } else {
183 cj('#limit_to').removeAttr('enabled').attr('disabled','disabled');
184 }
185 if (cj(this).val() == 2) {
186 cj('#entity_status_1').removeAttr('disabled').attr('enabled','enabled');
187 cj('#entity_status_2').removeAttr('disabled').attr('enabled','enabled');
188 } else {
189 cj('#entity_status_1').removeAttr('enabled').attr('disabled','disabled');
190 cj('#entity_status_2').removeAttr('enabled').attr('disabled','disabled');
191 }
192 });
193
194 //Select all options in selectbox before submitting
195 cj(this).submit(function() {
196 cj('#exclude_date_list option').attr('selected',true);
197
198 //Check form for values submitted
199 if (cj('input[name=ends]:checked').val() == 1) {
200 if (cj('#start_action_offset').val() == "") {
201 if (!cj('span#start_action_offset-error').length) {
202 cj('#start_action_offset').after('<span id ="start_action_offset-error" class="crm-error"> This is a required field.</span>');
203 //Check if other message already present, hide it
204 cj('span#repeat_absolute_date_display-error').toggle();
205 }
206 return false;
207 }
208 } else if (cj('input[name=ends]:checked').val() == 2) {
209 if (cj('#repeat_absolute_date_display').val() == "") {
210 if (!cj('span#repeat_absolute_date_display-error').length) {
211 cj('#repeat_absolute_date_display').after('<span id="repeat_absolute_date_display-error" class="crm-error"> This is a required field.</span>');
212 //Check if other message already present, hide it
213 cj('span#start_action_offset-error').toggle();
214 }
215 return false;
216 }
217 }
218
219 });
220
221 //Detect changes in Repeat configuration field
222 var unsavedChanges = false;
223 cj('div.crm-core-form-recurringentity-block').on('change', function() {
224 unsavedChanges = true;
225 });
226
227 //If there are changes in repeat configuration, enable save button
228 //Dialog for preview repeat Configuration dates
229 cj('#preview-dialog').dialog({ autoOpen: false });
230 function previewDialog() {
231 cj('#exclude_date_list option').attr('selected',true);
232 //Copy exclude dates
233 var dateTxt=[];
234 cj('#exclude_date_list option:selected').each(function() {
235 dateTxt.push(cj(this).text());
236 });
237 var completeDateText = dateTxt.join(',');
238 cj('#copyExcludeDates').val(completeDateText);
239
240 cj('#generated_dates').html('').html('<div class="crm-loading-element"><span class="loading-text">{/literal}{ts escape='js'}Just a moment, generating dates{/ts}{literal}...</span></div>');
241 cj('#preview-dialog').dialog('open');
242 cj('#preview-dialog').dialog({
243 title: 'Confirm dates',
244 width: '650',
245 position: 'center',
246 //draggable: false,
247 buttons: {
248 Ok: function() {
249 cj(this).dialog( "close" );
250 cj('form#Repeat, form#Activity').submit();
251 },
252 Cancel: function() { //cancel
253 cj(this).dialog( "close" );
254 }
255 }
256 });
257 var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview");
258 var entityID = parseInt('{/literal}{$currentEntityId}{literal}');
259 var entityTable = '{/literal}{$entityTable}{literal}';
260 if (entityTable != "") {
261 ajaxurl += "?entity_table="+entityTable;
262 }
263 if (entityID != "") {
264 ajaxurl += "&entity_id="+entityID;
265 }
266 var formData = cj('form').serializeArray();
267 cj.ajax({
268 dataType: "json",
269 type: "POST",
270 data: formData,
271 url: ajaxurl,
272 success: function (result) {
273 if (Object.keys(result).length > 0) {
274 var errors = [];
275 var participantData = [];
276 var html = 'Based on your repeat configuration, here is the list of dates. Do you wish to create a recurring set with these dates?<br/><table id="options" class="display"><thead><tr><th></th><th>Start date</th><th id="th-end-date">End date</th></tr><thead>';
277 var count = 1;
278 for(var i in result) {
279 if (i != 'errors') {
280 if (i == 'participantData') {
281 participantData = result.participantData;
282 break;
283 }
284 var start_date = result[i].start_date;
285 var end_date = result[i].end_date;
286
287 var end_date_text = '';
288 if (end_date !== undefined) {
289 end_date_text = '<td>'+end_date+'</td>';
290 }
291 html += '<tr><td>'+count+'</td><td>'+start_date+'</td>'+end_date_text+'</tr>';
292 count = count + 1;
293 } else {
294 errors = result.errors;
295 }
296 }
297 html += '</table>';
298 var warningHtml = '';
299 if (Object.keys(participantData).length > 0) {
300 warningHtml += '<div class="messages status no-popup"><div class="icon inform-icon"></div>&nbsp;There are registrations for the repeating events already present in the set, continuing with the process would unlink them and repeating events without registration would be trashed. </div><table id="options" class="display"><thead><tr><th>Event ID</th><th>Event</th><th>Participant Count</th></tr><thead>';
301 for (var id in participantData) {
302 for(var data in participantData[id]) {
303 warningHtml += '<tr><td>'+id+'</td><td> <a href="{/literal}{crmURL p="civicrm/event/manage/settings" q="reset=1&action=update&id="}{literal}'+id+'{/literal}{literal}">'+data+'</a></td><td><a href="{/literal}{crmURL p='civicrm/event/search' q="reset=1&force=1&status=true&event="}{literal}'+id+'{/literal}{literal}">'+participantData[id][data]+'</a></td></tr>';
304 }
305 }
306 warningHtml += '</table><br/>';
307 }
308 if (errors.length > 0) {
309 html = '';
310 for (var j = 0; j < errors.length; j++) {
311 html += '<span class="crm-error">*&nbsp;' + errors[j] + '</span><br/>';
312 }
313 }
314 if (warningHtml != "") {
315 cj('#generated_dates').append(warningHtml).append(html);
316 } else {
317 cj('#generated_dates').html(html);
318 }
319 if (end_date_text == "") {
320 cj('#th-end-date').hide();
321 }
322 if (cj("#preview-dialog").height() >= 300) {
323 cj('#preview-dialog').css('height', '300');
324 cj('#preview-dialog').css('overflow-y', 'auto');
325 }
326 } else {
327 cj('div.ui-dialog-buttonset button span:contains(Ok)').hide();
328 cj('#generated_dates').append("<span class='crm-error'>Sorry, no dates could be generated for the given criteria!</span>");
329 }
330 },
331 complete: function() {
332 cj('div.crm-loading-element').hide();
333 }
334 });
335 return false;
336 }
337
338 cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click( function () {
339 return previewDialog();
340 });
341
342 cj('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function () {
343 //Process this only when repeat is configured. We need to do this test here as there is a common save for activity.
344 var isRepeatConfigured = '{/literal}{$scheduleReminderId}{literal}';
345 if (isRepeatConfigured) {
346 if (unsavedChanges) {
347 cj('#allowRepeatConfigToSubmit').val('1');
348 //Set this variable to decide which dialog box to show
349 cj.data( document.body, "preview-dialog", true );
350 return previewDialog();
351 }
352 else {
353 cj.data( document.body, "preview-dialog", false );
354 return false;
355 }
356 }
357 else {
358 if (unsavedChanges) {
359 cj('#allowRepeatConfigToSubmit').val('1');
360 return previewDialog();
361 }
362 }
363 });
364
365 //Build Summary
366 var finalSummary = '';
367 var numberText = '';
368 var interval = cj('#repetition_frequency_interval').val() + ' ';
369 if (cj('#repetition_frequency_interval').val() == 1) {
370 interval = '';
371 } else {
372 numberText = 's';
373 }
374 finalSummary = "Every " + interval + cj('#repetition_frequency_unit option:selected').val() + numberText;
375
376 //Case Week
377 var dayOfWeek = new Array();
378 if (cj('#repetition_frequency_unit option:selected').val() == "week") {
379 cj("input[name^='start_action_condition']:checked").each(function() {
380 var tempArray = new Array();
381 var thisID = cj(this).attr('id');
382 tempArray = thisID.split('_');
383 dayOfWeek.push(tempArray[3].substr(0, 1).toUpperCase() + tempArray[3].substr(1).toLowerCase());
384 });
385 finalSummary += ' on ' + dayOfWeek.join();
386 }
387
388 //Case Monthly
389 if (cj('#repetition_frequency_unit option:selected').val() == "month") {
390 if (cj('input:radio[name=repeats_by]:checked').val() == 1) {
391 finalSummary += ' on day ' + cj('#limit_to').val();
392 }
393 if (cj('input:radio[name=repeats_by]:checked').val() == 2) {
394 finalSummary += ' on ' + cj('#entity_status_1').val().substr(0, 1).toUpperCase() + cj('#entity_status_1').val().substr(1).toLowerCase() + ' ' + cj('#entity_status_2').val().substr(0, 1).toUpperCase() + cj('#entity_status_2').val().substr(1).toLowerCase();
395 }
396 }
397
398 //Case Ends
399 if (cj('input:radio[name=ends]:checked').val() == 1) {
400 var timeText = ''
401 if (cj('#start_action_offset').val() != 1) {
402 timeText = cj('#start_action_offset').val() + ' times';
403 } else {
404 timeText = ' once';
405 }
406 finalSummary += ', ' + timeText;
407 }
408 if (cj('input:radio[name=ends]:checked').val() == 2) {
409 var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
410 var date = new Date(cj('#repeat_absolute_date_display').val());
411 function addOrdinal(d) {
412 if (d>3 && d<21) return 'th';
413 switch (d % 10) {
414 case 1: return "st";
415 case 2: return "nd";
416 case 3: return "rd";
417 default: return "th";
418 }
419 }
420 var newDate = monthNames[(date.getMonth())] + ' ' + date.getDate()+ addOrdinal() + ' ' + date.getFullYear();
421 finalSummary += ', untill '+ newDate;
422 }
423
424 //Build/Attach final Summary
425 cj('#rec-summary').html(finalSummary);
426
427 });
428
429 //Exclude list function
430 function addToExcludeList(val) {
431 if (val !== "") {
432 var exists = false;
433 for(var i = 0, opts = document.getElementById('exclude_date_list').options; i < opts.length; ++i) {
434 if (opts[i].text == val) {
435 exists = true;
436 break;
437 }
438 }
439 if (exists == false) {
440 cj('#exclude_date_list').append('<option>'+val+'</option>');
441 }
442 }
443 }
444
445 function removeFromExcludeList(sourceID) {
446 var src = document.getElementById(sourceID);
447 for(var count= src.options.length-1; count >= 0; count--) {
448 if (src.options[count].selected == true) {
449 try{
450 src.remove(count, null);
451 }catch(error) {
452 src.remove(count);
453 }
454 }
455 }
456 }
457 </script>
458 {/literal}
459 {*Hide Summary*}
460 {if empty($scheduleReminderId)}
461 {literal}
462 <script type="text/javascript">
463 cj(document).ready(function() {
464 if (cj('#rec-summary').length) {
465 cj('#rec-summary').parent().parent().hide();
466 }
467 });
468 </script>
469 {/literal}
470 {/if}