MDL-43648 course: Allow start /end dates to have times

This commit is contained in:
Stephen Bourget 2017-12-14 19:48:31 -05:00
parent 109aa07648
commit 57422d7158
8 changed files with 32 additions and 17 deletions

View file

@ -1 +1 @@
define(["jquery"],function(a){var b=function(b){var c=a(b.target),d=JSON.parse(c.attr("data-defaultvalue")),e=JSON.parse(c.attr("data-customvalue")),f=c.attr("data-type"),g=c.closest("form"),h=c.attr("name").replace(/\[customize\]$/,"[value]"),i=c.prop("checked")?e:d;"text"===f?g.find('[name="'+h+'"]').val(i):"date_selector"===f&&(g.find('[name="'+h+'[day]"]').val(i.day),g.find('[name="'+h+'[month]"]').val(i.month),g.find('[name="'+h+'[year]"]').val(i.year))},c="input[data-defaultcustom=true]";a("body").on("change",c,b)});
define(["jquery"],function(a){var b=function(b){var c=a(b.target),d=JSON.parse(c.attr("data-defaultvalue")),e=JSON.parse(c.attr("data-customvalue")),f=c.attr("data-type"),g=c.closest("form"),h=c.attr("name").replace(/\[customize\]$/,"[value]"),i=c.prop("checked")?e:d;"text"===f?g.find('[name="'+h+'"]').val(i):"date_selector"===f?(g.find('[name="'+h+'[day]"]').val(i.day),g.find('[name="'+h+'[month]"]').val(i.month),g.find('[name="'+h+'[year]"]').val(i.year)):"date_time_selector"===f&&(g.find('[name="'+h+'[day]"]').val(i.day),g.find('[name="'+h+'[month]"]').val(i.month),g.find('[name="'+h+'[year]"]').val(i.year),g.find('[name="'+h+'[hour]"]').val(i.hour),g.find('[name="'+h+'[minute]"]').val(i.minute))},c="input[data-defaultcustom=true]";a("body").on("change",c,b)});

View file

@ -39,6 +39,12 @@ define(['jquery'], function($) {
form.find('[name="' + elementName + '[day]"]').val(newvalue.day);
form.find('[name="' + elementName + '[month]"]').val(newvalue.month);
form.find('[name="' + elementName + '[year]"]').val(newvalue.year);
} else if (type === 'date_time_selector') {
form.find('[name="' + elementName + '[day]"]').val(newvalue.day);
form.find('[name="' + elementName + '[month]"]').val(newvalue.month);
form.find('[name="' + elementName + '[year]"]').val(newvalue.year);
form.find('[name="' + elementName + '[hour]"]').val(newvalue.hour);
form.find('[name="' + elementName + '[minute]"]').val(newvalue.minute);
}
};

View file

@ -84,8 +84,8 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
if (is_array($options)) {
foreach ($options as $name => $value) {
if (array_key_exists($name, $this->_options)) {
if ($name === 'type' && !in_array($value, ['text', 'date_selector'])) {
throw new coding_exception('Only text and date_selector elements are supported in ' . $this->_type);
if ($name === 'type' && !in_array($value, ['text', 'date_selector', 'date_time_selector'])) {
throw new coding_exception('Only text, date_selector, and date_time_selector elements are supported in ' . $this->_type);
}
if ($name === 'optional' && $value) {
throw new coding_exception('Date selector can not be optional in ' . $this->_type);
@ -105,6 +105,8 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$currentdate = $calendartype->timestamp_to_date_array($value, $this->_options['timezone']);
return array(
'minutes' => $currentdate['minutes'],
'hours' => $currentdate['hours'],
'day' => $currentdate['mday'],
'month' => $currentdate['mon'],
'year' => $currentdate['year']);
@ -137,6 +139,9 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
} else if ($this->_options['type'] === 'date_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
} else if ($this->_options['type'] === 'date_time_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
}
$this->_elements[] = $element;
}
@ -184,10 +189,17 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
if ($this->has_customize_switch()) {
if ($this->_options['type'] === 'text') {
$caller->disabledIf($arg[0] . '[value]', $arg[0] . '[customize]', 'notchecked');
} else {
} else if ($this->_options['type'] === 'date_selector') {
$caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
} else {
// Date / Time selector.
$caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][hours]', $arg[0] . '[customize]', 'notchecked');
$caller->disabledIf($arg[0] . '[value][minutes]', $arg[0] . '[customize]', 'notchecked');
}
}
return $rv;