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