Merge branch 'MDL-32729-master' of git://github.com/andrewnicols/moodle

Conflicts:
	theme/bootstrapbase/style/moodle.css
This commit is contained in:
Sam Hemelryk 2014-04-02 09:27:23 +13:00
commit 0ea11b7cee
24 changed files with 674 additions and 253 deletions

View File

@ -47,6 +47,9 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, {
return;
}
// Ensure that we're showing the JS version of the chooser.
Y.one(Y.config.doc.body).addClass('jschooser');
// Set Default options
var paramkey,
params = {

View File

@ -1 +1 @@
YUI.add("moodle-core-chooserdialogue",function(e,t){var n=function(){n.superclass.constructor.apply(this,arguments)};e.extend(n,e.Base,{panel:null,submitbutton:null,container:null,listenevents:[],bodycontent:null,headercontent:null,instanceconfig:null,hiddenRadioValue:null,setup_chooser_dialogue:function(e,t,n){this.bodycontent=e,this.headercontent=t,this.instanceconfig=n},prepare_chooser:function(){if(this.panel)return;var t,n={bodyContent:this.bodycontent.get("innerHTML"),headerContent:this.headercontent.get("innerHTML"),width:"540px",draggable:!0,visible:!1,zindex:100,modal:!0,shim:!0,closeButtonTitle:this.get("closeButtonTitle"),focusOnPreviousTargetAfterHide:!0,render:!1};for(t in this.instanceconfig)n[t]=this.instanceconfig[t];this.panel=new M.core.dialogue(n),this.bodycontent.remove(),this.headercontent.remove(),this.panel.hide(),this.panel.render(),this.container=this.panel.get("boundingBox").one(".choosercontainer"),this.options=this.container.all(".option input[type=radio]"),this.hiddenRadioValue=e.Node.create('<input type="hidden" value="" />'),this.container.one("form").appendChild(this.hiddenRadioValue),this.panel.get("boundingBox").addClass("chooserdialogue")},display_chooser:function(t){var n,r,i;this.prepare_chooser(),t.preventDefault(),n=this.panel.get("boundingBox"),r=this.container.one(".alloptions"),i=e.one("document").on("orientationchange",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=e.one("window").on("resize",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=this.container.on("click",this.check_options,this),this.listenevents.push(i),i=this.container.on("key_up",this.check_options,this),this.listenevents.push(i),i=this.container.on("dblclick",function(e){e.target.ancestor("div.option")&&(this.check_options(),this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents(),this.container.one("form").submit())},this),this.listenevents.push(i),this.container.one("form").on("submit",function(){this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents()},this),i=this.container.one(".addcancel").on("click",this.cancel_popup,this),this.listenevents.push(i),i=n.one("button.closebutton").on("click",this.cancel_popup,this),this.listenevents.push(i),i=e.one("document").on("keydown",this.handle_key_press,this),this.listenevents.push(i),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(t),this.center_dialogue(r),this.container.one(".option input[type=radio]").focus(),this.check_options()},cancel_listenevents:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()},center_dialogue:function(e){var t=this.panel.get("boundingBox"),n=t.get("winHeight"),r,i;if(this.panel.shouldResizeFullscreen())return;r=this.get("maxheight"),n<=r&&(n<=this.get("minheight")?r=this.get("minheight"):r=n),r>this.get("minheight")?this.panel.lockScroll&&!this.panel.lockScroll.isActive()&&this.panel.lockScroll.enableScrollLock(!0):this.panel.lockScroll&&this.panel.lockScroll.isActive()&&this.panel.lockScroll.disableScrollLock(),i=r,r-=110,e.setStyle("maxHeight",r+"px"),dialogueheight=t.getStyle("height"),dialogueheight.match(/.*px$/)?dialogueheight=dialogueheight.replace(/px$/,""):dialogueheight=i,dialogueheight<this.get("baseheight")&&(dialogueheight=this.get("baseheight"),e.setStyle("height",dialogueheight+"px")),this.panel.centerDialogue()},handle_key_press:function(e){e.keyCode===27&&this.cancel_popup(e)},cancel_popup:function(e){e.preventDefault(),this.hide()},hide:function(){this.cancel_listenevents(),this.container.detachAll(),this.panel.hide()},check_options:function(){this.options.each(function(e){var t=e.get("parentNode").get("parentNode");e.get("checked")?(t.addClass("selected"),this.option_selected(e),this.submitbutton.removeAttribute("disabled"),e.focus()):t.removeClass("selected")},this)},option_selected:function(e){this.hiddenRadioValue.setAttrs({value:e.get("value"),name:e.get("name")})}},{NAME:"moodle-core-chooserdialogue",ATTRS:{minheight:{value:300},baseheight:{value:400},maxheight:{value:660},closeButtonTitle:{validator:e.Lang.isString,value:"Close"}}}),M.core=M.core||{},M.core.chooserdialogue=n},"@VERSION@",{requires:["base","panel","moodle-core-notification"]});
YUI.add("moodle-core-chooserdialogue",function(e,t){var n=function(){n.superclass.constructor.apply(this,arguments)};e.extend(n,e.Base,{panel:null,submitbutton:null,container:null,listenevents:[],bodycontent:null,headercontent:null,instanceconfig:null,hiddenRadioValue:null,setup_chooser_dialogue:function(e,t,n){this.bodycontent=e,this.headercontent=t,this.instanceconfig=n},prepare_chooser:function(){if(this.panel)return;e.one(e.config.doc.body).addClass("jschooser");var t,n={bodyContent:this.bodycontent.get("innerHTML"),headerContent:this.headercontent.get("innerHTML"),width:"540px",draggable:!0,visible:!1,zindex:100,modal:!0,shim:!0,closeButtonTitle:this.get("closeButtonTitle"),focusOnPreviousTargetAfterHide:!0,render:!1};for(t in this.instanceconfig)n[t]=this.instanceconfig[t];this.panel=new M.core.dialogue(n),this.bodycontent.remove(),this.headercontent.remove(),this.panel.hide(),this.panel.render(),this.container=this.panel.get("boundingBox").one(".choosercontainer"),this.options=this.container.all(".option input[type=radio]"),this.hiddenRadioValue=e.Node.create('<input type="hidden" value="" />'),this.container.one("form").appendChild(this.hiddenRadioValue),this.panel.get("boundingBox").addClass("chooserdialogue")},display_chooser:function(t){var n,r,i;this.prepare_chooser(),t.preventDefault(),n=this.panel.get("boundingBox"),r=this.container.one(".alloptions"),i=e.one("document").on("orientationchange",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=e.one("window").on("resize",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=this.container.on("click",this.check_options,this),this.listenevents.push(i),i=this.container.on("key_up",this.check_options,this),this.listenevents.push(i),i=this.container.on("dblclick",function(e){e.target.ancestor("div.option")&&(this.check_options(),this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents(),this.container.one("form").submit())},this),this.listenevents.push(i),this.container.one("form").on("submit",function(){this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents()},this),i=this.container.one(".addcancel").on("click",this.cancel_popup,this),this.listenevents.push(i),i=n.one("button.closebutton").on("click",this.cancel_popup,this),this.listenevents.push(i),i=e.one("document").on("keydown",this.handle_key_press,this),this.listenevents.push(i),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(t),this.center_dialogue(r),this.container.one(".option input[type=radio]").focus(),this.check_options()},cancel_listenevents:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()},center_dialogue:function(e){var t=this.panel.get("boundingBox"),n=t.get("winHeight"),r,i;if(this.panel.shouldResizeFullscreen())return;r=this.get("maxheight"),n<=r&&(n<=this.get("minheight")?r=this.get("minheight"):r=n),r>this.get("minheight")?this.panel.lockScroll&&!this.panel.lockScroll.isActive()&&this.panel.lockScroll.enableScrollLock(!0):this.panel.lockScroll&&this.panel.lockScroll.isActive()&&this.panel.lockScroll.disableScrollLock(),i=r,r-=110,e.setStyle("maxHeight",r+"px"),dialogueheight=t.getStyle("height"),dialogueheight.match(/.*px$/)?dialogueheight=dialogueheight.replace(/px$/,""):dialogueheight=i,dialogueheight<this.get("baseheight")&&(dialogueheight=this.get("baseheight"),e.setStyle("height",dialogueheight+"px")),this.panel.centerDialogue()},handle_key_press:function(e){e.keyCode===27&&this.cancel_popup(e)},cancel_popup:function(e){e.preventDefault(),this.hide()},hide:function(){this.cancel_listenevents(),this.container.detachAll(),this.panel.hide()},check_options:function(){this.options.each(function(e){var t=e.get("parentNode").get("parentNode");e.get("checked")?(t.addClass("selected"),this.option_selected(e),this.submitbutton.removeAttribute("disabled"),e.focus()):t.removeClass("selected")},this)},option_selected:function(e){this.hiddenRadioValue.setAttrs({value:e.get("value"),name:e.get("name")})}},{NAME:"moodle-core-chooserdialogue",ATTRS:{minheight:{value:300},baseheight:{value:400},maxheight:{value:660},closeButtonTitle:{validator:e.Lang.isString,value:"Close"}}}),M.core=M.core||{},M.core.chooserdialogue=n},"@VERSION@",{requires:["base","panel","moodle-core-notification"]});

View File

@ -47,6 +47,9 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, {
return;
}
// Ensure that we're showing the JS version of the chooser.
Y.one(Y.config.doc.body).addClass('jschooser');
// Set Default options
var paramkey,
params = {

View File

@ -45,6 +45,9 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, {
return;
}
// Ensure that we're showing the JS version of the chooser.
Y.one(Y.config.doc.body).addClass('jschooser');
// Set Default options
var paramkey,
params = {

View File

@ -93,7 +93,7 @@ if ($cm !== null) {
// Display a form to choose the question type.
echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
print_choose_qtype_to_add_form($hiddenparams);
print_choose_qtype_to_add_form($hiddenparams, null, false);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

View File

@ -441,16 +441,9 @@ class question_bank_checkbox_column extends question_bank_column_base {
echo '<input title="' . $this->strselect . '" type="checkbox" name="q' .
$question->id . '" id="checkq' . $question->id . '" value="1"/>';
if ($this->firstrow) {
$PAGE->requires->js('/question/qengine.js');
$module = array(
'name' => 'qbank',
'fullpath' => '/question/qbank.js',
'requires' => array('yui2-dom', 'yui2-event', 'yui2-container'),
'strings' => array(),
'async' => false,
);
$PAGE->requires->js_init_call('question_bank.init_checkbox_column', array(get_string('selectall'),
get_string('deselectall'), 'checkq' . $question->id), false, $module);
$PAGE->requires->strings_for_js(array('selectall', 'deselectall'), 'moodle');
$PAGE->requires->yui_module('moodle-question-qbankmanager', 'M.question.qbankmanager.init',
array('checkq' . $question->id));
$this->firstrow = false;
}
}
@ -1930,75 +1923,32 @@ function require_login_in_context($contextorid = null){
* @param $allowedqtypes optional list of qtypes that are allowed. If given, only
* those qtypes will be shown. Example value array('description', 'multichoice').
*/
function print_choose_qtype_to_add_form($hiddenparams, array $allowedqtypes = null) {
function print_choose_qtype_to_add_form($hiddenparams, array $allowedqtypes = null, $enablejs = true) {
global $CFG, $PAGE, $OUTPUT;
echo '<div id="chooseqtypehead" class="hd">' . "\n";
echo $OUTPUT->heading(get_string('chooseqtypetoadd', 'question'), 3);
echo "</div>\n";
echo '<div id="chooseqtype">' . "\n";
echo '<form action="' . $CFG->wwwroot . '/question/question.php" method="get"><div id="qtypeformdiv">' . "\n";
foreach ($hiddenparams as $name => $value) {
echo '<input type="hidden" name="' . s($name) . '" value="' . s($value) . '" />' . "\n";
if ($enablejs) {
// Add the chooser.
$PAGE->requires->yui_module('moodle-question-chooser',
'M.question.init_chooser',
array(array('courseid' => $PAGE->course->id))
);
}
echo "</div>\n";
echo '<div class="qtypes">' . "\n";
echo '<div class="instruction">' . get_string('selectaqtypefordescription', 'question') . "</div>\n";
echo '<div class="alloptions">' . "\n";
echo '<div class="realqtypes">' . "\n";
$realqtypes = array();
$fakeqtypes = array();
foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) {
if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) {
continue;
}
if ($qtype->is_real_question_type()) {
print_qtype_to_add_option($qtype);
$realqtypes[] = $qtype;
} else {
$fakeqtypes[] = $qtype;
}
}
echo "</div>\n";
echo '<div class="fakeqtypes">' . "\n";
foreach ($fakeqtypes as $qtype) {
print_qtype_to_add_option($qtype);
}
echo "</div>\n";
echo "</div>\n";
echo "</div>\n";
echo '<div class="submitbuttons">' . "\n";
echo '<input type="submit" value="' . get_string('next') . '" id="chooseqtype_submit" />' . "\n";
echo '<input type="submit" id="chooseqtypecancel" name="addcancel" value="' . get_string('cancel') . '" />' . "\n";
echo "</div></form>\n";
echo "</div>\n";
$PAGE->requires->js('/question/qengine.js');
$module = array(
'name' => 'qbank',
'fullpath' => '/question/qbank.js',
'requires' => array('yui2-dom', 'yui2-event', 'yui2-container'),
'strings' => array(),
'async' => false,
);
$PAGE->requires->js_init_call('qtype_chooser.init', array('chooseqtype'), false, $module);
}
/**
* Private function used by the preceding one.
* @param question_type $qtype the question type.
*/
function print_qtype_to_add_option($qtype) {
echo '<div class="qtypeoption">' . "\n";
echo '<label for="' . $qtype->plugin_name() . '">';
echo '<input type="radio" name="qtype" id="' . $qtype->plugin_name() .
'" value="' . $qtype->name() . '" />';
echo '<span class="qtypename">';
$fakequestion = new stdClass();
$fakequestion->qtype = $qtype->name();
echo print_question_icon($fakequestion);
echo $qtype->menu_name() . '</span><span class="qtypesummary">' .
get_string('pluginnamesummary', $qtype->plugin_name());
echo "</span></label>\n";
echo "</div>\n";
$renderer = $PAGE->get_renderer('question', 'bank');
echo $renderer->qbank_chooser($realqtypes, $fakeqtypes, $PAGE->course, $hiddenparams);
}
/**

View File

@ -1,170 +0,0 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript belonging to question_bank_view.
*
* This script is included by question_bank_view and other parts of question/editlib.php.
*
* @package moodlecore
* @subpackage questionbank
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
question_bank = {
strselectall: '',
strdeselectall: '',
headercheckbox: null,
firstcheckbox: null,
init_checkbox_column: function(Y, 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.
Y.YUI2.util.Event.addListener(question_bank.headercheckbox, 'click', question_bank.header_checkbox_click);
},
header_checkbox_click: function() {
if (question_bank.firstcheckbox.checked) {
select_all_in_element_with_id('categoryquestions', '');
question_bank.headercheckbox.title = question_bank.strselectall;
} else {
select_all_in_element_with_id('categoryquestions', 'checked');
question_bank.headercheckbox.title = question_bank.strdeselectall;
}
question_bank.headercheckbox.checked = false;
}
};
// JavaScript to make the list of question types pop-up when you click an add
// add question button.
qtype_chooser = {
radiobuttons: [],
labels: [],
container: null,
submitbutton: null,
yui3: null,
init: function(Y, boxid) {
// Store Y reference.
qtype_chooser.yui3 = Y;
// Find the radio buttons.
qtype_chooser.radiobuttons = Y.YUI2.util.Dom.getElementsBy(
function(el) { return el.type == 'radio'; }, 'input' , boxid);
qtype_chooser.labels = Y.YUI2.util.Dom.getElementsByClassName('qtypeoption', 'div', boxid);
// Find the submit button.
qtype_chooser.submitbutton = document.getElementById(boxid + '_submit');
qtype_chooser.enable_disable_submit();
// Add the event handlers.
Y.YUI2.util.Event.addListener(boxid, 'click', qtype_chooser.enable_disable_submit);
Y.YUI2.util.Event.addListener(boxid, 'key_down', qtype_chooser.enable_disable_submit);
Y.YUI2.util.Event.addListener(boxid, 'key_up', qtype_chooser.enable_disable_submit);
Y.YUI2.util.Event.addListener(boxid, 'dblclick', function(e) {
if (!qtype_chooser.submitbutton.disabled) {
M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
qtype_chooser.submitbutton.form.submit();
}
});
Y.YUI2.util.Event.onDOMReady(qtype_chooser.init_container);
Y.on('submit', function(e) {
M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
}, qtype_chooser.submitbutton.form);
},
enable_disable_submit: function() {
var Y = qtype_chooser.yui3;
var ok = false;
for (var i = 0; i < qtype_chooser.radiobuttons.length; i++) {
if (qtype_chooser.radiobuttons[i].checked) {
ok = true;
Y.YUI2.util.Dom.addClass(qtype_chooser.labels[i], 'selected');
} else {
Y.YUI2.util.Dom.removeClass(qtype_chooser.labels[i], 'selected');
}
}
qtype_chooser.submitbutton.disabled = !ok;
},
init_container: function() {
var Y = qtype_chooser.yui3;
if (!document.getElementById('qtypechoicecontainer')) {
return;
}
var qtypechoicecontainer = document.getElementById('qtypechoicecontainer');
qtypechoicecontainer.style.display = 'block';
qtypechoicecontainer.parentNode.removeChild(qtypechoicecontainer);
document.body.appendChild(qtypechoicecontainer);
qtype_chooser.container = new Y.YUI2.widget.Dialog(qtypechoicecontainer, {
constraintoviewport: true,
visible: false,
modal: true,
fixedcenter: true,
close: true,
draggable: true,
dragOnly: true,
postmethod: 'form',
zIndex: 1000
});
qtype_chooser.container.render();
Y.YUI2.util.Event.addListener('chooseqtypecancel', 'click', qtype_chooser.cancel_popup);
var addforms = Y.YUI2.util.Dom.getElementsBy(function(el) {
return /question\/addquestion\.php/.test(el.action); }, 'form', document.body);
for (var i = 0; i < addforms.length; i++) {
Y.YUI2.util.Event.addListener(addforms[i], 'submit', qtype_chooser.add_button_click);
}
},
add_button_click: function(e) {
var Y = qtype_chooser.yui3;
var form = document.getElementById('qtypeformdiv');
var oldhidden = Y.YUI2.util.Dom.getElementsBy(
function(el) { return el.type == 'hidden'; }, 'input', form);
for (var i = 0; i < oldhidden.length; i++) {
oldhidden[i].parentNode.removeChild(oldhidden[i]);
}
var wantedhidden = Y.YUI2.util.Dom.getElementsBy(
function(el) { return el.type == 'hidden'; }, 'input', this);
for (i = 0; i < wantedhidden.length; i++) {
form.appendChild(wantedhidden[i].cloneNode(true));
}
qtype_chooser.container.show();
Y.YUI2.util.Event.preventDefault(e);
},
cancel_popup: function(e) {
var Y = qtype_chooser.yui3;
qtype_chooser.container.hide();
Y.YUI2.util.Event.preventDefault(e);
}
};

View File

@ -36,7 +36,8 @@ defined('MOODLE_INTERNAL') || die();
class core_question_bank_renderer extends plugin_renderer_base {
/**
* Output the icon for a question type
* Output the icon for a question type.
*
* @param string $qtype the question type.
* @return string HTML fragment.
*/
@ -46,4 +47,141 @@ class core_question_bank_renderer extends plugin_renderer_base {
return $this->pix_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr));
}
/**
* Build the HTML for the question chooser javascript popup.
*
* @param array $real A set of real question types
* @param array $fake A set of fake question types
* @param object $course The course that will be displayed
* @param array $hiddenparams Any hidden parameters to add to the form
* @return string The composed HTML for the questionbank chooser
*/
public function qbank_chooser($real, $fake, $course, $hiddenparams) {
global $OUTPUT;
// Start the form content.
$formcontent = html_writer::start_tag('form', array('action' => new moodle_url('/question/question.php'),
'id' => 'chooserform', 'method' => 'get'));
// Add the hidden fields.
$hiddenfields = '';
$hiddenfields .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'category', 'id' => 'qbankcategory'));
$hiddenfields .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $course->id));
foreach ($hiddenparams as $k => $v) {
$hiddenfields .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => $k, 'value' => $v));
}
$hiddenfields .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
$formcontent .= html_writer::div($hiddenfields, '', array('id' => 'typeformdiv'));
// Put everything into one tag 'options'.
$formcontent .= html_writer::start_tag('div', array('class' => 'options'));
$formcontent .= html_writer::div(get_string('selectaqtypefordescription', 'question'), 'instruction');
// Put all options into one tag 'qoptions' to allow us to handle scrolling.
$formcontent .= html_writer::start_tag('div', array('class' => 'alloptions'));
// First display real questions.
$formcontent .= $this->qbank_chooser_title('questions', 'question');
$formcontent .= $this->qbank_chooser_types($real);
$formcontent .= html_writer::div('', 'separator');
// Then fake questions.
$formcontent .= $this->qbank_chooser_title('other');
$formcontent .= $this->qbank_chooser_types($fake);
// Options.
$formcontent .= html_writer::end_tag('div');
// Types.
$formcontent .= html_writer::end_tag('div');
// Add the form submission buttons.
$submitbuttons = '';
$submitbuttons .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'submitbutton', 'class' => 'submitbutton', 'value' => get_string('add')));
$submitbuttons .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'addcancel', 'class' => 'addcancel', 'value' => get_string('cancel')));
$formcontent .= html_writer::div($submitbuttons, 'submitbuttons');
$formcontent .= html_writer::end_tag('form');
// Wrap the whole form in a div.
$formcontent = html_writer::tag('div', $formcontent, array('id' => 'chooseform'));
// Generate the header and return the whole form.
$header = html_writer::div(get_string('chooseqtypetoadd', 'question'), 'choosertitle hd');
return $header . html_writer::div(html_writer::div($formcontent, 'choosercontainer'), 'chooserdialogue');
}
/**
* Build the HTML for a specified set of question types.
*
* @param array $types A set of question types as used by the qbank_chooser_module function
* @return string The composed HTML for the module
*/
protected function qbank_chooser_types($types) {
$return = '';
foreach ($types as $type) {
$return .= $this->qbank_chooser_qtype($type);
}
return $return;
}
/**
* Return the HTML for the specified question type, adding any required classes.
*
* @param object $qtype An object containing the title, and link. An icon, and help text may optionally be specified.
* If the module contains subtypes in the types option, then these will also be displayed.
* @param array $classes Additional classes to add to the encompassing div element
* @return string The composed HTML for the question type
*/
protected function qbank_chooser_qtype($qtype, $classes = array()) {
$output = '';
$classes[] = 'option';
$output .= html_writer::start_tag('div', array('class' => implode(' ', $classes)));
$output .= html_writer::start_tag('label', array('for' => 'qtype_' . $qtype->plugin_name()));
$output .= html_writer::tag('input', '', array('type' => 'radio',
'name' => 'qtype', 'id' => 'qtype_' . $qtype->plugin_name(), 'value' => $qtype->name()));
$output .= html_writer::start_tag('span', array('class' => 'modicon'));
// Add an icon if we have one.
$output .= $this->pix_icon('icon', $qtype->local_name(), $qtype->plugin_name(),
array('title' => $qtype->local_name(), 'class' => 'icon'));
$output .= html_writer::end_tag('span');
$output .= html_writer::span($qtype->menu_name(), 'typename');
// Format the help text using markdown with the following options.
$options = new stdClass();
$options->trusted = false;
$options->noclean = false;
$options->smiley = false;
$options->filter = false;
$options->para = true;
$options->newlines = false;
$options->overflowdiv = false;
$qtype->help = format_text(get_string('pluginnamesummary', $qtype->plugin_name()), FORMAT_MARKDOWN, $options);
$output .= html_writer::span($qtype->help, 'typesummary');
$output .= html_writer::end_tag('label');
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Return the title for the question bank chooser.
*
* @param string $title The language string identifier
* @param string $identifier The component identifier
* @return string The composed HTML for the title
*/
protected function qbank_chooser_title($title, $identifier = null) {
$span = html_writer::span('', 'modicon');
$span .= html_writer::span(get_string($title, $identifier), 'typename');
return html_writer::div($span, 'option moduletypetitle');
}
}

