Skip to content

Commit

Permalink
MDL-36404 gradingform_rubric: Accessibility fixes rubric grading
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Jan 18, 2016
1 parent e8d5100 commit e9088e2
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 45 deletions.
4 changes: 2 additions & 2 deletions grade/grading/form/rubric/edit_form.php
Expand Up @@ -50,8 +50,8 @@ public function definition() {
$form->setType('returnurl', PARAM_LOCALURL);

// name
$form->addElement('text', 'name', get_string('name', 'gradingform_rubric'), array('size'=>52));
$form->addRule('name', get_string('required'), 'required');
$form->addElement('text', 'name', get_string('name', 'gradingform_rubric'), array('size' => 52, 'aria-required' => 'true'));
$form->addRule('name', get_string('required'), 'required', null, 'client');
$form->setType('name', PARAM_TEXT);

// description
Expand Down
11 changes: 11 additions & 0 deletions grade/grading/form/rubric/js/rubric.js
Expand Up @@ -5,6 +5,10 @@ M.gradingform_rubric = {};
*/
M.gradingform_rubric.init = function(Y, options) {
Y.on('click', M.gradingform_rubric.levelclick, '#rubric-'+options.name+' .level', null, Y, options.name);
// Capture also space and enter keypress.
Y.on('key', M.gradingform_rubric.levelclick, '#rubric-' + options.name + ' .level', 'space', Y, options.name);
Y.on('key', M.gradingform_rubric.levelclick, '#rubric-' + options.name + ' .level', 'enter', Y, options.name);

Y.all('#rubric-'+options.name+' .radio').setStyle('display', 'none')
Y.all('#rubric-'+options.name+' .level').each(function (node) {
if (node.one('input[type=radio]').get('checked')) {
Expand All @@ -19,12 +23,19 @@ M.gradingform_rubric.levelclick = function(e, Y, name) {
if (!el) return
e.preventDefault();
el.siblings().removeClass('checked');

// Set aria-checked attribute for siblings to false.
el.siblings().setAttribute('aria-checked', 'false');
chb = el.one('input[type=radio]')
if (!chb.get('checked')) {
chb.set('checked', true)
el.addClass('checked')
// Set aria-checked attribute to true if checked.
el.setAttribute('aria-checked', 'true');
} else {
el.removeClass('checked');
// Set aria-checked attribute to false if unchecked.
el.setAttribute('aria-checked', 'false');
el.get('parentNode').all('input[type=radio]').set('checked', false)
}
}
28 changes: 21 additions & 7 deletions grade/grading/form/rubric/js/rubriceditor.js
Expand Up @@ -143,9 +143,11 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
elements_str = '#rubric-'+name+' .criterion'
}
// prepare the id of the next inserted level or criterion
var newlevid = 0;
var newid = 0;
if (action == 'addcriterion' || action == 'addlevel' || action == 'duplicate' ) {
var newid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .criterion')
var newlevid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .level')
newid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .criterion');
newlevid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .level');
}
var dialog_options = {
'scope' : this,
Expand All @@ -164,22 +166,34 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
for (levidx;levidx<3;levidx++) levelsscores[levidx] = parseFloat(levelsscores[levidx-1])+1
var levelsstr = '';
for (levidx=0;levidx<levelsscores.length;levidx++) {
levelsstr += M.gradingform_rubriceditor.templates[name]['level'].replace(/\{LEVEL-id\}/g, 'NEWID'+(newlevid+levidx)).replace(/\{LEVEL-score\}/g, levelsscores[levidx])
levelsstr += M.gradingform_rubriceditor.templates[name].level.
replace(/\{LEVEL-id\}/g, 'NEWID'+(newlevid+levidx)).
replace(/\{LEVEL-score\}/g, levelsscores[levidx]).
replace(/\{LEVEL-index\}/g, levidx + 1);
}
var newcriterion = M.gradingform_rubriceditor.templates[name]['criterion'].replace(/\{LEVELS\}/, levelsstr)
parentel.append(newcriterion.replace(/\{CRITERION-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, ''))
M.gradingform_rubriceditor.assignclasses('#rubric-'+name+' #'+name+'-criteria-NEWID'+newid+'-levels .level')
M.gradingform_rubriceditor.addhandlers();
M.gradingform_rubriceditor.disablealleditors()
M.gradingform_rubriceditor.assignclasses(elements_str)
M.gradingform_rubriceditor.editmode(Y.one('#rubric-'+name+' #'+name+'-criteria-NEWID'+newid+'-description'),true)
M.gradingform_rubriceditor.editmode(
Y.one('#rubric-' + name + ' #' + name + '-criteria-NEWID' + newid + '-description-cell'), true
);
} else if (chunks.length == 5 && action == 'addlevel') {
// ADD NEW LEVEL
var newscore = 0;
parent = Y.one('#'+name+'-criteria-'+chunks[2]+'-levels')
parent.all('.level').each(function (node) { newscore = Math.max(newscore, parseFloat(node.one('.score input[type=text]').get('value'))+1) })
var levelIndex = 1;
parent.all('.level').each(function (node) {
newscore = Math.max(newscore, parseFloat(node.one('.score input[type=text]').get('value')) + 1);
levelIndex++;
});
var newlevel = M.gradingform_rubriceditor.templates[name]['level'].
replace(/\{CRITERION-id\}/g, chunks[2]).replace(/\{LEVEL-id\}/g, 'NEWID'+newlevid).replace(/\{LEVEL-score\}/g, newscore).replace(/\{.+?\}/g, '')
replace(/\{CRITERION-id\}/g, chunks[2]).replace(/\{LEVEL-id\}/g, 'NEWID'+newlevid).
replace(/\{LEVEL-score\}/g, newscore).
replace(/\{LEVEL-index\}/g, levelIndex).
replace(/\{.+?\}/g, '');
parent.append(newlevel)
M.gradingform_rubriceditor.addhandlers();
M.gradingform_rubriceditor.disablealleditors()
Expand Down Expand Up @@ -238,7 +252,7 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
M.gradingform_rubriceditor.addhandlers();
M.gradingform_rubriceditor.disablealleditors();
M.gradingform_rubriceditor.assignclasses(elements_str);
M.gradingform_rubriceditor.editmode(Y.one('#rubric-'+name+' #'+name+'-criteria-NEWID'+newid+'-description'),true);
M.gradingform_rubriceditor.editmode(Y.one('#rubric-'+name+' #'+name+'-criteria-NEWID'+newid+'-description-cell'),true);
} else if (chunks.length == 6 && action == 'delete') {
// DELETE LEVEL
if (confirmed) {
Expand Down
8 changes: 7 additions & 1 deletion grade/grading/form/rubric/lang/en/gradingform_rubric.php
Expand Up @@ -29,12 +29,14 @@
$string['backtoediting'] = 'Back to editing';
$string['confirmdeletecriterion'] = 'Are you sure you want to delete this criterion?';
$string['confirmdeletelevel'] = 'Are you sure you want to delete this level?';
$string['criterion'] = 'Criterion {$a}';
$string['criterionaddlevel'] = 'Add level';
$string['criteriondelete'] = 'Delete criterion';
$string['criterionduplicate'] = 'Duplicate criterion';
$string['criterionempty'] = 'Click to edit criterion';
$string['criterionmovedown'] = 'Move down';
$string['criterionmoveup'] = 'Move up';
$string['criterionremark'] = 'Remark for criterion {$a->description}: {$a->remark}';
$string['definerubric'] = 'Define rubric';
$string['description'] = 'Description';
$string['enableremarks'] = 'Allow grader to add text remarks for each criterion';
Expand All @@ -45,8 +47,11 @@
$string['err_scoreformat'] = 'Number of points for each level must be a valid non-negative number';
$string['err_totalscore'] = 'Maximum number of points possible when graded by the rubric must be more than zero';
$string['gradingof'] = '{$a} grading';
$string['leveldelete'] = 'Delete level';
$string['level'] = 'Level {$a->definition}, {$a->score} points.';
$string['leveldelete'] = 'Delete level {$a}';
$string['leveldefinition'] = 'Level {$a} definition';
$string['levelempty'] = 'Click to edit level';
$string['levelsgroup'] = 'Levels group';
$string['name'] = 'Name';
$string['needregrademessage'] = 'The rubric definition was changed after this student had been graded. The student can not see this rubric until you check the rubric and update the grade.';
$string['pluginname'] = 'Rubric';
Expand All @@ -68,6 +73,7 @@
$string['save'] = 'Save';
$string['saverubric'] = 'Save rubric and make it ready';
$string['saverubricdraft'] = 'Save as draft';
$string['scoreinputforlevel'] = 'Score input for level {$a}';
$string['scorepostfix'] = '{$a}points';
$string['showdescriptionstudent'] = 'Display rubric description to those being graded';
$string['showdescriptionteacher'] = 'Display rubric description during evaluation';
Expand Down
3 changes: 2 additions & 1 deletion grade/grading/form/rubric/lib.php
Expand Up @@ -927,7 +927,8 @@ public function render_grading_element($page, $gradingformelement) {
}
$currentinstance = $this->get_current_instance();
if ($currentinstance && $currentinstance->get_status() == gradingform_instance::INSTANCE_STATUS_NEEDUPDATE) {
$html .= html_writer::tag('div', get_string('needregrademessage', 'gradingform_rubric'), array('class' => 'gradingform_rubric-regrade'));
$html .= html_writer::div(get_string('needregrademessage', 'gradingform_rubric'), 'gradingform_rubric-regrade',
array('role' => 'alert'));
}
$haschanges = false;
if ($currentinstance) {
Expand Down

0 comments on commit e9088e2

Please sign in to comment.