2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
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"}
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>
38 <tr class="crm-core-form-recurringentity-block-repetition_frequency_unit">
39 <td class="label">{$form.repetition_frequency_unit.label} <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>
42 <tr class="crm-core-form-recurringentity-block-repetition_frequency_interval">
43 <td class="label">{$form.repetition_frequency_interval.label} <span class="crm-marker" title="This field is required.">*</span></td>
44 <td>{$form.repetition_frequency_interval.html} <span id="repeats-every-text">hour(s)</span> {help id="id-repeats-every" file="CRM/Core/Form/RecurringEntity.hlp"}</td>
47 <tr class="crm-core-form-recurringentity-block-start_action_condition">
49 <label for="repeats_on">{$form.start_action_condition.label}: </label>
52 {$form.start_action_condition.html} {help id="id-repeats-on" file="CRM/Core/Form/RecurringEntity.hlp"}</td>
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} {$form.limit_to.html} {help id="id-repeats-by-month" file="CRM/Core/Form/RecurringEntity.hlp"}
60 <tr class="crm-core-form-recurringentity-block-repeats_by">
61 <td class="label"></td>
62 <td>{$form.repeats_by.2.html} {$form.entity_status_1.html} {$form.entity_status_2.html} {help id="id-repeats-by-week" file="CRM/Core/Form/RecurringEntity.hlp"}
65 <tr class="crm-core-form-recurringentity-block-ends">
66 <td class="label">{$form.ends.label} <span class="crm-marker" title="This field is required.">*</span></td>
67 <td>{$form.ends.1.html} {$form.start_action_offset.html} occurrences {help id="id-ends-after" file="CRM/Core/Form/RecurringEntity.hlp"}</td>
69 <tr class="crm-core-form-recurringentity-block-absolute_date">
70 <td class="label"></td>
71 <td>{$form.ends.2.html} {include file="CRM/common/jcalendar.tpl" elementName=repeat_absolute_date} {help id="id-ends-on" file="CRM/Core/Form/RecurringEntity.hlp"}
74 <tr class="crm-core-form-recurringentity-block-exclude_date">
75 <td class="label">{$form.exclude_date.label}</td>
76 <td> {include file="CRM/common/jcalendar.tpl" elementName=exclude_date}
77 {$form.add_to_exclude_list.html} {$form.remove_from_exclude_list.html}
78 {$form.exclude_date_list.html} {help id="id-exclude-date" file="CRM/Core/Form/RecurringEntity.hlp"}
82 <td class="label bold">{ts}Summary:{/ts}</td>
83 <td><span id="rec-summary"></span></td>
86 <div class="crm-submit-buttons">
87 {include file="CRM/common/formButtons.tpl" location="bottom"}
91 <div id="preview-dialog" class="hide-block">
92 <div id="generated_dates" class="show-block"></div>
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();
106 cj('.crm-core-form-recurringentity-block-start_action_condition').hide();
107 cj('.crm-core-form-recurringentity-block-repeats_by td').hide();
109 cj("#repeats-every-text").html(cj('#repetition_frequency_unit').val()+'(s)');
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('');
121 cj('#start_action_offset').removeAttr('enabled').attr('disabled','disabled');
122 cj('#repeat_absolute_date_display').removeAttr('enabled').attr('disabled','disabled');
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');
133 //Just in-case block shows up, disable it
134 cj('#limit_to, #entity_status_1, #entity_status_2').removeAttr('enabled').attr('disabled','disabled');
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();
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('');
172 cj('#repeat_absolute_date_display').removeAttr('enabled').attr('disabled','disabled');
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');
181 cj('#limit_to').removeAttr('enabled').attr('disabled','disabled');
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');
187 cj('#entity_status_1').removeAttr('enabled').attr('disabled','disabled');
188 cj('#entity_status_2').removeAttr('enabled').attr('disabled','disabled');
192 //Select all options in selectbox before submitting
193 cj(this).submit(function() {
194 cj('#exclude_date_list option').attr('selected',true);
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();
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();
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;
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);
232 cj('#exclude_date_list option:selected').each(function() {
233 dateTxt.push(cj(this).text());
235 var completeDateText = dateTxt.join(',');
236 cj('#copyExcludeDates').val(completeDateText);
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',
247 cj(this).dialog( "close" );
248 cj('form#Repeat, form#Activity').submit();
250 Cancel: function() { //cancel
251 cj(this).dialog( "close" );
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;
261 var formData = cj('form').serializeArray();
267 success: function (result) {
268 if (Object.keys(result).length > 0) {
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>';
273 for(var i in result) {
275 if (i == 'participantData') {
276 participantData = result.participantData;
279 var start_date = result[i].start_date;
280 var end_date = result[i].end_date;
282 var end_date_text = '';
283 if (end_date !== undefined) {
284 end_date_text = '<td>'+end_date+'</td>';
286 html += '<tr><td>'+count+'</td><td>'+start_date+'</td>'+end_date_text+'</tr>';
289 errors = result.errors;
293 var warningHtml = '';
294 if (Object.keys(participantData).length > 0) {
295 warningHtml += '<div class="messages status no-popup"><div class="icon inform-icon"></div> 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>';
301 warningHtml += '</table><br/>';
303 if (errors.length > 0) {
305 for (var j = 0; j < errors.length; j++) {
306 html += '<span class="crm-error">* ' + errors[j] + '</span><br/>';
309 if (warningHtml != "") {
310 cj('#generated_dates').append(warningHtml).append(html);
312 cj('#generated_dates').html(html);
314 if (end_date_text == "") {
315 cj('#th-end-date').hide();
317 if (cj("#preview-dialog").height() >= 300) {
318 cj('#preview-dialog').css('height', '300');
319 cj('#preview-dialog').css('overflow-y', 'auto');
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>");
326 complete: function() {
327 cj('div.crm-loading-element').hide();
333 cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click( function () {
334 return previewDialog();
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();
348 cj.data( document.body, "preview-dialog", false );
353 if (unsavedChanges) {
354 cj('#allowRepeatConfigToSubmit').val('1');
355 return previewDialog();
361 var finalSummary = '';
363 var interval = cj('#repetition_frequency_interval').val() + ' ';
364 if (cj('#repetition_frequency_interval').val() == 1) {
369 finalSummary = "Every " + interval + cj('#repetition_frequency_unit option:selected').val() + numberText;
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());
380 finalSummary += ' on ' + dayOfWeek.join();
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();
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();
394 if (cj('input:radio[name=ends]:checked').val() == 1) {
396 if (cj('#start_action_offset').val() != 1) {
397 timeText = cj('#start_action_offset').val() + ' times';
401 finalSummary += ', ' + timeText;
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';
412 default: return "th";
415 var newDate = monthNames[(date.getMonth())] + ' ' + date.getDate()+ addOrdinal() + ' ' + date.getFullYear();
416 finalSummary += ', untill '+ newDate;
419 //Build/Attach final Summary
420 cj('#rec-summary').html(finalSummary);
424 //Exclude list function
425 function addToExcludeList(val) {
428 for(var i = 0, opts = document.getElementById('exclude_date_list').options; i < opts.length; ++i) {
429 if (opts[i].text == val) {
434 if (exists == false) {
435 cj('#exclude_date_list').append('<option>'+val+'</option>');
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) {
445 src.remove(count, null);
455 {if empty($scheduleReminderId)}
457 <script type="text/javascript">
458 cj(document).ready(function() {
459 if (cj('#rec-summary').length) {
460 cj('#rec-summary').parent().parent().hide();