View File

@ -0,0 +1,47 @@
YUI.add('moodle-question-chooser', function (Y, NAME) {
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.one(SELECTORS.CREATENEWQUESTIONFORM).on('submit', this.displayQuestionChooser, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue"]});

View File

@ -0,0 +1 @@
YUI.add("moodle-question-chooser",function(e,t){function r(){r.superclass.constructor.apply(this,arguments)}var n={CREATENEWQUESTION:"div.createnewquestion",CREATENEWQUESTIONFORM:"div.createnewquestion form",CHOOSERDIALOGUE:"div.chooserdialogue",CHOOSERHEADER:"div.choosertitle",QBANKCATEGORY:"#qbankcategory"};e.extend(r,M.core.chooserdialogue,{initializer:function(){e.one(n.CREATENEWQUESTIONFORM).on("submit",this.displayQuestionChooser,this)},displayQuestionChooser:function(t){var r=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERDIALOGUE),i=e.one(n.CREATENEWQUESTION+" "+n.CHOOSERHEADER);this.container===null&&(this.setup_chooser_dialogue(r,i,{}),this.prepare_chooser()),this.container.one(n.QBANKCATEGORY).set("value",e.one(n.CREATENEWQUESTIONFORM).get("category").get("value")),this.display_chooser(t)}},{NAME:"questionChooser"}),M.question=M.question||{},M.question.init_chooser=function(e){return new r(e)}},"@VERSION@",{requires:["moodle-core-chooserdialogue"]});

View File

@ -0,0 +1,47 @@
YUI.add('moodle-question-chooser', function (Y, NAME) {
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.one(SELECTORS.CREATENEWQUESTIONFORM).on('submit', this.displayQuestionChooser, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};
}, '@VERSION@', {"requires": ["moodle-core-chooserdialogue"]});

View File

@ -0,0 +1,107 @@
YUI.add('moodle-question-qbankmanager', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Question Bank Management.
*
* @package question
* @copyright 2014 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Questionbank Management.
*
* @module moodle-question-qbankmanager
*/
/**
* Question Bank Management.
*
* @class M.question.qbankmanager
*/
var manager = {
/**
* A reference to the header checkbox.
*
* @property _header
* @type Node
* @private
*/
_header: null,
/**
* The ID of the first checkbox on the page.
*
* @property _firstCheckboxId
* @type String
* @private
*/
_firstCheckboxId: null,
/**
* Set up the Question Bank Manager.
*
* @method init
* @param {String} firstCheckboxId The ID of the first checkbox on the page.
*/
init: function(firstCheckboxId) {
// Find the header checkbox, and set the initial values.
this._header = Y.one('#qbheadercheckbox');
this._header.setAttrs({
disabled: false,
title: M.util.get_string('selectall', 'moodle')
});
this._header.on('click', this._headerClick, this);
// Store the first checkbox details.
this._firstCheckboxId = firstCheckboxId;
},
/**
* Handle toggling of the header checkbox.
*
* @method _headerClick
* @private
*/
_headerClick: function() {
// Get the list of questions we affect.
var categoryQuestions = Y.one('#categoryquestions')
.all('[type=checkbox],[type=radio]');
// We base the state of all of the questions on the state of the first.
firstCheckbox = Y.one('#' + this._firstCheckboxId);
if (firstCheckbox.get('checked')) {
categoryQuestions.set('checked', false);
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
} else {
categoryQuestions.set('checked', true);
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
}
this._header.set('checked', false);
}
};
M.question = M.question || {};
M.question.qbankmanager = M.question.qbankmanager || manager;
}, '@VERSION@', {"requires": ["node", "selector-css3"]});

View File

@ -0,0 +1 @@
YUI.add("moodle-question-qbankmanager",function(e,t){var n={_header:null,_firstCheckboxId:null,init:function(t){this._header=e.one("#qbheadercheckbox"),this._header.setAttrs({disabled:!1,title:M.util.get_string("selectall","moodle")}),this._header.on("click",this._headerClick,this),this._firstCheckboxId=t},_headerClick:function(){var t=e.one("#categoryquestions").all("[type=checkbox],[type=radio]");firstCheckbox=e.one("#"+this._firstCheckboxId),firstCheckbox.get("checked")?(t.set("checked",!1),this._header.setAttribute("title",M.util.get_string("selectall","moodle"))):(t.set("checked",!0),this._header.setAttribute("title",M.util.get_string("deselectall","moodle"))),this._header.set("checked",!1)}};M.question=M.question||{},M.question.qbankmanager=M.question.qbankmanager||n},"@VERSION@",{requires:["node","selector-css3"]});

View File

@ -0,0 +1,107 @@
YUI.add('moodle-question-qbankmanager', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Question Bank Management.
*
* @package question
* @copyright 2014 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Questionbank Management.
*
* @module moodle-question-qbankmanager
*/
/**
* Question Bank Management.
*
* @class M.question.qbankmanager
*/
var manager = {
/**
* A reference to the header checkbox.
*
* @property _header
* @type Node
* @private
*/
_header: null,
/**
* The ID of the first checkbox on the page.
*
* @property _firstCheckboxId
* @type String
* @private
*/
_firstCheckboxId: null,
/**
* Set up the Question Bank Manager.
*
* @method init
* @param {String} firstCheckboxId The ID of the first checkbox on the page.
*/
init: function(firstCheckboxId) {
// Find the header checkbox, and set the initial values.
this._header = Y.one('#qbheadercheckbox');
this._header.setAttrs({
disabled: false,
title: M.util.get_string('selectall', 'moodle')
});
this._header.on('click', this._headerClick, this);
// Store the first checkbox details.
this._firstCheckboxId = firstCheckboxId;
},
/**
* Handle toggling of the header checkbox.
*
* @method _headerClick
* @private
*/
_headerClick: function() {
// Get the list of questions we affect.
var categoryQuestions = Y.one('#categoryquestions')
.all('[type=checkbox],[type=radio]');
// We base the state of all of the questions on the state of the first.
firstCheckbox = Y.one('#' + this._firstCheckboxId);
if (firstCheckbox.get('checked')) {
categoryQuestions.set('checked', false);
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
} else {
categoryQuestions.set('checked', true);
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
}
this._header.set('checked', false);
}
};
M.question = M.question || {};
M.question.qbankmanager = M.question.qbankmanager || manager;
}, '@VERSION@', {"requires": ["node", "selector-css3"]});

