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