MDL-59921 calendar: replace selector for groups events

This commit is contained in:
Simey Lameze
2017-10-09 09:51:14 +08:00
parent 4b9c662b2a
commit 86244e9102
5 changed files with 30 additions and 22 deletions
+1 -1
View File
@@ -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}});
+8 -2
View File
@@ -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);
};
@@ -136,6 +136,10 @@ class create extends \moodleform {
$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)) {
@@ -246,13 +250,11 @@ class create extends \moodleform {
}
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 = [];
@@ -266,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', '');
}
}
@@ -101,21 +101,20 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
} else {
$properties->courseid = $data->courseid;
}
}
} else if ($data->eventtype == 'group') {
if (isset($data->groupcourseid)) {
$properties->courseid = $data->groupcourseid;
unset($properties->groupcourseid);
}
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;
}
}
// 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;
}
// Decode the form fields back into valid event property.
$properties->timeduration = $this->get_time_duration_from_form_data($data);
+1 -1
View File
@@ -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'])) {