mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
Merge branch 'MDL-59921-master' of git://github.com/lameze/moodle
This commit is contained in:
commit
e34196d6ef
2
calendar/amd/build/event_form.min.js
vendored
2
calendar/amd/build/event_form.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery"],function(a){var b={EVENT_GROUP_COURSE_ID:'[name="groupcourseid"]',EVENT_GROUP_ID:'[name="groupid"]',SELECT_OPTION:"option"},c=function(c){c.find(b.EVENT_GROUP_ID).find(b.SELECT_OPTION).each(function(b,c){c=a(c);var d=c.attr("value"),e=d.split("-"),f=e[0];c.attr("data-course-id",f)})},d=function(c){var d=c.find(b.EVENT_GROUP_COURSE_ID),e=c.find(b.EVENT_GROUP_ID),f=e.find(b.SELECT_OPTION),g=function(){var b=d.val(),c=null;f.each(function(d,e){e=a(e),e.attr("data-course-id")==b?(e.removeClass("hidden"),e.prop("disabled",!1),(null===c||e.attr("selected"))&&(c=d)):(e.addClass("hidden"),e.prop("disabled",!0))}),e.prop("selectedIndex",c)};d.on("change",g),g()},e=function(b){var e=a("#"+b);c(e),d(e)};return{init:e}});
|
||||
define(["jquery"],function(a){var b={EVENT_GROUP_COURSE_ID:'[name="groupcourseid"]',EVENT_GROUP_ID:'[name="groupid"]',SELECT_OPTION:"option"},c=function(c){c.find(b.EVENT_GROUP_ID).find(b.SELECT_OPTION).each(function(b,c){c=a(c);var d=c.attr("value"),e=d.split("-"),f=e[0];c.attr("data-course-id",f)})},d=function(c){var d=c.find(b.EVENT_GROUP_COURSE_ID),e=c.find(b.EVENT_GROUP_ID),f=e.find(b.SELECT_OPTION),g=function(){var b=d.val(),c=null,g=!1;f.each(function(d,e){e=a(e),e.attr("data-course-id")==b?(e.removeClass("hidden"),e.prop("disabled",!1),g=!0,(null===c||e.attr("selected"))&&(c=d)):(e.addClass("hidden"),e.prop("disabled",!0))}),g?e.prop("disabled",!1):e.prop("disabled",!0),e.prop("selectedIndex",c)};d.on("change",g),g()},e=function(b){var e=a("#"+b);c(e),d(e)};return{init:e}});
|
@ -74,14 +74,14 @@ define(['jquery'], function($) {
|
||||
var filterGroupSelectOptions = function() {
|
||||
var selectedCourseId = courseGroupSelect.val();
|
||||
var selectedIndex = null;
|
||||
|
||||
var hasGroups = false;
|
||||
groupSelectOptions.each(function(index, element) {
|
||||
element = $(element);
|
||||
|
||||
if (element.attr('data-course-id') == selectedCourseId) {
|
||||
element.removeClass('hidden');
|
||||
element.prop('disabled', false);
|
||||
|
||||
hasGroups = true;
|
||||
if (selectedIndex === null || element.attr('selected')) {
|
||||
selectedIndex = index;
|
||||
}
|
||||
@ -91,6 +91,12 @@ define(['jquery'], function($) {
|
||||
}
|
||||
});
|
||||
|
||||
if (hasGroups) {
|
||||
groupSelect.prop('disabled', false);
|
||||
} else {
|
||||
groupSelect.prop('disabled', true);
|
||||
}
|
||||
|
||||
groupSelect.prop('selectedIndex', selectedIndex);
|
||||
};
|
||||
|
||||
|
@ -132,6 +132,14 @@ class create extends \moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
if ($eventtype == 'course' && empty($data['courseid'])) {
|
||||
$errors['courseid'] = get_string('selectacourse');
|
||||
}
|
||||
|
||||
if ($eventtype == 'group' && empty($data['groupcourseid'])) {
|
||||
$errors['groupcourseid'] = get_string('selectacourse');
|
||||
}
|
||||
|
||||
if ($data['duration'] == 1 && $data['timestart'] > $data['timedurationuntil']) {
|
||||
$errors['durationgroup'] = get_string('invalidtimedurationuntil', 'calendar');
|
||||
} else if ($data['duration'] == 2 && (trim($data['timedurationminutes']) == '' || $data['timedurationminutes'] < 1)) {
|
||||
@ -237,24 +245,16 @@ class create extends \moodleform {
|
||||
}
|
||||
|
||||
if (isset($eventtypes['course'])) {
|
||||
$courseoptions = [];
|
||||
foreach ($eventtypes['course'] as $course) {
|
||||
$courseoptions[$course->id] = format_string($course->fullname, true,
|
||||
['context' => \context_course::instance($course->id)]);
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'courseid', get_string('course'), $courseoptions);
|
||||
$mform->addElement('course', 'courseid', get_string('course'), ['limittoenrolled' => true]);
|
||||
$mform->hideIf('courseid', 'eventtype', 'noteq', 'course');
|
||||
}
|
||||
|
||||
if (isset($eventtypes['group'])) {
|
||||
$courseoptions = [];
|
||||
foreach ($eventtypes['groupcourses'] as $course) {
|
||||
$courseoptions[$course->id] = format_string($course->fullname, true,
|
||||
['context' => \context_course::instance($course->id)]);
|
||||
}
|
||||
// Exclude courses without group.
|
||||
$excludedcourses = array_diff(array_keys($eventtypes['course']), array_keys($eventtypes['groupcourses']));
|
||||
|
||||
$mform->addElement('select', 'groupcourseid', get_string('course'), $courseoptions);
|
||||
$options = ['limittoenrolled' => true, 'exclude' => $excludedcourses];
|
||||
$mform->addElement('course', 'groupcourseid', get_string('course'), $options);
|
||||
$mform->hideIf('groupcourseid', 'eventtype', 'noteq', 'group');
|
||||
|
||||
$groupoptions = [];
|
||||
@ -268,6 +268,7 @@ class create extends \moodleform {
|
||||
|
||||
$mform->addElement('select', 'groupid', get_string('group'), $groupoptions);
|
||||
$mform->hideIf('groupid', 'eventtype', 'noteq', 'group');
|
||||
$mform->disabledIf('groupid', 'groupcourseid', 'eq', '');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,10 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||
$data->groupid = "{$legacyevent->courseid}-{$legacyevent->groupid}";
|
||||
$data->groupcourseid = $legacyevent->courseid;
|
||||
}
|
||||
|
||||
if ($legacyevent->eventtype == 'course') {
|
||||
// Set up the correct value for the to display on the form.
|
||||
$data->courseid = $legacyevent->courseid;
|
||||
}
|
||||
$data->description = [
|
||||
'text' => $data->description,
|
||||
'format' => $data->format
|
||||
@ -87,24 +90,28 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||
|
||||
// Undo the form definition work around to allow us to have two different
|
||||
// course selectors present depending on which event type the user selects.
|
||||
if (isset($data->groupcourseid)) {
|
||||
$properties->courseid = $data->groupcourseid;
|
||||
unset($properties->groupcourseid);
|
||||
}
|
||||
|
||||
// Pull the group id back out of the value. The form saves the value
|
||||
// as "<courseid>-<groupid>" to allow the javascript to work correctly.
|
||||
if (isset($data->groupid)) {
|
||||
list($courseid, $groupid) = explode('-', $data->groupid);
|
||||
$properties->groupid = $groupid;
|
||||
}
|
||||
|
||||
// Default course id if none is set.
|
||||
if (!isset($properties->courseid)) {
|
||||
if ($properties->eventtype === 'site') {
|
||||
$properties->courseid = SITEID;
|
||||
if ($data->eventtype == 'course') {
|
||||
// Default course id if none is set.
|
||||
if (!isset($properties->courseid)) {
|
||||
if ($properties->eventtype === 'site') {
|
||||
$properties->courseid = SITEID;
|
||||
} else {
|
||||
$properties->courseid = 0;
|
||||
}
|
||||
} else {
|
||||
$properties->courseid = 0;
|
||||
$properties->courseid = $data->courseid;
|
||||
}
|
||||
} else if ($data->eventtype == 'group') {
|
||||
if (isset($data->groupcourseid)) {
|
||||
$properties->courseid = $data->groupcourseid;
|
||||
unset($properties->groupcourseid);
|
||||
}
|
||||
|
||||
// Pull the group id back out of the value. The form saves the value
|
||||
// as "<courseid>-<groupid>" to allow the javascript to work correctly.
|
||||
if (isset($data->groupid)) {
|
||||
list($courseid, $groupid) = explode('-', $data->groupid);
|
||||
$properties->groupid = $groupid;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2481,7 +2481,7 @@ function calendar_get_all_allowed_types() {
|
||||
if (!isset($types['course'])) {
|
||||
$types['course'] = [$course];
|
||||
} else {
|
||||
$types['course'][] = $course;
|
||||
$types['course'][$course->id] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2489,7 +2489,7 @@ function calendar_get_all_allowed_types() {
|
||||
if (!isset($types['groupcourses'])) {
|
||||
$types['groupcourses'] = [$course];
|
||||
} else {
|
||||
$types['groupcourses'][] = $course;
|
||||
$types['groupcourses'][$course->id] = $course;
|
||||
}
|
||||
|
||||
if (!isset($types['group'])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user