View File

@ -0,0 +1,10 @@
{
"name": "moodle-question-chooser",
"builds": {
"moodle-question-chooser": {
"jsfiles": [
"chooser.js"
]
}
}
}

42
question/yui/src/chooser/js/chooser.js vendored Normal file
View File

@ -0,0 +1,42 @@
var SELECTORS = {
CREATENEWQUESTION: 'div.createnewquestion',
CREATENEWQUESTIONFORM: 'div.createnewquestion form',
CHOOSERDIALOGUE: 'div.chooserdialogue',
CHOOSERHEADER: 'div.choosertitle',
QBANKCATEGORY: '#qbankcategory'
};
function Chooser() {
Chooser.superclass.constructor.apply(this, arguments);
}
Y.extend(Chooser, M.core.chooserdialogue, {
initializer: function() {
Y.one(SELECTORS.CREATENEWQUESTIONFORM).on('submit', this.displayQuestionChooser, this);
},
displayQuestionChooser: function(e) {
var dialogue = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERDIALOGUE),
header = Y.one(SELECTORS.CREATENEWQUESTION + ' ' + SELECTORS.CHOOSERHEADER);
if (this.container === null) {
// Setup the dialogue, and then prepare the chooser if it's not already been set up.
this.setup_chooser_dialogue(dialogue, header, {});
this.prepare_chooser();
}
// Set the category ID in the form - this may have been updated since the dialogue
// was previously displayed so we must update it here.
this.container.one(SELECTORS.QBANKCATEGORY).set('value',
Y.one(SELECTORS.CREATENEWQUESTIONFORM).get('category').get('value'));
// Display the chooser dialogue.
this.display_chooser(e);
}
}, {
NAME: 'questionChooser'
});
M.question = M.question || {};
M.question.init_chooser = function(config) {
return new Chooser(config);
};

