| 1 | {*\r |
| 2 | +--------------------------------------------------------------------+\r |
| 3 | | CiviCRM version 4.7 |\r |
| 4 | +--------------------------------------------------------------------+\r |
| 5 | | Copyright CiviCRM LLC (c) 2004-2015 |\r |
| 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 |
| 27 | <div class="crm-core-form-recurringentity-block crm-accordion-wrapper{if $recurringFormIsEmbedded && !$scheduleReminderId} collapsed{/if}" id="recurring-entity-block">\r |
| 28 | <div class="crm-accordion-header">\r |
| 29 | {ts 1=$recurringEntityType}Repeat %1{/ts}\r |
| 30 | </div>\r |
| 31 | <div class="crm-accordion-body">\r |
| 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 |
| 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 |
| 42 | <tr class="crm-core-form-recurringentity-block-repetition_frequency">\r |
| 43 | <td class="label">{$form.repetition_frequency_unit.label} <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 |
| 45 | </tr>\r |
| 46 | <tr class="crm-core-form-recurringentity-block-start_action_condition">\r |
| 47 | <td class="label">\r |
| 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 |
| 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 |
| 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} {$form.limit_to.html}\r |
| 57 | </td>\r |
| 58 | </tr>\r |
| 59 | <tr class="crm-core-form-recurringentity-block-repeats_by">\r |
| 60 | <td class="label">{help id="id-repeats-by-week" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r |
| 61 | <td>{$form.repeats_by.2.html} {$form.entity_status_1.html} {$form.entity_status_2.html}\r |
| 62 | </td>\r |
| 63 | </tr>\r |
| 64 | <tr class="crm-core-form-recurringentity-block-ends">\r |
| 65 | <td class="label">{$form.ends.label} <span class="crm-marker">*</span> {help id="id-ends-after" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r |
| 66 | <td>{$form.ends.1.html} {$form.start_action_offset.html} {ts}occurrences{/ts}</td>\r |
| 67 | </tr>\r |
| 68 | <tr class="crm-core-form-recurringentity-block-absolute_date">\r |
| 69 | <td class="label"> {help id="id-ends-on" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r |
| 70 | <td>{$form.ends.2.html} {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 |
| 74 | <td class="label">{$form.exclude_date_list.label} {help id="id-exclude-date" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r |
| 75 | <td>{$form.exclude_date_list.html}</td>\r |
| 76 | </tr>\r |
| 77 | </table>\r |
| 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 |
| 83 | </div>\r |
| 84 | </div>\r |
| 85 | {literal}\r |
| 86 | <script type="text/javascript">\r |
| 87 | (function (_) {\r |
| 88 | CRM.$(function($) {\r |
| 89 | var $form = $('form.{/literal}{$form.formClass}{literal}'),\r |
| 90 | defaultDate = null;\r |
| 91 | \r |
| 92 | // Prevent html5 errors\r |
| 93 | $form.attr('novalidate', 'novalidate');\r |
| 94 | \r |
| 95 | function changeFrequencyUnit() {\r |
| 96 | switch ($(this).val()) {\r |
| 97 | case 'week':\r |
| 98 | //Show "Repeats On" block when week is selected\r |
| 99 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).show();\r |
| 100 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r |
| 101 | break;\r |
| 102 | case 'month':\r |
| 103 | //Show "Repeats By" block when month is selected\r |
| 104 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r |
| 105 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).show();\r |
| 106 | break;\r |
| 107 | default:\r |
| 108 | $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r |
| 109 | $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r |
| 110 | }\r |
| 111 | }\r |
| 112 | $('#repetition_frequency_unit', $form).each(changeFrequencyUnit).change(changeFrequencyUnit);\r |
| 113 | \r |
| 114 | function disableUnselected() {\r |
| 115 | $('input:radio[name=ends], input[name=repeats_by]', $form).not(':checked').siblings(':input').prop('disabled', true).removeClass('required');\r |
| 116 | }\r |
| 117 | disableUnselected();\r |
| 118 | \r |
| 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 |
| 122 | });\r |
| 123 | \r |
| 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 |
| 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 |
| 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 |
| 140 | $('#exclude_date_list', $form).crmSelect2({\r |
| 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 |
| 154 | .on('select2-opening', function(e) {\r |
| 155 | var $el = $(this),\r |
| 156 | $input = $('.select2-search-field input', $el.select2('container'));\r |
| 157 | // Prevent select2 from opening and show a datepicker instead\r |
| 158 | e.preventDefault();\r |
| 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 |
| 194 | }\r |
| 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 |
| 200 | });\r |
| 201 | \r |
| 202 | \r |
| 203 | // Dialog for preview repeat Configuration dates\r |
| 204 | function previewDialog() {\r |
| 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 |
| 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 |
| 217 | $form.submit();\r |
| 218 | });\r |
| 219 | }\r |
| 220 | \r |
| 221 | $('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click(function (e) {\r |
| 222 | if (validate()) {\r |
| 223 | previewDialog();\r |
| 224 | }\r |
| 225 | e.preventDefault();\r |
| 226 | });\r |
| 227 | \r |
| 228 | $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click(function (e) {\r |
| 229 | if (CRM.utils.initialValueChanged('#recurring-entity-block')) {\r |
| 230 | e.preventDefault();\r |
| 231 | if (validate()) {\r |
| 232 | previewDialog();\r |
| 233 | }\r |
| 234 | }\r |
| 235 | });\r |
| 236 | \r |
| 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 |
| 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 |
| 250 | });\r |
| 251 | })(CRM._);\r |
| 252 | </script>\r |
| 253 | {/literal}\r |