diff --git a/mod/assign/classes/form/grading_options_temp_form.php b/mod/assign/classes/form/grading_options_temp_form.php index 98dc3d6758b..a94d4b977fd 100644 --- a/mod/assign/classes/form/grading_options_temp_form.php +++ b/mod/assign/classes/form/grading_options_temp_form.php @@ -67,12 +67,6 @@ class grading_options_temp_form extends \moodleform { $markingfilter = get_string('markerfilter', 'assign'); $mform->addElement('select', 'markerfilter', $markingfilter, $instance['markingallocationopt']); } - // Quickgrading. - if ($instance['showquickgrading']) { - $mform->addElement('checkbox', 'quickgrading', get_string('quickgrading', 'assign')); - $mform->addHelpButton('quickgrading', 'quickgrading', 'assign'); - $mform->setDefault('quickgrading', $instance['quickgrading']); - } // Show active/suspended user option. if ($instance['showonlyactiveenrolopt']) { diff --git a/mod/assign/classes/output/grading_actionmenu.php b/mod/assign/classes/output/grading_actionmenu.php index 46d202988bd..4c5aa1e8f74 100644 --- a/mod/assign/classes/output/grading_actionmenu.php +++ b/mod/assign/classes/output/grading_actionmenu.php @@ -123,7 +123,6 @@ class grading_actionmenu implements templatable, renderable { 'group' => 0, 'status' => '', 'workflowfilter' => '', - 'sesskey' => sesskey(), ]); $data['pagereset'] = $url->out(false); } @@ -143,6 +142,26 @@ class grading_actionmenu implements templatable, renderable { $data['graderurl'] = $url->out(false); } + $gradingmanager = get_grading_manager($this->assign->get_context(), 'mod_assign', 'submissions'); + $controller = $gradingmanager->get_active_controller(); + $showquickgrading = empty($controller) && $this->assign->can_grade(); + if ($showquickgrading) { + $quickgradingbaseurl = new moodle_url('/mod/assign/view.php', [ + 'id' => $this->assign->get_course_module()->id, + 'action' => 'grading', + ]); + if ($userid) { + $quickgradingbaseurl->param('userid', $userid); + } else if ($usersearch) { + $quickgradingbaseurl->param('search', $usersearch); + } + + $data['quickgrading'] = [ + 'baseurl' => $quickgradingbaseurl->out(false), + 'enabled' => get_user_preferences('assign_quickgrading', false), + ]; + } + $actions = $this->get_actions(); if ($actions) { $menu = new \action_menu(); @@ -223,14 +242,13 @@ class grading_actionmenu implements templatable, renderable { $groupedfilters = $this->assign->get_filters(true); foreach ($groupedfilters as $group => $filters) { foreach ($filters as $filter) { - if ($filter['key'] === 'none') { + if ($filter['key'] === ASSIGN_FILTER_NONE) { // The 'none' filter is not a real filter. $filter['key'] = ''; } $url = new moodle_url('/mod/assign/view.php', [ 'id' => $this->assign->get_course_module()->id, 'action' => 'grading', - 'sesskey' => sesskey(), 'status' => $filter['key'], ]); $statusmenu[$url->out(false)] = $filter['name']; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index e99c63b46a9..95125ae84a8 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -4486,8 +4486,17 @@ class assign { require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php'); $submittedfilter = optional_param('status', null, PARAM_ALPHA); - if (isset($submittedfilter) && confirm_sesskey()) { - set_user_preference('assign_filter', $submittedfilter); + if (isset($submittedfilter)) { + $validfilters = array_column($this->get_filters(), 'key'); + $validfilters = array_diff($validfilters, [ASSIGN_FILTER_NONE]); // The 'none' filter is not a real filter. + if ($submittedfilter === '' || in_array($submittedfilter, $validfilters)) { + set_user_preference('assign_filter', $submittedfilter); + } + } + + $submittedquickgrading = optional_param('quickgrading', null, PARAM_BOOL); + if (isset($submittedquickgrading)) { + set_user_preference('assign_quickgrading', $submittedquickgrading); } $o = ''; @@ -4535,17 +4544,17 @@ class assign { $markingworkflowoptions = $this->get_marking_workflow_filters(); // Print options for changing the filter and changing the number of results per page. - $gradingoptionsformparams = array('cm'=>$cmid, - 'contextid'=>$this->context->id, - 'userid'=>$USER->id, - 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), - 'showquickgrading'=>$showquickgrading, - 'quickgrading'=>$quickgrading, - 'markingworkflowopt'=>$markingworkflowoptions, - 'markingallocationopt'=>$markingallocationoptions, - 'showonlyactiveenrolopt'=>$showonlyactiveenrolopt, - 'showonlyactiveenrol' => $this->show_only_active_users(), - 'downloadasfolders' => $downloadasfolders); + $gradingoptionsformparams = [ + 'cm' => $cmid, + 'contextid' => $this->context->id, + 'userid' => $USER->id, + 'submissionsenabled' => $this->is_any_submission_plugin_enabled(), + 'markingworkflowopt' => $markingworkflowoptions, + 'markingallocationopt' => $markingallocationoptions, + 'showonlyactiveenrolopt' => $showonlyactiveenrolopt, + 'showonlyactiveenrol' => $this->show_only_active_users(), + 'downloadasfolders' => $downloadasfolders, + ]; $classoptions = array('class'=>'gradingoptionsform'); $gradingoptionsform = new \mod_assign\form\grading_options_temp_form(null, @@ -7378,10 +7387,6 @@ class assign { $this->require_view_grades(); require_sesskey(); - // Is advanced grading enabled? - $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions'); - $controller = $gradingmanager->get_active_controller(); - $showquickgrading = empty($controller); if (!is_null($this->context)) { $showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context); } else { @@ -7407,26 +7412,23 @@ class assign { // Get marking states to show in form. $markingworkflowoptions = $this->get_marking_workflow_filters(); - $gradingoptionsparams = array('cm'=>$this->get_course_module()->id, - 'contextid'=>$this->context->id, - 'userid'=>$USER->id, - 'submissionsenabled'=>$this->is_any_submission_plugin_enabled(), - 'showquickgrading'=>$showquickgrading, - 'quickgrading'=>false, - 'markingworkflowopt' => $markingworkflowoptions, - 'markingallocationopt' => $markingallocationoptions, - 'showonlyactiveenrolopt'=>$showonlyactiveenrolopt, - 'showonlyactiveenrol' => $this->show_only_active_users(), - 'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1)); + $gradingoptionsparams = [ + 'cm' => $this->get_course_module()->id, + 'contextid' => $this->context->id, + 'userid' => $USER->id, + 'submissionsenabled' => $this->is_any_submission_plugin_enabled(), + 'markingworkflowopt' => $markingworkflowoptions, + 'markingallocationopt' => $markingallocationoptions, + 'showonlyactiveenrolopt' => $showonlyactiveenrolopt, + 'showonlyactiveenrol' => $this->show_only_active_users(), + 'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1), + ]; $mform = new mod_assign\form\grading_options_temp_form(null, $gradingoptionsparams); if ($formdata = $mform->get_data()) { set_user_preference('assign_perpage', $formdata->perpage); if (isset($formdata->markerfilter)) { set_user_preference('assign_markerfilter', $formdata->markerfilter); } - if ($showquickgrading) { - set_user_preference('assign_quickgrading', isset($formdata->quickgrading)); - } if (isset($formdata->downloadasfolders)) { set_user_preference('assign_downloadasfolders', 1); // Enabled. } else { @@ -9677,7 +9679,7 @@ class assign { // First is always "no filter" option. $filters[0] = [ [ - 'key' => 'none', + 'key' => ASSIGN_FILTER_NONE, 'name' => get_string('filterall', 'assign'), 'active' => ($current == ''), ], diff --git a/mod/assign/module.js b/mod/assign/module.js index 0e9bb676f36..3fa02e73323 100644 --- a/mod/assign/module.js +++ b/mod/assign/module.js @@ -137,12 +137,6 @@ M.mod_assign.init_grading_options = function(Y) { Y.one('form.gradingoptionsform').submit(); }); } - var quickgradingelement = Y.one('#id_quickgrading'); - if (quickgradingelement) { - quickgradingelement.on('change', function(e) { - Y.one('form.gradingoptionsform').submit(); - }); - } var showonlyactiveenrolelement = Y.one('#id_showonlyactiveenrol'); if (showonlyactiveenrolelement) { showonlyactiveenrolelement.on('change', function(e) { diff --git a/mod/assign/templates/grading_actionmenu.mustache b/mod/assign/templates/grading_actionmenu.mustache index fd5c25a1855..53124402b00 100644 --- a/mod/assign/templates/grading_actionmenu.mustache +++ b/mod/assign/templates/grading_actionmenu.mustache @@ -27,6 +27,9 @@ * groupselector - (optional) HTML that outputs the group selector * statusselector - (optional) The data object containing the required properties to render the status selector * extrafiltersdropdown - HTML that outputs the extra filters dropdown + * pagereset - (optional) URL to reset the page + * graderurl - (optional) URL to the grader page + * quickgrading - (optional) Includes the baseurl and enabled properties for the quick grading checkbox * actions - (optional) HTML that outputs the bulk action menu Example context (json): @@ -49,6 +52,11 @@ }, "extrafiltersdropdown": "", "pagereset": "http://moodle.local/mod/assign/view.php?id=2&action=grading&group=0", + "graderurl": "http://moodle.local/mod/assign/view.php?id=2&action=grader", + "quickgrading": { + "baseurl": "http://moodle.local/mod/assign/view.php?id=2&action=grading", + "enabled": true + }, "actions": "
" } @@ -95,14 +103,32 @@ {{/pagereset}} {{#graderurl}} - + {{/graderurl}} -
-{{#actions}} -
{{{actions}}}
-{{/actions}} +
+
+ {{#quickgrading}} + + + {{#js}} + document.querySelector('#quickgrading-{{uniqid}}').addEventListener('change', function(e) { + var url = new URL('{{{baseurl}}}'); + url.searchParams.set('quickgrading', e.target.checked ? 1 : 0); + window.location.href = url; + }); + {{/js}} + {{/quickgrading}} + {{#actions}} + + {{/actions}} +