View File

@ -0,0 +1,7 @@
{
"moodle-question-chooser": {
"requires": [
"moodle-core-chooserdialogue"
]
}
}

View File

@ -0,0 +1,10 @@
{
"name": "moodle-question-qbankmanager",
"builds": {
"moodle-question-qbankmanager": {
"jsfiles": [
"qbankmanager.js"
]
}
}
}

View File

@ -0,0 +1,102 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Question Bank Management.
*
* @package question
* @copyright 2014 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Questionbank Management.
*
* @module moodle-question-qbankmanager
*/
/**
* Question Bank Management.
*
* @class M.question.qbankmanager
*/
var manager = {
/**
* A reference to the header checkbox.
*
* @property _header
* @type Node
* @private
*/
_header: null,
/**
* The ID of the first checkbox on the page.
*
* @property _firstCheckboxId
* @type String
* @private
*/
_firstCheckboxId: null,
/**
* Set up the Question Bank Manager.
*
* @method init
* @param {String} firstCheckboxId The ID of the first checkbox on the page.
*/
init: function(firstCheckboxId) {
// Find the header checkbox, and set the initial values.
this._header = Y.one('#qbheadercheckbox');
this._header.setAttrs({
disabled: false,
title: M.util.get_string('selectall', 'moodle')
});
this._header.on('click', this._headerClick, this);
// Store the first checkbox details.
this._firstCheckboxId = firstCheckboxId;
},
/**
* Handle toggling of the header checkbox.
*
* @method _headerClick
* @private
*/
_headerClick: function() {
// Get the list of questions we affect.
var categoryQuestions = Y.one('#categoryquestions')
.all('[type=checkbox],[type=radio]');
// We base the state of all of the questions on the state of the first.
firstCheckbox = Y.one('#' + this._firstCheckboxId);
if (firstCheckbox.get('checked')) {
categoryQuestions.set('checked', false);
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
} else {
categoryQuestions.set('checked', true);
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
}
this._header.set('checked', false);
}
};
M.question = M.question || {};
M.question.qbankmanager = M.question.qbankmanager || manager;

