MDL-50283 rubric: Add duplicate row button

Adds the ability to duplicate a row in a rubric.
This commit is contained in:
Syxton 2015-05-19 08:33:48 -04:00 committed by David Monllao
parent 17abbfba1f
commit e22c8d2ae3
4 changed files with 40 additions and 2 deletions

View File

@ -143,7 +143,7 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
elements_str = '#rubric-'+name+' .criterion' elements_str = '#rubric-'+name+' .criterion'
} }
// prepare the id of the next inserted level or criterion // prepare the id of the next inserted level or criterion
if (action == 'addcriterion' || action == 'addlevel') { if (action == 'addcriterion' || action == 'addlevel' || action == 'duplicate' ) {
var newid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .criterion') var newid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .criterion')
var newlevid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .level') var newlevid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .level')
} }
@ -204,6 +204,41 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
dialog_options['message'] = M.util.get_string('confirmdeletecriterion', 'gradingform_rubric') dialog_options['message'] = M.util.get_string('confirmdeletecriterion', 'gradingform_rubric')
M.util.show_confirm_dialog(e, dialog_options); M.util.show_confirm_dialog(e, dialog_options);
} }
} else if (chunks.length == 4 && action == 'duplicate') {
// DUPLICATE CRITERION
var levelsdef = [], levelsscores = [0], levidx = 1;
var parentel = Y.one('#'+name+'-criteria');
if (parentel.one('>tbody')) { parentel = parentel.one('>tbody'); }
var source = Y.one('#'+name+'-criteria-'+chunks[2]);
if (source.all('.level')) {
var lastcriterion = source.all('.level');
for (levidx=0;levidx<lastcriterion.size();levidx++) {
levelsdef[levidx] = lastcriterion.item(levidx).one('.definition .textvalue').get('innerHTML');
}
for (levidx=0;levidx<lastcriterion.size();levidx++) {
levelsscores[levidx] = lastcriterion.item(levidx).one('.score input[type=text]').get('value');
}
}
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])
.replace(/\{LEVEL-definition\}/g, Y.Escape.html(levelsdef[levidx]));
}
var description = source.one('.description .textvalue');
var newcriterion = M.gradingform_rubriceditor.templates[name]['criterion']
.replace(/\{LEVELS\}/, levelsstr)
.replace(/\{CRITERION-description\}/, Y.Escape.html(description.get('innerHTML')));
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);
} else if (chunks.length == 6 && action == 'delete') { } else if (chunks.length == 6 && action == 'delete') {
// DELETE LEVEL // DELETE LEVEL
if (confirmed) { if (confirmed) {

View File

@ -31,6 +31,7 @@ $string['confirmdeletecriterion'] = 'Are you sure you want to delete this criter
$string['confirmdeletelevel'] = 'Are you sure you want to delete this level?'; $string['confirmdeletelevel'] = 'Are you sure you want to delete this level?';
$string['criterionaddlevel'] = 'Add level'; $string['criterionaddlevel'] = 'Add level';
$string['criteriondelete'] = 'Delete criterion'; $string['criteriondelete'] = 'Delete criterion';
$string['criterionduplicate'] = 'Duplicate criterion';
$string['criterionempty'] = 'Click to edit criterion'; $string['criterionempty'] = 'Click to edit criterion';
$string['criterionmovedown'] = 'Move down'; $string['criterionmovedown'] = 'Move down';
$string['criterionmoveup'] = 'Move up'; $string['criterionmoveup'] = 'Move up';

View File

@ -71,7 +71,7 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
$criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}')); $criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}'));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) { if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls')); $criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls'));
foreach (array('moveup', 'delete', 'movedown') as $key) { foreach (array('moveup', 'delete', 'movedown', 'duplicate') as $key) {
$value = get_string('criterion'.$key, 'gradingform_rubric'); $value = get_string('criterion'.$key, 'gradingform_rubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']', $button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']',
'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value, 'tabindex' => -1)); 'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value, 'tabindex' => -1));

View File

@ -95,9 +95,11 @@
/* replace buttons with images */ /* replace buttons with images */
.gradingform_rubric.editor .delete input, .gradingform_rubric.editor .delete input,
.gradingform_rubric.editor .duplicate input,
.gradingform_rubric.editor .moveup input, .gradingform_rubric.editor .moveup input,
.gradingform_rubric.editor .movedown input{text-indent: -1000em;cursor:pointer;border:none;} .gradingform_rubric.editor .movedown input{text-indent: -1000em;cursor:pointer;border:none;}
.gradingform_rubric.editor .criterion .controls .delete input {width:12px;height:12px;background: transparent url([[pix:t/delete]]) no-repeat center top; margin: .3em .3em 0 .3em;} .gradingform_rubric.editor .criterion .controls .delete input {width:12px;height:12px;background: transparent url([[pix:t/delete]]) no-repeat center top; margin: .3em .3em 0 .3em;}
.gradingform_rubric.editor .criterion .controls .duplicate input {width:12px;height:12px;background: transparent url([[pix:t/copy]]) no-repeat center top; margin: .3em .3em 0 .3em;}
.gradingform_rubric.editor .levels .level .delete input {width:12px;height:16px;background: transparent url([[pix:t/delete]]) no-repeat center center; } .gradingform_rubric.editor .levels .level .delete input {width:12px;height:16px;background: transparent url([[pix:t/delete]]) no-repeat center center; }
.dir-rtl .gradingform_rubric.editor .levels .level .delete input { margin-right: .45em; margin-left: 0; } .dir-rtl .gradingform_rubric.editor .levels .level .delete input { margin-right: .45em; margin-left: 0; }
.gradingform_rubric.editor .moveup input {width:12px;height:12px;background: transparent url([[pix:t/up]]) no-repeat center top; margin: .3em .3em 0 .3em; } .gradingform_rubric.editor .moveup input {width:12px;height:12px;background: transparent url([[pix:t/up]]) no-repeat center top; margin: .3em .3em 0 .3em; }