From 22c97c6446d864db00b123505473af482ae10a40 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 26 Jul 2011 16:11:20 +0100 Subject: [PATCH] MDL-28471 Further tweaks to the question flag code. --- lang/en/question.php | 10 +++----- pix/i/flagged.png | Bin 193 -> 383 bytes pix/i/unflagged.png | Bin 197 -> 310 bytes question/engine/lib.php | 8 +++--- question/engine/renderer.php | 21 +++++++++++----- question/flags.js | 45 +++++++++++++--------------------- theme/base/style/question.css | 14 ++++++----- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lang/en/question.php b/lang/en/question.php index c1c7947e5b9..7a3e794c44c 100644 --- a/lang/en/question.php +++ b/lang/en/question.php @@ -65,8 +65,10 @@ $string['categorymove'] = 'The category \'{$a->name}\' contains {$a->count} questions (some of them may be old, hidden, questions that are still in use in some existing quizzes). Please choose another category to move them to.'; $string['categorymoveto'] = 'Save in category'; $string['categorynamecantbeblank'] = 'The category name cannot be blank.'; -$string['clicktoflag'] = 'Click to flag this question'; -$string['clicktounflag'] = 'Click to un-flag this question'; +$string['clickflag'] = 'Flag question'; +$string['clicktoflag'] = 'Flag this question for future reference'; +$string['clicktounflag'] = 'Remove flag'; +$string['clickunflag'] = 'Remove flag'; $string['contexterror'] = 'You shouldn\'t have got here if you\'re not moving a category to another context.'; $string['copy'] = 'Copy from {$a} and change links.'; $string['created'] = 'Created'; @@ -298,8 +300,6 @@ $string['changeoptions'] = 'Change options'; $string['check'] = 'Check'; $string['clearwrongparts'] = 'Clear incorrect responses'; -$string['clicktoflag'] = 'Click to flag this question'; -$string['clicktounflag'] = 'Click to un-flag this question'; $string['closepreview'] = 'Close preview'; $string['combinedfeedback'] = 'Combined feedback'; $string['commented'] = 'Commented: {$a}'; @@ -399,5 +399,3 @@ $string['withselected'] = 'With selected'; $string['xoutofmax'] = '{$a->mark} out of {$a->max}'; $string['yougotnright'] = 'You have correctly selected {$a->num}.'; -$string['clickflag'] = 'Flag question'; -$string['clickunflag'] = 'Unflag question'; diff --git a/pix/i/flagged.png b/pix/i/flagged.png index 287b41c4b585768ae8f767dac26bbe9247dc4904..bd6f0d0528211944765ffcb54445d2b3d7aa0be7 100644 GIT binary patch literal 383 zcmV-_0f7FAP)*(m{;^_9~=H=w%=H%qz;Naof-QC*S+0)VI)6>t+&d$co)$qW+z`eENuYbI?tHG0k z;Bj20ZduDgE5R-)p#T6&5&mNU000SaNLh0L01FZT01FZU(%pXi0000SbVXQnQ*UN; zcVTj606}DLVr3vkX>w(EZ*psMAVX6%akb+%0001jNkly?jy}MNO0L%dpV2{9- dv2r>AYUz#5_4Ds()+Xko=6o2WC3k5=V8IPvpg ojRAjz{1n0JLvAvi|L5PGEg*9!=i|dOKpPo6UHx3vIVCg!02C}j+W-In diff --git a/pix/i/unflagged.png b/pix/i/unflagged.png index 35935fe86fb8f03fe8c2205c401fa9c664f4d128..e70c25e9a504fdaac7bed0fd0690a7b2bb86099c 100644 GIT binary patch literal 310 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJbFq_W2nPqp?T7vkfLxmZpAgr- zfB*ja_3QihAD_Q|27-?tKfZhS?)B@}FJ8QQ@#4jkXV0HKd-CK75I=nI;L)wScW>Rg zdHwqJOP9}|J9kceY3)y-Ih+L^k;M!Q+(IDCcIQ+eo=O@f^)EG;nv4yKy{g(E{-7*Q)BzRg&GuioCBLhU4K6LSH87jaY9+; z<&>agu`jdgkP#Ah#c6`0xlD`P$%N9BvF(OfCV zo?Kvj`=*>B`|W#&lRXLQZy8FudK~^p&#b?HFL@68{QO4?t$~&@c)I$ztaD0e0syjs Bj9UNz literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnH3?%tPCZz)@o&cW^*8>a;k!svMJw3~oEmI4b z9Sjs_ED7=pW^j0RBMrz&_jGX#kqGZSyOFoSfQR+sFVdQ&MBb@03-@R6#xJL diff --git a/question/engine/lib.php b/question/engine/lib.php index 17d3c1f7ea7..1d535522979 100644 --- a/question/engine/lib.php +++ b/question/engine/lib.php @@ -632,8 +632,10 @@ public static function initialise_js() { 'requires' => array('base', 'dom', 'event-delegate', 'io-base'), ); $actionurl = $CFG->wwwroot . '/question/toggleflag.php'; - $fltext = array(0 => get_string('clickflag', 'question'), - 1 => get_string('clickunflag', 'question')); + $flagtext = array( + 0 => get_string('clickflag', 'question'), + 1 => get_string('clickunflag', 'question') + ); $flagattributes = array( 0 => array( 'src' => $OUTPUT->pix_url('i/unflagged') . '', @@ -649,7 +651,7 @@ public static function initialise_js() { ), ); $PAGE->requires->js_init_call('M.core_question_flags.init', - array($actionurl, $flagattributes, $fltext), false, $module); + array($actionurl, $flagattributes, $flagtext), false, $module); $done = true; } } diff --git a/question/engine/renderer.php b/question/engine/renderer.php index 910bda96585..66597f6e634 100644 --- a/question/engine/renderer.php +++ b/question/engine/renderer.php @@ -243,16 +243,25 @@ protected function question_flag(question_attempt $qa, $flagsoption) { * @return string the img tag. */ protected function get_flag_html($flagged, $id = '') { + if ($flagged) { + $icon = 'i/flagged'; + $alt = get_string('flagged', 'question'); + } else { + $icon = 'i/unflagged'; + $alt = get_string('notflagged', 'question'); + } + $attributes = array( + 'src' => $this->pix_url($icon), + 'alt' => $alt, + ); if ($id) { - $id = 'id="' . $id . '" '; + $attributes['id'] = $id; } + $img = html_writer::empty_tag('img', $attributes); if ($flagged) { - $img = 'flagged'; - } else { - $img = 'unflagged'; + $img .= ' ' . get_string('flagged', 'question'); } - return '' . get_string('flagthisquestion', 'question') . ''; + return $img; } protected function edit_question_link(question_attempt $qa, diff --git a/question/flags.js b/question/flags.js index d587a7d1c17..aa8dac16cc5 100644 --- a/question/flags.js +++ b/question/flags.js @@ -28,13 +28,13 @@ M.core_question_flags = { flagattributes: null, actionurl: null, - fltext: null, + flagtext: null, listeners: [], - init: function(Y, actionurl, flagattributes, fltext) { + init: function(Y, actionurl, flagattributes, flagtext) { M.core_question_flags.flagattributes = flagattributes; M.core_question_flags.actionurl = actionurl; - M.core_question_flags.fltext = fltext; + M.core_question_flags.flagtext = flagtext; Y.all('div.questionflag').each(function(flagdiv, i) { var checkbox = flagdiv.one('input[type=checkbox]'); @@ -42,21 +42,15 @@ M.core_question_flags = { return; } - var input = Y.Node.create(''); + var input = Y.Node.create(''); input.set('id', checkbox.get('id')); input.set('name', checkbox.get('name')); input.set('value', checkbox.get('checked') ? 1 : 0); // Create an image input to replace the img tag. var image = Y.Node.create(''); - M.core_question_flags.update_flag(input, image); - - // Create flag text - var flstatus = input.get('value'); - var txt = M.core_question_flags.fltext[flstatus]; - var flagtext = Y.Node.create(''); - flagtext.addClass(txt); - flagtext.append(txt); + var flagtext = Y.Node.create('.'); + M.core_question_flags.update_flag(input, image, flagtext); checkbox.remove(); flagdiv.one('label').remove(); @@ -66,30 +60,25 @@ M.core_question_flags = { }); Y.delegate('click', function(e) { - var input = this.previous('input'); + var input = this.one('input.questionflagvalue'); input.set('value', 1 - input.get('value')); - M.core_question_flags.update_flag(input, this); - var postdata = this.previous('input.questionflagpostdata').get('value') + + M.core_question_flags.update_flag(input, this.one('input.questionflagimage'), + this.one('span.questionflagtext')); + var postdata = this.one('input.questionflagpostdata').get('value') + input.get('value'); e.halt(); Y.io(M.core_question_flags.actionurl , {method: 'POST', 'data': postdata}); M.core_question_flags.fire_listeners(postdata); - }, document.body, 'input.questionflagimage'); + }, document.body, 'div.questionflag'); }, - update_flag: function(input, image) { - - YUI().use('node', function (Y) { - image.setAttrs(M.core_question_flags.flagattributes[input.get('value')]); - // get flag text which is next to image element - var element = image.next(); - // if element update its text - if(element){ - element.set('innerText', M.core_question_flags.fltext[input.get('value')]); - } - }); - + update_flag: function(input, image, flagtext) { + var value = input.get('value'); + image.setAttrs(M.core_question_flags.flagattributes[value]); + flagtext.replaceChild(flagtext.create(M.core_question_flags.flagtext[value]), + flagtext.get('firstChild')); + flagtext.set('title', M.core_question_flags.flagattributes[value].title); }, add_listener: function(listener) { diff --git a/theme/base/style/question.css b/theme/base/style/question.css index 2a0ce677b49..95d8e7dd69f 100644 --- a/theme/base/style/question.css +++ b/theme/base/style/question.css @@ -38,15 +38,17 @@ body.jsenabled #qtypechoicecontainer {display: block;} .que {clear: left;text-align: left;margin: 0 auto 1.8em auto;} .dir-rtl .que {text-align: right;} -.que .info {float: left;width: 6em;padding:0.5em;margin-bottom: 1.8em;background: #eee;} +.que .info {float: left;width: 7em;padding:0.5em;margin-bottom: 1.8em;background: #eee;} .que h2.no {margin: 0;font-size: 0.8em;line-height: 1;} .que span.qno {font-size: 1.5em;font-weight:bold;} -.que .state, -.que .grade, -.que .editquestion {font-size: 0.8em; margin-top: 0.7em;} -.que .info .questionflag {margin-top: 1em;margin-right: 1em;text-align: center;} +.que .info * {font-size: 0.8em;} +.que .info .state, +.que .info .grade, +.que .info .editquestion, +.que .info .questionflag {margin-top: 0.7em;} +.que .info .questionflag {cursor:pointer;} -.que .content {margin: 0 0 0 7.5em;} +.que .content {margin: 0 0 0 8.5em;} .que .formulation, .que .outcome,