View File

@ -0,0 +1,8 @@
{
"moodle-question-qbankmanager": {
"requires": [
"node",
"selector-css3"
]
}
}

View File

@ -1241,7 +1241,7 @@ sup {vertical-align: super;}
}
/* Only set these options if we're showing the js container */
.jsenabled .choosercontainer #chooseform .alloptions {
.jschooser .choosercontainer #chooseform .alloptions {
overflow-x: hidden;
overflow-y: auto;
max-width: 20.3em;
@ -1249,7 +1249,7 @@ sup {vertical-align: super;}
-webkit-box-shadow: inset 0px 0px 30px 0px #CCCCCC;
-moz-box-shadow: inset 0px 0px 30px 0px #CCCCCC;
}
.dir-rtl.jsenabled .choosercontainer #chooseform .alloptions {
.dir-rtl.jschooser .choosercontainer #chooseform .alloptions {
max-width: 18.3em;
}
@ -1323,8 +1323,8 @@ sup {vertical-align: super;}
}
/* The instruction/help area */
.jsenabled .choosercontainer #chooseform .instruction,
.jsenabled .choosercontainer #chooseform .typesummary {
.jschooser .choosercontainer #chooseform .instruction,
.jschooser .choosercontainer #chooseform .typesummary {
display: none;
position: absolute;
top: 0px;
@ -1339,15 +1339,15 @@ sup {vertical-align: super;}
line-height: 2em;
}
.dir-rtl.jsenabled .choosercontainer #chooseform .instruction,
.dir-rtl.jsenabled .choosercontainer #chooseform .typesummary {
.dir-rtl.jschooser .choosercontainer #chooseform .instruction,
.dir-rtl.jschooser .choosercontainer #chooseform .typesummary {
left: 0px;
right: 18.5em;
border-right: 1px solid grey;
}
/* Selected option settings */
.jsenabled .choosercontainer #chooseform .instruction,
.jschooser .choosercontainer #chooseform .instruction,
.choosercontainer #chooseform .selected .typesummary {
display: block;
}

