Permalink
Browse files

Merge pull request #15 from marinaglancy/wip-renderer-rubric

MDL-29481: implemented rubrics renderer, improved rubrics UI
  • Loading branch information...
2 parents 8168299 + ab15674 commit 6477706e9c0e60b458ce8d553da98f144bdb0915 @mudrd8mz mudrd8mz committed Oct 17, 2011
View
@@ -289,6 +289,18 @@ public function validate_grading_element($elementvalue, $itemid) {
return true;
}
+ /**
+ * Returns the renderer for the current plugin
+ *
+ * @param string $subtype optional subtype
+ * @param string $target one of rendering target constants
+ * @return renderer_base
+ */
+ public function get_renderer($subtype = null, $target = null) {
+ global $PAGE;
+ return $PAGE->get_renderer('gradingform_'. $this->get_method_name(), $subtype, $target);
+ }
+
////////////////////////////////////////////////////////////////////////////
@@ -6,6 +6,11 @@ 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);
Y.all('#rubric-'+options.name+' .radio').setStyle('display', 'none')
+ Y.all('#rubric-'+options.name+' .level').each(function (node) {
+ if (node.one('input[type=radio][checked]')) {
+ node.addClass('checked');
+ }
+ });
};
M.gradingform_rubric.levelclick = function(e, Y, name) {
@@ -8,13 +8,82 @@ M.gradingform_rubriceditor.init = function(Y, options) {
'criterion' : options.criteriontemplate,
'level' : options.leveltemplate
}
- M.gradingform_rubriceditor.addhandlers(Y, options.name);
+ M.gradingform_rubriceditor.disablealleditors(null, Y, options.name)
+ M.gradingform_rubriceditor.addhandlers(Y, options.name)
};
// Adds handlers for clicking submit button. This function must be called each time JS adds new elements to html
M.gradingform_rubriceditor.addhandlers = function(Y, name) {
if (M.gradingform_rubriceditor.eventhandler) M.gradingform_rubriceditor.eventhandler.detach()
- M.gradingform_rubriceditor.eventhandler = Y.on('click', M.gradingform_rubriceditor.buttonclick, '#rubriceditor-'+name+' input[type=submit]', null, Y, name);
+ M.gradingform_rubriceditor.eventhandler = Y.on('click', M.gradingform_rubriceditor.clickanywhere, 'body', null, Y, name);
+ M.gradingform_rubriceditor.eventhandler = Y.on('click', M.gradingform_rubriceditor.buttonclick, '#rubric-'+name+' input[type=submit]', null, Y, name);
+}
+
+M.gradingform_rubriceditor.disablealleditors = function(e, Y, name) {
+ Y.all('#rubric-'+name+' .level').each( function(node) {M.gradingform_rubriceditor.editmode(node, false)} );
+ Y.all('#rubric-'+name+' .description').each( function(node) {M.gradingform_rubriceditor.editmode(node, false)} );
+}
+
+M.gradingform_rubriceditor.clickanywhere = function(e, Y, name) {
+ var el = e.target
+ // if clicked on button - disablecurrenteditor, continue
+ if (el.get('tagName') == 'INPUT' && el.get('type') == 'submit') {
+ M.gradingform_rubriceditor.disablealleditors(null, Y, name)
+ return
+ }
+ // else if clicked on level and this level is not enabled - enable it
+ // or if clicked on description and this description is not enabled - enable it
+ while (el && !(el.hasClass('level') || el.hasClass('description'))) el = el.get('parentNode')
+ if (el) {
+ if (el.one('textarea').getStyle('display') == 'none') {
+ M.gradingform_rubriceditor.disablealleditors(null, Y, name)
+ M.gradingform_rubriceditor.editmode(el, true)
+ }
+ return
+ }
+ // else disablecurrenteditor
+ M.gradingform_rubriceditor.disablealleditors(null, Y, name)
+}
+
+M.gradingform_rubriceditor.editmode = function(el, editmode) {
+ var ta = el.one('textarea')
+ if (!ta.get('parentNode').one('.plainvalue')) {
+ ta.get('parentNode').append('<div class="plainvalue"></div>')
+ }
+ var tb = el.one('input[type=text]')
+ if (tb && !tb.get('parentNode').one('.plainvalue')) {
+ tb.get('parentNode').append('<div class="plainvalue"></div>')
+ }
+ if (!editmode) {
+ var value = ta.get('value')
+ if (value.length) ta.get('parentNode').one('.plainvalue').removeClass('empty')
+ else {
+ value = (el.hasClass('level')) ? M.str.gradingform_rubric.levelempty : M.str.gradingform_rubric.criterionempty
+ ta.get('parentNode').one('.plainvalue').addClass('empty')
+ }
+ ta.get('parentNode').one('.plainvalue').set('innerHTML', value)
+ ta.get('parentNode').one('.plainvalue').setStyle('display', 'block')
+ ta.setStyle('display', 'none')
+ if (tb) {
+ tb.get('parentNode').one('.plainvalue').set('innerHTML', tb.get('value'))
+ tb.get('parentNode').one('.plainvalue').setStyle('display', 'inline-block')
+ tb.setStyle('display', 'none')
+ }
+ } else {
+ if (tb) {
+ tb.get('parentNode').one('.plainvalue').setStyle('display', 'none')
+ tb.setStyle('display', 'inline-block')
+ }
+ var width = ta.get('parentNode').getComputedStyle('width') // TODO min width
+ var height = ta.get('parentNode').getComputedStyle('height') // TODO min height
+ if (el.hasClass('level')) {
+ height = el.getComputedStyle('height') - el.one('.score').getComputedStyle('height')
+ } else if (el.hasClass('description')) {
+ height = el.get('parentNode').getComputedStyle('height')
+ }
+ ta.get('parentNode').one('.plainvalue').setStyle('display', 'none')
+ ta.setStyle('display', 'block').setStyle('width', width).setStyle('height', height)
+ }
}
// handler for clicking on submit buttons within rubriceditor element. Adds/deletes/rearranges criteria and/or levels on client side
@@ -25,9 +94,9 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
if (chunks[0] != name) return;
var elements_str
if (chunks.length>3 || action == 'addlevel') {
- elements_str = '#rubriceditor-'+name+' #'+name+'-'+chunks[1]+'-levels .level'
+ elements_str = '#rubric-'+name+' #'+name+'-'+chunks[1]+'-levels .level'
} else {
- elements_str = '#rubriceditor-'+name+' .criterion'
+ elements_str = '#rubric-'+name+' .criterion'
}
// prepare the id of the next inserted level or criterion
var newid = 1
@@ -48,7 +117,7 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
replace(/\{CRITERION-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
Y.one('#'+name+'-criteria').append(newcriterion)
M.gradingform_rubriceditor.addhandlers(Y, name);
- } else if (chunks.length == 3 && action == 'addlevel') {
+ } else if (chunks.length == 4 && action == 'addlevel') {
// ADD NEW LEVEL
var newlevel = M.gradingform_rubriceditor.templates[name]['level'].
replace(/\{CRITERION-id\}/g, chunks[1]).replace(/\{LEVEL-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
@@ -33,9 +33,12 @@
$string['name'] = 'Name';
$string['addcriterion'] = 'Add criterion';
-$string['criterionmoveup'] = 'Up';
-$string['criteriondelete'] = 'Delete';
-$string['criterionmovedown'] = 'Down';
+$string['criterionmoveup'] = 'Move up';
+$string['criteriondelete'] = 'Delete criterion';
+$string['criterionmovedown'] = 'Move down';
$string['criterionaddlevel'] = 'Add level';
$string['scorepostfix'] = ' pts';
-$string['leveldelete'] = 'Del';
+$string['leveldelete'] = 'Delete level';
+
+$string['criterionempty'] = 'Click to edit criterion';
+$string['levelempty'] = 'Click to edit level';
@@ -32,6 +32,13 @@
* This controller encapsulates the rubric grading logic
*/
class gradingform_rubric_controller extends gradingform_controller {
+ // Modes of displaying the rubric (used in gradingform_rubric_renderer)
+ const DISPLAY_EDIT_FULL = 1; // For editing (moderator or teacher creates a rubric)
+ const DISPLAY_EDIT_FROZEN = 2; // Preview the rubric design with hidden fields
+ const DISPLAY_PREVIEW = 3; // Preview the rubric design
+ const DISPLAY_EVAL = 4; // For evaluation, enabled (teacher grades a student)
+ const DISPLAY_EVAL_FROZEN = 5; // For evaluation, with hidden fields
+ const DISPLAY_REVIEW = 6; // Dispaly filled rubric (i.e. students see their grades)
/**
* Extends the module settings navigation with the rubric grading settings
@@ -307,6 +314,32 @@ public function save_and_get_grade($raterid, $itemid, $formdata) {
*/
public function to_html($gradingformelement) {
global $PAGE, $USER;
+ if (!$gradingformelement->_flagFrozen) {
+ $module = array('name'=>'gradingform_rubric', 'fullpath'=>'/grade/grading/form/rubric/js/rubric.js');
+ $PAGE->requires->js_init_call('M.gradingform_rubric.init', array(array('name' => $gradingformelement->getName(), 'criteriontemplate' =>'', 'leveltemplate' => '')), true, $module);
+ $mode = self::DISPLAY_EVAL;
+ } else {
+ if ($this->_persistantFreeze) {
+ $mode = gradingform_rubric_controller::DISPLAY_EVAL_FROZEN;
+ } else {
+ $mode = gradingform_rubric_controller::DISPLAY_REVIEW;
+ }
+ }
+ $criteria = $this->definition->rubric_criteria;
+ $submissionid = $gradingformelement->get_grading_attribute('submissionid');
+ $raterid = $USER->id; // TODO - this is very strange!
+ $value = $gradingformelement->getValue();
+ if ($value === null) {
+ $value = $this->get_grading($raterid, $submissionid); // TODO maybe implement in form->set_data() ?
+ }
+ return $this->get_renderer()->display_rubric($criteria, $mode, $gradingformelement->getName(), $value);
+ }
+
+ /**
+ * Returns html for form element
+ */
+ public function to_html_old($gradingformelement) {
+ global $PAGE, $USER;
//TODO move to renderer
//$gradingrenderer = $this->prepare_renderer($PAGE);
Oops, something went wrong.

0 comments on commit 6477706

Please sign in to comment.