From: tjhunt Date: Fri, 23 Jan 2009 06:05:25 +0000 (+0000) Subject: question bank: MDL-18000 Make select all work by clicking the checkbox column heading. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bfb1691da35fd9e46b536342deff21b860645a4e;p=moodle.git question bank: MDL-18000 Make select all work by clicking the checkbox column heading. Yay! I got bug 18000 and it is already fixed. --- diff --git a/question/editlib.php b/question/editlib.php index 96b45264d7..e9ac16379f 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -140,6 +140,8 @@ abstract class question_bank_column_base { public function __construct(question_bank_view $qbank) { $this->qbank = $qbank; $this->init(); + require_js(array('yui_yahoo','yui_event')); + require_js('question/qbank.js'); } /** @@ -390,7 +392,7 @@ class question_bank_checkbox_column extends question_bank_column_base { } protected function get_title() { - return ''; + return ''; } protected function get_title_tip() { @@ -399,7 +401,9 @@ class question_bank_checkbox_column extends question_bank_column_base { protected function display_content($question, $rowclasses) { echo ''; + $question->id . '" id="checkq' . $question->id . '" value="1"/>'; + print_js_call('question_bank.init_checkbox_column', array(get_string('selectall'), + get_string('deselectall'), 'checkq' . $question->id)); } public function get_required_fields() { @@ -1282,14 +1286,6 @@ class question_bank_view { echo $paging; echo ''; - echo '
'; - if ($caneditall || $canmoveall || $canuseall){ - echo ''.$strselectall.' /'. - ' '.$strselectnone.''; - echo '
'; - } - echo "
\n"; - echo '
'; if ($caneditall || $canmoveall || $canuseall){ echo ' '.get_string('withselected', 'quiz').':
'; diff --git a/question/qbank.js b/question/qbank.js new file mode 100644 index 0000000000..7c756f834a --- /dev/null +++ b/question/qbank.js @@ -0,0 +1,35 @@ +// This script is included by question_bank_view in question/editlib.php. + +question_bank = { + strselectall: '', + strdeselectall: '', + headercheckbox: null, + firstcheckbox: null, + + init_checkbox_column: function(strselectall, strdeselectall, firstcbid) { + question_bank.strselectall = strselectall; + question_bank.strdeselectall = strdeselectall; + + // Find the header checkbox, and initialise it. + question_bank.headercheckbox = document.getElementById('qbheadercheckbox'); + question_bank.headercheckbox.disabled = false; + question_bank.headercheckbox.title = strselectall; + + // Find the first real checkbox. + question_bank.firstcheckbox = document.getElementById(firstcbid); + + // Add the event handler. + YAHOO.util.Event.addListener(question_bank.headercheckbox, 'change', question_bank.header_checkbox_click); + }, + + header_checkbox_click: function() { + if (question_bank.firstcheckbox.checked) { + deselect_all_in('TABLE', null, 'categoryquestions'); + question_bank.headercheckbox.title = question_bank.strselectall; + } else { + select_all_in('TABLE', null, 'categoryquestions'); + question_bank.headercheckbox.title = question_bank.strdeselectall; + } + question_bank.headercheckbox.checked = false; + } +};