Skip to content

Commit

Permalink
Merge branch 'MDL-50283_master' of https://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jun 23, 2015
2 parents 20a1651 + a939ae6 commit 782300f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
39 changes: 37 additions & 2 deletions grade/grading/form/rubric/js/rubriceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
elements_str = '#rubric-'+name+' .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 newlevid = M.gradingform_rubriceditor.calculatenewid('#rubric-'+name+' .level')
}
Expand Down Expand Up @@ -204,6 +204,41 @@ M.gradingform_rubriceditor.buttonclick = function(e, confirmed) {
dialog_options['message'] = M.util.get_string('confirmdeletecriterion', 'gradingform_rubric')
M.util.show_confirm_dialog(e, dialog_options);
}
} else if (chunks.length == 4 && action == 'duplicate') {
// Duplicate criterion.
var levelsdef = [], levelsscores = [0], levidx = null;
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') {
// DELETE LEVEL
if (confirmed) {
Expand Down Expand Up @@ -241,4 +276,4 @@ M.gradingform_rubriceditor.calculatenewid = function (elements_str) {
if (id.match(/^NEWID(\d+)$/)) newid = Math.max(newid, parseInt(id.substring(5))+1);
} );
return newid
}
}
1 change: 1 addition & 0 deletions grade/grading/form/rubric/lang/en/gradingform_rubric.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
$string['confirmdeletelevel'] = 'Are you sure you want to delete this level?';
$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';
Expand Down
2 changes: 1 addition & 1 deletion grade/grading/form/rubric/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function criterion_template($mode, $options, $elementname = '{NAME}', $cr
$criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}'));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$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');
$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));
Expand Down
2 changes: 2 additions & 0 deletions grade/grading/form/rubric/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@

/* replace buttons with images */
.gradingform_rubric.editor .delete input,
.gradingform_rubric.editor .duplicate input,
.gradingform_rubric.editor .moveup input,
.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 .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; }
.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; }
Expand Down
2 changes: 1 addition & 1 deletion grade/grading/form/rubric/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'gradingform_rubric';
$plugin->version = 2015051100;
$plugin->version = 2015051101;

$plugin->requires = 2015050500;

Expand Down

0 comments on commit 782300f

Please sign in to comment.