$excludeOptionValues = array();
if (!empty($optionValue)) {
foreach ($optionValue as $key => $val) {
- $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
+ $excludeOptionValues[$val['value']] = CRM_Utils_Date::customFormat($val['value']);
}
self::$_excludeDateInfo = $excludeOptionValues;
}
if (self::$_scheduleReminderDetails->entity_status) {
$defaults['repeats_by'] = 2;
}
+ if (self::$_excludeDateInfo) {
+ $defaults['exclude_date_list'] = implode(',', self::$_excludeDateInfo);
+ }
}
return $defaults;
}
/**
* Build form.
*
- * @param $form
+ * @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
if (self::$_entityTable) {
$form->add('text', 'start_action_offset', ts(''), array('size' => 3, 'maxlength' => 2));
$form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
$form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
- $form->addDate('exclude_date', ts('Exclude Date(s)'), FALSE);
- $select = $form->add('select', 'exclude_date_list', ts(''), self::$_excludeDateInfo, FALSE, array(
- 'style' => 'width:150px;',
- 'size' => 4,
+ $form->add('text', 'exclude_date_list', ts('Exclude Dates'), array(
+ 'class' => 'twenty',
));
- $select->setMultiple(TRUE);
- $form->addElement('button', 'add_to_exclude_list', '>>', 'onClick="addToExcludeList(document.getElementById(\'exclude_date\').value);"');
- $form->addElement('button', 'remove_from_exclude_list', '<<', 'onClick="removeFromExcludeList(\'exclude_date_list\')"');
- $form->addElement('hidden', 'copyExcludeDates', '', array('id' => 'copyExcludeDates'));
$form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit'));
$form->addButtons(array(
array(
//exclude dates
$excludeDateList = array();
- if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
+ if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
//Since we get comma separated values lets get them in array
- $excludeDates = array();
- $excludeDates = explode(",", $params['copyExcludeDates']);
+ $excludeDates = explode(",", $params['exclude_date_list']);
//Check if there exists any values for this option group
$optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
</td>\r
</tr>\r
<tr class="crm-core-form-recurringentity-block-exclude_date">\r
- <td class="label">{$form.exclude_date.label} {help id="id-exclude-date" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
- <td> {include file="CRM/common/jcalendar.tpl" elementName=exclude_date}\r
- {$form.add_to_exclude_list.html} {$form.remove_from_exclude_list.html}\r
- {$form.exclude_date_list.html}\r
- </td>\r
+ <td class="label">{$form.exclude_date_list.label} {help id="id-exclude-date" entityType=$entityType file="CRM/Core/Form/RecurringEntity.hlp"}</td>\r
+ <td>{$form.exclude_date_list.html}</td>\r
</tr>\r
<tr>\r
<td class="label bold">{ts}Summary:{/ts}</td>\r
\r
//Select all options in selectbox before submitting\r
$(this).submit(function() {\r
- $('#exclude_date_list option').attr('selected',true);\r
-\r
//Check form for values submitted\r
if ($('input[name=ends]:checked').val() == 1) {\r
if ($('#start_action_offset').val() == "") {\r
return false;\r
}\r
}\r
-\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
+ multiple: true,\r
+ data: [],\r
+ initSelection: function(element, callback) {\r
+ var values = [];\r
+ $.each($(element).val().split(','), function(k, v) {\r
+ values.push({\r
+ text: getDisplayDate(v),\r
+ id: v\r
+ });\r
+ });\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
+ e.preventDefault();\r
+ $('.select2-search-field input', $el.select2('container'))\r
+ .datepicker({dateFormat: CRM.config.dateInputFormat})\r
+ .datepicker('show')\r
+ .off('.crmDate')\r
+ .on('change.crmDate', function() {\r
+ if ($(this).val()) {\r
+ var date = $(this).datepicker('getDate'),\r
+ data = $el.select2('data') || [];\r
+ data.push({\r
+ text: $.datepicker.formatDate(CRM.config.dateInputFormat, date),\r
+ id: $.datepicker.formatDate('yy-mm-dd', date)\r
+ });\r
+ $el.select2('data', data);\r
+ }\r
+ });\r
+ });\r
+\r
//Detect changes in Repeat configuration field\r
var unsavedChanges = false;\r
$('div.crm-core-form-recurringentity-block').on('change', function() {\r
//Dialog for preview repeat Configuration dates\r
$('#preview-dialog').dialog({ autoOpen: false });\r
function previewDialog() {\r
- $('#exclude_date_list option').attr('selected', true);\r
- //Copy exclude dates\r
- var dateTxt=[];\r
- $('#exclude_date_list option:selected').each(function() {\r
- dateTxt.push($(this).text());\r
- });\r
- var completeDateText = dateTxt.join(',');\r
- $('#copyExcludeDates').val(completeDateText);\r
-\r
$('#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>');\r
$('#preview-dialog').dialog('open');\r
$('#preview-dialog').dialog({\r
\r
});\r
\r
- //Exclude list function\r
- function addToExcludeList(val) {\r
- if (val !== "") {\r
- var exists = false;\r
- for(var i = 0, opts = document.getElementById('exclude_date_list').options; i < opts.length; ++i) {\r
- if (opts[i].text == val) {\r
- exists = true;\r
- break;\r
- }\r
- }\r
- if (exists == false) {\r
- cj('#exclude_date_list').append('<option>'+val+'</option>');\r
- }\r
- }\r
- }\r
-\r
- function removeFromExcludeList(sourceID) {\r
- var src = document.getElementById(sourceID);\r
- for(var count= src.options.length-1; count >= 0; count--) {\r
- if (src.options[count].selected == true) {\r
- try{\r
- src.remove(count, null);\r
- }catch(error) {\r
- src.remove(count);\r
- }\r
- }\r
- }\r
- }\r
</script>\r
{/literal}\r
{*Hide Summary*}\r