Skip to content

Commit

Permalink
MDL-28471 Further tweaks to the question flag code.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jul 26, 2011
1 parent 474ee93 commit 22c97c6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
10 changes: 4 additions & 6 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}';
Expand Down Expand Up @@ -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';
Binary file modified pix/i/flagged.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pix/i/unflagged.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions question/engine/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') . '',
Expand All @@ -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;
}
}
Expand Down
21 changes: 15 additions & 6 deletions question/engine/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<img ' . $id . 'src="' . $this->pix_url('/i/' . $img) .
'" alt="' . get_string('flagthisquestion', 'question') . '" />';
return $img;
}

protected function edit_question_link(question_attempt $qa,
Expand Down
45 changes: 17 additions & 28 deletions question/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,29 @@
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]');
if (!checkbox) {
return;
}

var input = Y.Node.create('<input type="hidden" />');
var input = Y.Node.create('<input type="hidden" class="questionflagvalue" />');
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('<input type="image" class="questionflagimage" />');
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('<span class="flag-text">');
flagtext.addClass(txt);
flagtext.append(txt);
var flagtext = Y.Node.create('<span class="questionflagtext">.</span>');
M.core_question_flags.update_flag(input, image, flagtext);

checkbox.remove();
flagdiv.one('label').remove();
Expand All @@ -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) {
Expand Down
14 changes: 8 additions & 6 deletions theme/base/style/question.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 22c97c6

Please sign in to comment.