* @return array
*/
public static function setDefaultValues() {
- $defaults = array();
+ // Defaults for new entity
+ $defaults = array(
+ 'repetition_frequency_unit' => 'week',
+ );
+
+ // Default for existing entity
if (self::$_scheduleReminderID) {
$defaults['repetition_frequency_unit'] = self::$_scheduleReminderDetails->repetition_frequency_unit;
$defaults['repetition_frequency_interval'] = self::$_scheduleReminderDetails->repetition_frequency_interval;
if (self::$_scheduleReminderDetails->limit_to) {
$defaults['repeats_by'] = 1;
}
- $explodeStartActionCondition = array();
if (self::$_scheduleReminderDetails->entity_status) {
$explodeStartActionCondition = explode(" ", self::$_scheduleReminderDetails->entity_status);
$defaults['entity_status_1'] = $explodeStartActionCondition[0];
'saturday',
);
$dayOfTheWeek = array_combine($dayOfTheWeek, CRM_Utils_Date::getAbbrWeekdayNames());
- $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), $freqUnitsDisplay);
+ $form->add('select', 'repetition_frequency_unit', ts('Repeats every'), $freqUnitsDisplay, FALSE, array('class' => 'required'));
$numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
- $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions);
+ $form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required'));
$form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime'));
foreach ($dayOfTheWeek as $key => $val) {
$startActionCondition[] = $form->createElement('checkbox', $key, NULL, $val);
'1' => ts('day of the month'),
'2' => ts('day of the week'),
);
- $form->addRadio('repeats_by', ts("Repeats By"), $roptionTypes, array(), NULL);
- $getMonths = CRM_Core_SelectValues::getNumericOptions(1, 31);
- $form->add('select', 'limit_to', '', $getMonths);
+ $form->addRadio('repeats_by', ts("Repeats by"), $roptionTypes, array('required' => TRUE), NULL);
+ $form->add('select', 'limit_to', '', CRM_Core_SelectValues::getNumericOptions(1, 31));
$dayOfTheWeekNo = array(
'first' => ts('First'),
'second' => ts('Second'),
'1' => ts('After'),
'2' => ts('On'),
);
- $form->addRadio('ends', ts("Ends"), $eoptionTypes, array(), NULL);
- $form->add('text', 'start_action_offset', '', array('size' => 3, 'maxlength' => 2));
+ $form->addRadio('ends', ts("Ends"), $eoptionTypes, array('class' => 'required'), NULL);
+ $form->add('select', 'start_action_offset', NULL, CRM_Core_SelectValues::getNumericOptions(1, 30), FALSE);
$form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
$form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
$form->add('text', 'exclude_date_list', ts('Exclude Dates'), array(
+--------------------------------------------------------------------+\r
*}\r
\r
-<div class="crm-core-form-recurringentity-block crm-accordion-wrapper" id="recurring-entity-block">\r
+<div class="crm-core-form-recurringentity-block crm-accordion-wrapper{if $recurringFormIsEmbedded && !$scheduleReminderId} collapsed{/if}" id="recurring-entity-block">\r
<div class="crm-accordion-header">\r
{ts 1=$recurringEntityType}Repeat %1{/ts}\r
</div>\r
<div class="crm-accordion-body">\r
- <div class="crm-submit-buttons">\r
- {include file="CRM/common/formButtons.tpl" location="top"}\r
- </div>\r
+ {if !$recurringFormIsEmbedded}\r
+ <div class="crm-submit-buttons">\r
+ {include file="CRM/common/formButtons.tpl" location="top"}\r
+ </div>\r
+ {/if}\r
<table class="form-layout-compressed">\r
<tr class="crm-core-form-recurringentity-block-repetition_start_date" id="tr-repetition_start_date">\r
<td class="label">{$form.repetition_start_date.label}</td>\r
</td>\r
</tr>\r
<tr class="crm-core-form-recurringentity-block-ends">\r
- <td class="label">{$form.ends.label} <span class="crm-marker" title="This field is required.">*</span> {help id="id-ends-after" entityType=$recurringEntityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
+ <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
<td>{$form.ends.1.html} {$form.start_action_offset.html} {ts}occurrences{/ts}</td>\r
</tr>\r
<tr class="crm-core-form-recurringentity-block-absolute_date">\r
<td>{$form.exclude_date_list.html}</td>\r
</tr>\r
</table>\r
- <div class="crm-submit-buttons">\r
- {include file="CRM/common/formButtons.tpl" location="bottom"}\r
- </div>\r
+ {if !$recurringFormIsEmbedded}\r
+ <div class="crm-submit-buttons">\r
+ {include file="CRM/common/formButtons.tpl" location="bottom"}\r
+ </div>\r
+ {/if}\r
</div>\r
</div>\r
{literal}\r
CRM.$(function($) {\r
var $form = $('form.{/literal}{$form.formClass}{literal}');\r
\r
- $('#repetition_start_date_display').closest("tr").hide();\r
- /****** On load "Repeats By" and "Repeats On" blocks should be hidden if dropdown value is not week or month****** (Edit Mode)***/\r
- switch ($('#repetition_frequency_unit').val()) {\r
- case 'week':\r
- $('.crm-core-form-recurringentity-block-start_action_condition').show();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
- break;\r
- case 'month':\r
- $('.crm-core-form-recurringentity-block-repeats_by td').show();\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
- break;\r
- default:\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
- break;\r
- }\r
-\r
- /***********On Load Set Ends Value (Edit Mode) **********/\r
- switch ($('input:radio[name=ends]:checked').val()) {\r
- case '1':\r
- $('#start_action_offset').prop('disabled', false);\r
- $('#repeat_absolute_date_display').prop('disabled', true).val('');\r
- break;\r
- case '2':\r
- $('#repeat_absolute_date_display').prop('disabled', false);\r
- $('#start_action_offset').prop('disabled', true).val('');\r
- break;\r
- default:\r
- $('#start_action_offset').prop('disabled', true);\r
- $('#repeat_absolute_date_display').prop('disabled', true);\r
- break;\r
- }\r
+ // Prevent html5 errors\r
+ $form.attr('novalidate', 'novalidate');\r
\r
- /******On Load set Repeats by section******************/\r
- switch ($('input:radio[name=repeats_by]:checked').val()) {\r
- case '1':\r
- $('#limit_to').prop('disabled', false);\r
- $('#entity_status_1, #entity_status_2').prop('disabled', true);\r
- break;\r
- case '2':\r
- $('#entity_status_1, #entity_status_2').prop('disabled', false);\r
- $('#limit_to').prop('disabled', true);\r
- break;\r
- default:\r
- //Just in-case block shows up, disable it\r
- $('#limit_to, #entity_status_1, #entity_status_2').prop('disabled', true);\r
- break;\r
- }\r
-\r
- $('#repetition_frequency_unit').change(function () {\r
+ function changeFrequencyUnit() {\r
switch ($(this).val()) {\r
- case 'hour':\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
- break;\r
- case 'day':\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
- break;\r
case 'week':\r
//Show "Repeats On" block when week is selected\r
- $('.crm-core-form-recurringentity-block-start_action_condition').show();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
+ $('.crm-core-form-recurringentity-block-start_action_condition', $form).show();\r
+ $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r
break;\r
case 'month':\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
//Show "Repeats By" block when month is selected\r
- $('.crm-core-form-recurringentity-block-repeats_by td').show();\r
- break;\r
- case 'year':\r
- $('.crm-core-form-recurringentity-block-start_action_condition').hide();\r
- $('.crm-core-form-recurringentity-block-repeats_by td').hide();\r
- break;\r
- }\r
- });\r
-\r
- // For "Ends" block\r
- $('input:radio[name=ends]').click(function() {\r
- switch ($(this).val()) {\r
- case '1':\r
- $('#start_action_offset').prop('disabled', false);\r
- $('#repeat_absolute_date_display').val('');\r
- break;\r
- case '2':\r
- $('#repeat_absolute_date_display').prop('disabled', false);\r
- $('#start_action_offset').val('');\r
+ $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r
+ $('.crm-core-form-recurringentity-block-repeats_by td', $form).show();\r
break;\r
default:\r
- $('#repeat_absolute_date_display').prop('disabled', true);\r
- break;\r
+ $('.crm-core-form-recurringentity-block-start_action_condition', $form).hide();\r
+ $('.crm-core-form-recurringentity-block-repeats_by td', $form).hide();\r
}\r
- });\r
+ }\r
+ $('#repetition_frequency_unit', $form).each(changeFrequencyUnit).change(changeFrequencyUnit);\r
\r
- //For "Repeats By" block\r
- $('input:radio[name=repeats_by]').click(function() {\r
- $('#limit_to').prop('disabled', $(this).val() != 1);\r
- $('#entity_status_1, #entity_status_2').prop('disabled', $(this).val() != 2);\r
- });\r
+ function disableUnselected() {\r
+ $('input:radio[name=ends], input[name=repeats_by]', $form).not(':checked').siblings(':input').prop('disabled', true);\r
+ }\r
+ disableUnselected();\r
\r
- $form.submit(function() {\r
- //Check form for values submitted\r
- if ($('input[name=ends]:checked').val() == 1) {\r
- if ($('#start_action_offset').val() == "") {\r
- $('#start_action_offset').crmError();\r
- return false;\r
- }\r
- } else if ($('input[name=ends]:checked').val() == 2) {\r
- if ($('#repeat_absolute_date_display').val() == "") {\r
- $('#repeat_absolute_date_display').crmError();\r
- return false;\r
- }\r
- }\r
+ $('input:radio[name=ends], input[name=repeats_by]', $form).click(function() {\r
+ $(this).siblings(':input').prop('disabled', false).filter(':visible').addClass('required').focus();\r
+ disableUnselected();\r
});\r
\r
+ function validate() {\r
+ var valid = $(':input', '#recurring-entity-block').valid(),\r
+ modified = CRM.utils.initialValueChanged('#recurring-entity-block');\r
+ $('#allowRepeatConfigToSubmit', $form).val(valid && modified ? '1' : '0');\r
+ return valid;\r
+ }\r
+\r
function getDisplayDate(date) {\r
return $.datepicker.formatDate(CRM.config.dateInputFormat, $.datepicker.parseDate('yy-mm-dd', date));\r
}\r
\r
// Combine select2 and datepicker into a multi-select-date widget\r
- $('#exclude_date_list').crmSelect2({\r
+ $('#exclude_date_list', $form).crmSelect2({\r
multiple: true,\r
data: [],\r
initSelection: function(element, callback) {\r
callback(values);\r
}\r
})\r
- // Prevent select2 from opening and show a datepicker instead\r
.on('select2-opening', function(e) {\r
var $el = $(this);\r
+ // Prevent select2 from opening and show a datepicker instead\r
e.preventDefault();\r
$('.select2-search-field input', $el.select2('container'))\r
- .datepicker({dateFormat: CRM.config.dateInputFormat})\r
+ .datepicker()\r
.datepicker('show')\r
.off('.crmDate')\r
.on('change.crmDate', function() {\r
//If there are changes in repeat configuration, enable save button\r
//Dialog for preview repeat Configuration dates\r
function previewDialog() {\r
- $('#allowRepeatConfigToSubmit').val(CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block') ? '1' : '0');\r
var payload = $form.serialize() + '&entity_table={/literal}{$entityTable}{literal}&entity_id={/literal}{$currentEntityId}{literal}',\r
settings = CRM.utils.adjustDialogDefaults({\r
+ width: '50%',\r
url: CRM.url("civicrm/recurringentity/preview", payload)\r
});\r
CRM.confirm(settings)\r
}\r
\r
$('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click(function (e) {\r
- previewDialog();\r
+ if (validate()) {\r
+ previewDialog();\r
+ }\r
e.preventDefault();\r
});\r
\r
- $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function (e) {\r
- if (CRM.utils.initialValueChanged('.crm-core-form-recurringentity-block')) {\r
+ $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click(function (e) {\r
+ if (CRM.utils.initialValueChanged('#recurring-entity-block')) {\r
e.preventDefault();\r
- previewDialog();\r
+ if (validate()) {\r
+ previewDialog();\r
+ }\r
}\r
});\r
\r