View File

@ -56,6 +56,11 @@
.questionbank .singleselect { margin: 0; }
/* Question editing forms. */
#page-question-addquestion #chooserdialogue,
#page-question-addquestion #choosertitle {
display: block;
}
#combinedfeedbackhdr div.fhtmleditor {padding: 0;}
#combinedfeedbackhdr div.fcheckbox {margin-bottom: 1em;}

View File

@ -1684,13 +1684,13 @@ body#page-lib-editor-tinymce-plugins-moodlemedia-preview {
border-bottom: 1px solid #BBBBBB;
}
/* Only set these options if we're showing the js container */
.jsenabled .choosercontainer #chooseform .alloptions {
.jschooser .choosercontainer #chooseform .alloptions {
overflow-x: hidden;
overflow-y: auto;
max-width: 20.3em;
.box-shadow(inset 0 0 30px 0px #ccc);
}
.dir-rtl.jsenabled .choosercontainer #chooseform .alloptions {
.dir-rtl.jschooser .choosercontainer #chooseform .alloptions {
max-width: 18.3em;
}
/* Settings for option rows and option subtypes */
@ -1755,8 +1755,8 @@ body#page-lib-editor-tinymce-plugins-moodlemedia-preview {
margin: 0 0.2em 0 0;
}
/* The instruction/help area */
.jsenabled .choosercontainer #chooseform .instruction,
.jsenabled .choosercontainer #chooseform .typesummary {
.jschooser .choosercontainer #chooseform .instruction,
.jschooser .choosercontainer #chooseform .typesummary {
display: none;
position: absolute;
top: 0;
@ -1770,14 +1770,14 @@ body#page-lib-editor-tinymce-plugins-moodlemedia-preview {
overflow-y: auto;
line-height: 2em;
}
.dir-rtl.jsenabled .choosercontainer #chooseform .instruction,
.dir-rtl.jsenabled .choosercontainer #chooseform .typesummary {
.dir-rtl.jschooser .choosercontainer #chooseform .instruction,
.dir-rtl.jschooser .choosercontainer #chooseform .typesummary {
left: 0;
right: 18.5em;
border-right: 1px solid grey;
}
/* Selected option settings */
.jsenabled .choosercontainer #chooseform .instruction,
.jschooser .choosercontainer #chooseform .instruction,
.choosercontainer #chooseform .selected .typesummary {
display: block;
}

File diff suppressed because one or more lines are too long