Merge branch 'MDL-61138-master-require-context-id' of git://github.com/ryanwyllie/moodle

This commit is contained in:
David Monllao
2018-04-19 11:18:47 +02:00
60 changed files with 4176 additions and 407 deletions
+13 -2
View File
@@ -37,6 +37,8 @@ require_once($CFG->libdir.'/formslib.php');
class quiz_add_random_form extends moodleform {
protected function definition() {
global $OUTPUT, $PAGE;
$mform =& $this->_form;
$mform->setDisableShortforms();
@@ -44,7 +46,7 @@ class quiz_add_random_form extends moodleform {
$usablecontexts = $contexts->having_cap('moodle/question:useall');
// Random from existing category section.
$mform->addElement('header', 'categoryheader',
$mform->addElement('header', 'existingcategoryheader',
get_string('randomfromexistingcategory', 'quiz'));
$mform->addElement('questioncategory', 'category', get_string('category'),
@@ -71,10 +73,13 @@ class quiz_add_random_form extends moodleform {
$mform->addElement('select', 'numbertoadd', get_string('randomnumber', 'quiz'),
$this->get_number_of_questions_to_add_choices());
$previewhtml = $OUTPUT->render_from_template('mod_quiz/random_question_form_preview', []);
$mform->addElement('html', $previewhtml);
$mform->addElement('submit', 'existingcategory', get_string('addrandomquestion', 'quiz'));
// Random from a new category section.
$mform->addElement('header', 'categoryheader',
$mform->addElement('header', 'newcategoryheader',
get_string('randomquestionusinganewcategory', 'quiz'));
$mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="50"');
@@ -97,6 +102,12 @@ class quiz_add_random_form extends moodleform {
$mform->setType('cmid', PARAM_INT);
$mform->addElement('hidden', 'returnurl', 0);
$mform->setType('returnurl', PARAM_LOCALURL);
// Add the javascript required to enhance this mform.
$PAGE->requires->js_call_amd('mod_quiz/add_random_form', 'init', [
$mform->getAttribute('id'),
$contexts->lowest()->id
]);
}
public function validation($fromform, $files) {
+1
View File
@@ -0,0 +1 @@
define(["jquery","core/notification","core/modal_factory"],function(a,b,c){return{init:function(d,e,f,g){var h=a("body");return c.create({type:d,large:!0,preShowCallback:function(b,c){b=a(b),c.setContextId(f),c.setAddOnPageId(b.attr("data-addonpage")),c.setTitle(b.attr("data-header")),g&&g(b,c)}},[h,e]).fail(b.exception)}}});
+1
View File
@@ -0,0 +1 @@
define(["jquery","mod_quiz/random_question_form_preview"],function(a,b){var c=2e3,d={PREVIEW_CONTAINER:'[data-region="random-question-preview-container"]',CATEGORY_FORM_ELEMENT:'[name="category"]',SUBCATEGORY_FORM_ELEMENT:'[name="includesubcategories"]',TAG_IDS_FORM_ELEMENT:'[name="fromtags[]"]'},e=function(a){var b=a.find(d.CATEGORY_FORM_ELEMENT).val(),c=b.split(",");return c[0]},f=function(a){return a.find(d.SUBCATEGORY_FORM_ELEMENT).is(":checked")},g=function(a){var b=a.find(d.TAG_IDS_FORM_ELEMENT).val();return b.map(function(a){var b=a.split(",");return b[0]})},h=function(a,c){var h=a.find(d.PREVIEW_CONTAINER);b.reload(h,e(a),f(a),g(a),c)},i=function(a){return a.closest(d.CATEGORY_FORM_ELEMENT).length>0||(a.closest(d.SUBCATEGORY_FORM_ELEMENT).length>0||a.closest(d.TAG_IDS_FORM_ELEMENT).length>0)},j=function(d,e){var f=null;d.on("change",function(g){i(a(g.target))&&(b.showLoadingIcon(d),f&&clearTimeout(f),f=setTimeout(function(){h(d,e)},c))})},k=function(b,c){var d=a("#"+b);h(d,c),j(d,c)};return{init:k}});
+1
View File
@@ -0,0 +1 @@
define(["mod_quiz/add_question_modal_launcher","mod_quiz/modal_add_random_question"],function(a,b){return{init:function(c,d,e,f){a.init(b.TYPE,'.menu [data-action="addarandomquestion"]',c,function(a,b){b.setCategory(d),b.setReturnUrl(e),b.setCMID(f)})}}});
+1
View File
@@ -0,0 +1 @@
define(["jquery","core/yui","core/notification","core/modal","core/modal_events","core/modal_registry","core/fragment","core/templates"],function(a,b,c,d,e,f,g,h){var i=!1,j={EXISTING_CATEGORY_CONTAINER:'[data-region="existing-category-container"]',EXISTING_CATEGORY_FORM_ELEMENT:"#id_existingcategoryheader",NEW_CATEGORY_CONTAINER:'[data-region="new-category-container"]',NEW_CATEGORY_FORM_ELEMENT:"#id_newcategoryheader",TAB_CONTENT:'[data-region="tab-content"]',ADD_ON_PAGE_FORM_ELEMENT:'[name="addonpage"]',SUBMIT_BUTTON_ELEMENT:'input[type="submit"]',CANCEL_BUTTON_ELEMENT:'input[type="submit"][name="cancel"]',FORM_HEADER:"legend",BUTTON_CONTAINER:".fitem"},k=function(a){d.call(this,a),this.contextId=null,this.addOnPageId=null,this.category=null,this.returnUrl=null,this.cmid=null,this.loadedForm=!1};return k.TYPE="mod_quiz-quiz-add-random-question",k.prototype=Object.create(d.prototype),k.prototype.constructor=k,k.prototype.setContextId=function(a){this.contextId=a},k.prototype.getContextId=function(){return this.contextId},k.prototype.setAddOnPageId=function(a){this.addOnPageId=a,this.getBody().find(j.ADD_ON_PAGE_FORM_ELEMENT).val(a)},k.prototype.getAddOnPageId=function(){return this.addOnPageId},k.prototype.setCategory=function(a){this.category=a},k.prototype.getCategory=function(){return this.category},k.prototype.setReturnUrl=function(a){this.returnUrl=a},k.prototype.getReturnUrl=function(){return this.returnUrl},k.prototype.setCMID=function(a){this.cmid=a},k.prototype.getCMID=function(){return this.cmid},k.prototype.moveFormElementIntoTab=function(b,c){var d=b.find(j.SUBMIT_BUTTON_ELEMENT),e=a('<div class="modal-footer m-t-1" data-region="footer"></div>');b.find(j.FORM_HEADER).addClass("hidden"),b.wrap(c),d.closest(j.BUTTON_CONTAINER).remove(),d.appendTo(e),e.appendTo(b)},k.prototype.moveTabsIntoTabContent=function(a){var b=this.getBody().find(j.TAB_CONTENT).empty();a.find('[role="tabpanel"]').wrapAll(b)},k.prototype.moveCancelButtonToTabs=function(a){var b=a.find(j.CANCEL_BUTTON_ELEMENT).addClass("m-l-1"),c=a.find('[data-region="footer"]');b.closest(j.BUTTON_CONTAINER).remove(),b.clone().appendTo(c)},k.prototype.loadForm=function(){return g.loadFragment("mod_quiz","add_random_question_form",this.getContextId(),{addonpage:this.getAddOnPageId(),cat:this.getCategory(),returnurl:this.getReturnUrl(),cmid:this.getCMID()}).then(function(b,c){var d=a(b),e=d.find(j.EXISTING_CATEGORY_FORM_ELEMENT),f=this.getBody().find(j.EXISTING_CATEGORY_CONTAINER),g=d.find(j.NEW_CATEGORY_FORM_ELEMENT),i=this.getBody().find(j.NEW_CATEGORY_CONTAINER);this.moveFormElementIntoTab(e,f),this.moveFormElementIntoTab(g,i),this.moveTabsIntoTabContent(d),this.moveCancelButtonToTabs(d),h.replaceNode(this.getBody().find(j.TAB_CONTENT),d,c)}.bind(this)).then(function(){b.use("moodle-core-formchangechecker",function(){M.core_formchangechecker.reset_form_dirty_state()})}).fail(c.exception)},k.prototype.show=function(){d.prototype.show.call(this),this.loadedForm||(this.loadForm(),this.loadedForm=!0)},i||(f.register(k.TYPE,k,"mod_quiz/modal_add_random_question"),i=!0),k});
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/notification","core/custom_interaction_events","core/modal_factory","mod_quiz/modal_quiz_question_bank"],function(a,b,c,d,e){var f={ADD_QUESTION_LINKS:'.menu [data-action="questionbank"]'};return{init:function(g){var h=a("body");d.create({type:e.TYPE,large:!0},[h,f.ADD_QUESTION_LINKS]).then(function(b){return b.setContextId(g),h.on(c.events.activate,f.ADD_QUESTION_LINKS,function(c){var d=a(c.target).closest(f.ADD_QUESTION_LINKS);b.setAddOnPageId(d.attr("data-addonpage")),b.setTitle(d.attr("data-header"))}),b}).fail(b.exception)}}});
define(["mod_quiz/add_question_modal_launcher","mod_quiz/modal_quiz_question_bank"],function(a,b){return{init:function(c){a.init(b.TYPE,'.menu [data-action="questionbank"]',c)}}});
@@ -0,0 +1 @@
define(["jquery","core/ajax","core/str","core/notification","core/templates","core/paged_content_factory"],function(a,b,c,d,e,f){var g=5,h="mod_quiz/random_question_form_preview_question_list",i={LOADING_ICON_CONTAINER:'[data-region="overlay-icon-container"]',QUESTION_COUNT_CONTAINER:'[data-region="question-count-container"]',QUESTION_LIST_CONTAINER:'[data-region="question-list-container"]'},j=function(a){a.find(i.LOADING_ICON_CONTAINER).removeClass("hidden")},k=function(a){a.find(i.LOADING_ICON_CONTAINER).addClass("hidden")},l=function(a,b){c.get_string("questionsmatchingfilter","mod_quiz",b).then(function(b){a.find(i.QUESTION_COUNT_CONTAINER).html(b)}).fail(d.exception)},m=function(a,c,d,e,f,g){var h={methodname:"core_question_get_random_question_summaries",args:{categoryid:a,includesubcategories:c,tagids:d,contextid:e,limit:f,offset:g}};return b.call([h])[0]},n=function(a,b,c,i,j,k){return f.createFromAjax(j,g,function(f){return f.map(function(f){var g=f.limit,j=f.offset;return 0==j?e.render(h,{questions:k}):m(a,b,c,i,g,j).then(function(a){var b=a.questions;return e.render(h,{questions:b})}).fail(d.exception)})})},o=function(b,c,f,h,o){return j(b),m(c,f,h,o,g,0).then(function(a){var c=a.totalcount;return l(b,c),a}).then(function(b){var d=b.totalcount,e=b.questions;return e.length?n(c,f,h,o,d,e):a.Deferred().resolve("","")}).then(function(a,c){var d=b.find(i.QUESTION_LIST_CONTAINER);e.replaceNodeContents(d,a,c)}).always(function(){k(b)}).fail(d.exception)};return{reload:o,showLoadingIcon:j,hideLoadingIcon:k}});
@@ -0,0 +1,78 @@
// 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/>.
/**
* Initialise the an add question modal on the quiz page.
*
* @module mod_quiz/add_question_modal_launcher
* @package mod_quiz
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(
[
'jquery',
'core/notification',
'core/modal_factory',
],
function(
$,
Notification,
ModalFactory
) {
return {
/**
* Create a modal using the modal factory and add listeners to launch the
* modal when clicked.
*
* @param {string} modalType Which modal to create
* @param {string} selector The selectors for the elements that trigger the modal
* @param {int} contextId The current context id
* @param {function} preShowCallback A callback to execute before the modal is shown
* @return {promise} Resolved with the modal
*/
init: function(modalType, selector, contextId, preShowCallback) {
var body = $('body');
// Create a question bank modal using the factory.
// The same modal will be used by all of the add question
// links that match "selector" on the page. The content
// of the modal will be changed depending on which link is
// clicked.
return ModalFactory.create(
{
type: modalType,
large: true,
// This callback executes before the modal is shown when the
// trigger element is clicked.
preShowCallback: function(triggerElement, modal) {
triggerElement = $(triggerElement);
modal.setContextId(contextId);
modal.setAddOnPageId(triggerElement.attr('data-addonpage'));
modal.setTitle(triggerElement.attr('data-header'));
if (preShowCallback) {
preShowCallback(triggerElement, modal);
}
}
},
// Created a deligated listener rather than a single
// trigger element.
[body, selector]
).fail(Notification.exception);
}
};
});
+185
View File
@@ -0,0 +1,185 @@
// 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 for the add_random_form class.
*
* @module mod_quiz/add_random_form
* @package mod_quiz
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(
[
'jquery',
'mod_quiz/random_question_form_preview'
],
function(
$,
RandomQuestionFormPreview
) {
// Wait 2 seconds before reloading the question set just in case
// the user is still changing the criteria.
var RELOAD_DELAY = 2000;
var SELECTORS = {
PREVIEW_CONTAINER: '[data-region="random-question-preview-container"]',
CATEGORY_FORM_ELEMENT: '[name="category"]',
SUBCATEGORY_FORM_ELEMENT: '[name="includesubcategories"]',
TAG_IDS_FORM_ELEMENT: '[name="fromtags[]"]'
};
/**
* Get the category id from the form.
*
* @param {jquery} form The form element.
* @return {string} The category id.
*/
var getCategoryId = function(form) {
// The value string is the category id and category context id joined
// by a comma.
var valueString = form.find(SELECTORS.CATEGORY_FORM_ELEMENT).val();
// Split the two ids.
var values = valueString.split(',');
// Return just the category id.
return values[0];
};
/**
* Check if the form indicates we should include include subcategories in
* the filter.
*
* @param {jquery} form The form element.
* @return {bool}
*/
var shouldIncludeSubcategories = function(form) {
return form.find(SELECTORS.SUBCATEGORY_FORM_ELEMENT).is(':checked');
};
/**
* Get the tag ids for the selected tags in the form.
*
* @param {jquery} form The form element.
* @return {string[]} The tag ids.
*/
var getTagIds = function(form) {
var values = form.find(SELECTORS.TAG_IDS_FORM_ELEMENT).val();
return values.map(function(value) {
// The tag element value is the tag id and tag name joined
// by a comma. So we need to split them to get the tag id.
var parts = value.split(',');
return parts[0];
});
};
/**
* Reload the preview section with a new set of filters.
*
* @param {jquery} form The form element.
* @param {int} contextId The current context id.
*/
var reloadQuestionPreview = function(form, contextId) {
var previewContainer = form.find(SELECTORS.PREVIEW_CONTAINER);
RandomQuestionFormPreview.reload(
previewContainer,
getCategoryId(form),
shouldIncludeSubcategories(form),
getTagIds(form),
contextId
);
};
/**
* Is this an element we're interested in listening to changes on.
*
* @param {jquery} element The element to check.
* @return {bool}
*/
var isInterestingElement = function(element) {
if (element.closest(SELECTORS.CATEGORY_FORM_ELEMENT).length > 0) {
return true;
}
if (element.closest(SELECTORS.SUBCATEGORY_FORM_ELEMENT).length > 0) {
return true;
}
if (element.closest(SELECTORS.TAG_IDS_FORM_ELEMENT).length > 0) {
return true;
}
return false;
};
/**
* Listen for changes to any of the interesting elements and reload the form
* preview with the new filter values if they are changed.
*
* The reload is delayed for a small amount of time (see RELOAD_DELAY) in case
* the user is actively editing the form. This allows us to avoid having to
* send multiple requests to the server on each change.
*
* Instead we can just send a single request when the user appears to have
* finished editing the form.
*
* @param {jquery} form The form element.
* @param {int} contextId The current context id.
*/
var addEventListeners = function(form, contextId) {
var reloadTimerId = null;
form.on('change', function(e) {
// Only reload the preview when elements that will change the result
// are modified.
if (!isInterestingElement($(e.target))) {
return;
}
// Show the loading icon to let the user know that the preview
// will be updated after their actions.
RandomQuestionFormPreview.showLoadingIcon(form);
if (reloadTimerId) {
// Reset the timer each time the form is modified.
clearTimeout(reloadTimerId);
}
// Don't immediately reload the question preview section just
// in case the user is still modifying the form. We don't want to
// spam reload requests.
reloadTimerId = setTimeout(function() {
reloadQuestionPreview(form, contextId);
}, RELOAD_DELAY);
});
};
/**
* Trigger the first load of the preview section and then listen for modifications
* to the form to reload the preview with new filter values.
*
* @param {jquery} formId The form element id.
* @param {int} contextId The current context id.
*/
var init = function(formId, contextId) {
var form = $('#' + formId);
reloadQuestionPreview(form, contextId);
addEventListeners(form, contextId);
};
return {
init: init
};
});
+57
View File
@@ -0,0 +1,57 @@
// 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/>.
/**
* Initialise the add random question modal on the quiz page.
*
* @module mod_quiz/add_random_question
* @package mod_quiz
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(
[
'mod_quiz/add_question_modal_launcher',
'mod_quiz/modal_add_random_question'
],
function(
AddQuestionModalLauncher,
ModalAddRandomQuestion
) {
return {
/**
* Create the add random question modal.
*
* @param {int} contextId Current context id.
* @param {string} category Category id and category context id comma separated.
* @param {string} returnUrl URL to return to after form submission.
* @param {int} cmid Current course module id.
*/
init: function(contextId, category, returnUrl, cmid) {
AddQuestionModalLauncher.init(
ModalAddRandomQuestion.TYPE,
'.menu [data-action="addarandomquestion"]',
contextId,
// Additional values that should be set before the modal is shown.
function(triggerElement, modal) {
modal.setCategory(category);
modal.setReturnUrl(returnUrl);
modal.setCMID(cmid);
}
);
}
};
});
@@ -0,0 +1,315 @@
// 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/>.
/**
* Contain the logic for the add random question modal.
*
* @module mod_quiz/modal_add_random_question
* @package mod_quiz
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([
'jquery',
'core/yui',
'core/notification',
'core/modal',
'core/modal_events',
'core/modal_registry',
'core/fragment',
'core/templates',
],
function(
$,
Y,
Notification,
Modal,
ModalEvents,
ModalRegistry,
Fragment,
Templates
) {
var registered = false;
var SELECTORS = {
EXISTING_CATEGORY_CONTAINER: '[data-region="existing-category-container"]',
EXISTING_CATEGORY_FORM_ELEMENT: '#id_existingcategoryheader',
NEW_CATEGORY_CONTAINER: '[data-region="new-category-container"]',
NEW_CATEGORY_FORM_ELEMENT: '#id_newcategoryheader',
TAB_CONTENT: '[data-region="tab-content"]',
ADD_ON_PAGE_FORM_ELEMENT: '[name="addonpage"]',
SUBMIT_BUTTON_ELEMENT: 'input[type="submit"]',
CANCEL_BUTTON_ELEMENT: 'input[type="submit"][name="cancel"]',
FORM_HEADER: 'legend',
BUTTON_CONTAINER: '.fitem'
};
/**
* Constructor for the Modal.
*
* @param {object} root The root jQuery element for the modal
*/
var ModalAddRandomQuestion = function(root) {
Modal.call(this, root);
this.contextId = null;
this.addOnPageId = null;
this.category = null;
this.returnUrl = null;
this.cmid = null;
this.loadedForm = false;
};
ModalAddRandomQuestion.TYPE = 'mod_quiz-quiz-add-random-question';
ModalAddRandomQuestion.prototype = Object.create(Modal.prototype);
ModalAddRandomQuestion.prototype.constructor = ModalAddRandomQuestion;
/**
* Save the Moodle context id that the question bank is being
* rendered in.
*
* @method setContextId
* @param {int} id
*/
ModalAddRandomQuestion.prototype.setContextId = function(id) {
this.contextId = id;
};
/**
* Retrieve the saved Moodle context id.
*
* @method getContextId
* @return {int}
*/
ModalAddRandomQuestion.prototype.getContextId = function() {
return this.contextId;
};
/**
* Set the id of the page that the question should be added to
* when the user clicks the add to quiz link.
*
* @method setAddOnPageId
* @param {int} id
*/
ModalAddRandomQuestion.prototype.setAddOnPageId = function(id) {
this.addOnPageId = id;
this.getBody().find(SELECTORS.ADD_ON_PAGE_FORM_ELEMENT).val(id);
};
/**
* Returns the saved page id for the question to be added to.
*
* @method getAddOnPageId
* @return {int}
*/
ModalAddRandomQuestion.prototype.getAddOnPageId = function() {
return this.addOnPageId;
};
/**
* Set the category for this form. The category is a comma separated
* category id and category context id.
*
* @method setCategory
* @param {string} category
*/
ModalAddRandomQuestion.prototype.setCategory = function(category) {
this.category = category;
};
/**
* Returns the saved category.
*
* @method getCategory
* @return {string}
*/
ModalAddRandomQuestion.prototype.getCategory = function() {
return this.category;
};
/**
* Set the return URL for the form.
*
* @method setReturnUrl
* @param {string} url
*/
ModalAddRandomQuestion.prototype.setReturnUrl = function(url) {
this.returnUrl = url;
};
/**
* Returns the return URL for the form.
*
* @method getReturnUrl
* @return {string}
*/
ModalAddRandomQuestion.prototype.getReturnUrl = function() {
return this.returnUrl;
};
/**
* Set the course module id for the form.
*
* @method setCMID
* @param {int} id
*/
ModalAddRandomQuestion.prototype.setCMID = function(id) {
this.cmid = id;
};
/**
* Returns the course module id for the form.
*
* @method getCMID
* @return {int}
*/
ModalAddRandomQuestion.prototype.getCMID = function() {
return this.cmid;
};
/**
* Moves a given form element inside (a child of) a given tab element.
*
* Hides the 'legend' (e.g. header) element of the form element because the
* tab has the name.
*
* Moves the submit button into a footer element at the bottom of the form
* element for styling purposes.
*
* @method moveFormElementIntoTab
* @param {jquery} formElement The form element to move into the tab.
* @param {jquey} tabElement The tab element for the form element to move into.
*/
ModalAddRandomQuestion.prototype.moveFormElementIntoTab = function(formElement, tabElement) {
var submitButtons = formElement.find(SELECTORS.SUBMIT_BUTTON_ELEMENT);
var footer = $('<div class="modal-footer m-t-1" data-region="footer"></div>');
// Hide the header because the tabs show us which part of the form we're
// looking at.
formElement.find(SELECTORS.FORM_HEADER).addClass('hidden');
// Move the element inside a tab.
formElement.wrap(tabElement);
// Remove the buttons container element.
submitButtons.closest(SELECTORS.BUTTON_CONTAINER).remove();
// Put the button inside a footer.
submitButtons.appendTo(footer);
// Add the footer to the end of the category form element.
footer.appendTo(formElement);
};
/**
* Empty the tab content container and move all tabs from the form into the
* tab container element.
*
* @method moveTabsIntoTabContent
* @param {jquery} form The form element.
*/
ModalAddRandomQuestion.prototype.moveTabsIntoTabContent = function(form) {
// Empty it to remove the loading icon.
var tabContent = this.getBody().find(SELECTORS.TAB_CONTENT).empty();
// Make sure all tabs are inside the tab content element.
form.find('[role="tabpanel"]').wrapAll(tabContent);
};
/**
* Make sure all of the tabs have a cancel button in their fotter to sit along
* side the submit button.
*
* @method moveCancelButtonToTabs
* @param {jquey} form The form element.
*/
ModalAddRandomQuestion.prototype.moveCancelButtonToTabs = function(form) {
var cancelButton = form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass('m-l-1');
var tabFooters = form.find('[data-region="footer"]');
// Remove the buttons container element.
cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove();
cancelButton.clone().appendTo(tabFooters);
};
/**
* Load the add random question form in a fragement and perform some transformation
* on the HTML to convert it into tabs for rendering in the modal.
*
* @method loadForm
* @return {promise} Resolved with form HTML and JS.
*/
ModalAddRandomQuestion.prototype.loadForm = function() {
return Fragment.loadFragment(
'mod_quiz',
'add_random_question_form',
this.getContextId(),
{
addonpage: this.getAddOnPageId(),
cat: this.getCategory(),
returnurl: this.getReturnUrl(),
cmid: this.getCMID()
}
)
.then(function(html, js) {
var form = $(html);
var existingCategoryFormElement = form.find(SELECTORS.EXISTING_CATEGORY_FORM_ELEMENT);
var existingCategoryTab = this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER);
var newCategoryFormElement = form.find(SELECTORS.NEW_CATEGORY_FORM_ELEMENT);
var newCategoryTab = this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);
// Transform the form into tabs for better rendering in the modal.
this.moveFormElementIntoTab(existingCategoryFormElement, existingCategoryTab);
this.moveFormElementIntoTab(newCategoryFormElement, newCategoryTab);
this.moveTabsIntoTabContent(form);
this.moveCancelButtonToTabs(form);
Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT), form, js);
return;
}.bind(this))
.then(function() {
// Make sure the form change checker is disabled otherwise it'll
// stop the user from navigating away from the page once the modal
// is hidden.
Y.use('moodle-core-formchangechecker', function() {
M.core_formchangechecker.reset_form_dirty_state();
});
return;
})
.fail(Notification.exception);
};
/**
* Override the modal show function to load the form when this modal is first
* shown.
*
* @method show
*/
ModalAddRandomQuestion.prototype.show = function() {
Modal.prototype.show.call(this);
if (!this.loadedForm) {
this.loadForm();
this.loadedForm = true;
}
};
// Automatically register with the modal registry the first time this module is
// imported so that you can create modals of this type using the modal factory.
if (!registered) {
ModalRegistry.register(
ModalAddRandomQuestion.TYPE,
ModalAddRandomQuestion,
'mod_quiz/modal_add_random_question'
);
registered = true;
}
return ModalAddRandomQuestion;
});
+12 -41
View File
@@ -23,55 +23,26 @@
*/
define(
[
'jquery',
'core/notification',
'core/custom_interaction_events',
'core/modal_factory',
'mod_quiz/add_question_modal_launcher',
'mod_quiz/modal_quiz_question_bank'
],
function(
$,
Notification,
CustomEvents,
ModalFactory,
AddQuestionModalLauncher,
ModalQuizQuestionBank
) {
var SELECTORS = {
ADD_QUESTION_LINKS: '.menu [data-action="questionbank"]',
};
return {
/**
* Create the question bank modal.
*
* @param {int} contextId Current context id.
*/
init: function(contextId) {
var body = $('body');
// Create a question bank modal using the factory.
// The same modal will be used by all of the add question
// links on the page. The content of the modal will be
// changed depending on which link is clicked.
ModalFactory.create(
{
type: ModalQuizQuestionBank.TYPE,
large: true
},
// Created a deligated listener rather than a single
// trigger element.
[body, SELECTORS.ADD_QUESTION_LINKS]
).then(function(modal) {
// Save the Moodle context id that the modal is being rendered in.
modal.setContextId(contextId);
body.on(CustomEvents.events.activate, SELECTORS.ADD_QUESTION_LINKS, function(e) {
// We need to listen for activations on the trigger elements because there are
// several on the page and we need to know which one was activated in order to
// set some relevant data on the modal.
var triggerElement = $(e.target).closest(SELECTORS.ADD_QUESTION_LINKS);
modal.setAddOnPageId(triggerElement.attr('data-addonpage'));
modal.setTitle(triggerElement.attr('data-header'));
});
return modal;
}).fail(Notification.exception);
AddQuestionModalLauncher.init(
ModalQuizQuestionBank.TYPE,
'.menu [data-action="questionbank"]',
contextId
);
}
};
});
@@ -0,0 +1,235 @@
// 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 for the random_question_form_preview of the
* add_random_form class.
*
* @module mod_quiz/random_question_form_preview
* @package mod_quiz
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(
[
'jquery',
'core/ajax',
'core/str',
'core/notification',
'core/templates',
'core/paged_content_factory'
],
function(
$,
Ajax,
Str,
Notification,
Templates,
PagedContentFactory
) {
var ITEMS_PER_PAGE = 5;
var TEMPLATE_NAME = 'mod_quiz/random_question_form_preview_question_list';
var SELECTORS = {
LOADING_ICON_CONTAINER: '[data-region="overlay-icon-container"]',
QUESTION_COUNT_CONTAINER: '[data-region="question-count-container"]',
QUESTION_LIST_CONTAINER: '[data-region="question-list-container"]'
};
/**
* Show the loading spinner over the preview section.
*
* @param {jquery} root The root element.
*/
var showLoadingIcon = function(root) {
root.find(SELECTORS.LOADING_ICON_CONTAINER).removeClass('hidden');
};
/**
* Hide the loading spinner.
*
* @param {jquery} root The root element.
*/
var hideLoadingIcon = function(root) {
root.find(SELECTORS.LOADING_ICON_CONTAINER).addClass('hidden');
};
/**
* Render the section of text to show the question count.
*
* @param {jquery} root The root element.
* @param {int} questionCount The number of questions.
*/
var renderQuestionCount = function(root, questionCount) {
Str.get_string('questionsmatchingfilter', 'mod_quiz', questionCount)
.then(function(string) {
root.find(SELECTORS.QUESTION_COUNT_CONTAINER).html(string);
return;
})
.fail(Notification.exception);
};
/**
* Send a request to the server for more questions.
*
* @param {int} categoryId A question category id.
* @param {bool} includeSubcategories If the results should include subcategory questions
* @param {int[]} tagIds The list of tag ids that each question must have.
* @param {int} contextId The context where the questions will be added.
* @param {int} limit How many questions to retrieve.
* @param {int} offset How many questions to skip from the start of the result set.
* @return {promise} Resolved when the preview section has rendered.
*/
var requestQuestions = function(
categoryId,
includeSubcategories,
tagIds,
contextId,
limit,
offset
) {
var request = {
methodname: 'core_question_get_random_question_summaries',
args: {
categoryid: categoryId,
includesubcategories: includeSubcategories,
tagids: tagIds,
contextid: contextId,
limit: limit,
offset: offset
}
};
return Ajax.call([request])[0];
};
/**
* Build a paged content widget for questions with the given criteria. The
* criteria is used to fetch more questions from the server as the user
* requests new pages.
*
* @param {int} categoryId A question category id.
* @param {bool} includeSubcategories If the results should include subcategory questions
* @param {int[]} tagIds The list of tag ids that each question must have.
* @param {int} contextId The context where the questions will be added.
* @param {int} totalQuestionCount How many questions match the criteria above.
* @param {object[]} firstPageQuestions List of questions for the first page.
* @return {promise} A promise resolved with the HTML and JS for the paged content.
*/
var renderQuestionsAsPagedContent = function(
categoryId,
includeSubcategories,
tagIds,
contextId,
totalQuestionCount,
firstPageQuestions
) {
// Provide a callback, renderQuestionsPages,
// to control how the questions on each page are rendered.
return PagedContentFactory.createFromAjax(
totalQuestionCount,
ITEMS_PER_PAGE,
// Callback function to render the requested pages.
function(pagesData) {
return pagesData.map(function(pageData) {
var limit = pageData.limit;
var offset = pageData.offset;
if (offset == 0) {
// The first page is being requested and we've already got
// that data so we can just render it immediately.
return Templates.render(TEMPLATE_NAME, {questions: firstPageQuestions});
} else {
// Otherwise we need to ask the server for the data.
return requestQuestions(
categoryId,
includeSubcategories,
tagIds,
contextId,
limit,
offset
)
.then(function(response) {
var questions = response.questions;
return Templates.render(TEMPLATE_NAME, {questions: questions});
})
.fail(Notification.exception);
}
});
}
);
};
/**
* Re-render the preview section based on the provided filter criteria.
*
* @param {jquery} root The root element.
* @param {int} categoryId A question category id.
* @param {bool} includeSubcategories If the results should include subcategory questions
* @param {int[]} tagIds The list of tag ids that each question must have.
* @param {int} contextId The context where the questions will be added.
* @return {promise} Resolved when the preview section has rendered.
*/
var reload = function(root, categoryId, includeSubcategories, tagIds, contextId) {
// Show the loading spinner to tell the user that something is happening.
showLoadingIcon(root);
// Load the first set of questions.
return requestQuestions(categoryId, includeSubcategories, tagIds, contextId, ITEMS_PER_PAGE, 0)
.then(function(response) {
var totalCount = response.totalcount;
// Show the help message for the user to indicate how many questions
// match their filter criteria.
renderQuestionCount(root, totalCount);
return response;
})
.then(function(response) {
var totalQuestionCount = response.totalcount;
var questions = response.questions;
if (questions.length) {
// We received some questions so render them as paged content
// with a paging bar.
return renderQuestionsAsPagedContent(
categoryId,
includeSubcategories,
tagIds,
contextId,
totalQuestionCount,
questions
);
} else {
// If we didn't receive any questions then we can return empty
// HTML and JS to clear the preview section.
return $.Deferred().resolve('', '');
}
})
.then(function(html, js) {
// Show the user the question set.
var container = root.find(SELECTORS.QUESTION_LIST_CONTAINER);
Templates.replaceNodeContents(container, html, js);
return;
})
.always(function() {
hideLoadingIcon(root);
})
.fail(Notification.exception);
};
return {
reload: reload,
showLoadingIcon: showLoadingIcon,
hideLoadingIcon: hideLoadingIcon
};
});
+8 -31
View File
@@ -98,17 +98,17 @@ class edit_renderer extends \plugin_renderer_base {
// Include the contents of any other popups required.
if ($structure->can_be_edited()) {
$popups = '';
$thiscontext = $contexts->lowest();
$this->page->requires->js_call_amd('mod_quiz/quizquestionbank', 'init', [
$contexts->lowest()->id
$thiscontext->id
]);
$popups .= $this->random_question_form($pageurl, $contexts, $pagevars);
$this->page->requires->yui_module('moodle-mod_quiz-randomquestion',
'M.mod_quiz.randomquestion.init');
$output .= html_writer::div($popups, 'mod_quiz_edit_forms');
$this->page->requires->js_call_amd('mod_quiz/add_random_question', 'init', [
$thiscontext->id,
$pagevars['cat'],
$pageurl->out_as_local_url(true),
$pageurl->param('cmid')
]);
// Include the question chooser.
$output .= $this->question_chooser();
@@ -1059,29 +1059,6 @@ class edit_renderer extends \plugin_renderer_base {
return html_writer::div($this->pix_icon('i/loading', get_string('loading')), 'questionbankloading');
}
/**
* Return random question form.
* @param \moodle_url $thispageurl the canonical URL of this page.
* @param \question_edit_contexts $contexts the relevant question bank contexts.
* @param array $pagevars the variables from {@link \question_edit_setup()}.
* @return string HTML to output.
*/
protected function random_question_form(\moodle_url $thispageurl, \question_edit_contexts $contexts, array $pagevars) {
if (!$contexts->have_cap('moodle/question:useall')) {
return '';
}
$randomform = new \quiz_add_random_form(new \moodle_url('/mod/quiz/addrandom.php'),
array('contexts' => $contexts, 'cat' => $pagevars['cat']));
$randomform->set_data(array(
'category' => $pagevars['cat'],
'returnurl' => $thispageurl->out_as_local_url(true),
'randomnumber' => 1,
'cmid' => $thispageurl->param('cmid'),
));
return html_writer::div($randomform->render(), 'randomquestionformforpopup');
}
/**
* Initialise the JavaScript for the general editing. (JavaScript for popups
* is handled with the specific code for those.)
+4
View File
@@ -341,6 +341,7 @@ $string['eventreportviewed'] = 'Quiz report viewed';
$string['everynquestions'] = 'Every {$a} questions';
$string['everyquestion'] = 'Every question';
$string['everythingon'] = 'Everything on';
$string['existingcategory'] = 'Existing category';
$string['exportcategory'] = 'export category';
$string['exporterror'] = 'An error occurred during export processing';
$string['exportingquestions'] = 'Questions are being exported to file';
@@ -509,6 +510,7 @@ $string['navmethod_seq'] = 'Sequential';
$string['navnojswarning'] = 'Warning: these links will not save your answers. Use the next button at the bottom of the page.';
$string['neverallononepage'] = 'Never, all questions on one page';
$string['newattemptfail'] = 'Error: Could not start a new attempt at the quiz';
$string['newcategory'] = 'New category';
$string['newpage'] = 'New page';
$string['newpage_help'] = 'For longer quizzes it makes sense to stretch the quiz over several pages by limiting the number of questions per page. When adding questions to the quiz, page breaks will automatically be inserted according to this setting. However page breaks may later be moved manually on the editing page.';
$string['newpageevery'] = 'Automatically start a new page';
@@ -649,8 +651,10 @@ $string['questionnotloaded'] = 'Question {$a} has not been loaded from the datab
$string['questionorder'] = 'Question order';
$string['questionposition'] = 'New position in order for question {$a}';
$string['questions'] = 'Questions';
$string['questionsetpreview'] = 'Question set preview';
$string['questionsinclhidden'] = 'Questions (including hidden)';
$string['questionsinthisquiz'] = 'Questions in this quiz';
$string['questionsmatchingfilter'] = 'Questions matching this filter: {$a}';
$string['questionsperpage'] = 'Questions per page';
$string['questionsperpageselected'] = 'Questions per page has been set so the paging is currently fixed. As a result, the paging controls have been disabled. You can change this in {$a}.';
$string['questionsperpagex'] = 'Questions per page: {$a}';
+44 -1
View File
@@ -2406,7 +2406,7 @@ function mod_quiz_core_calendar_event_timestart_updated(\calendar_event $event,
}
/**
* Generates the question bank in a fargment output. This allows
* Generates the question bank in a fragment output. This allows
* the question bank to be displayed in a modal.
*
* The only expected argument provided in the $args array is
@@ -2445,3 +2445,46 @@ function mod_quiz_output_fragment_quiz_question_bank($args) {
$renderer = $PAGE->get_renderer('mod_quiz', 'edit');
return $renderer->question_bank_contents($questionbank, $pagevars);
}
/**
* Generates the add random question in a fragment output. This allows the
* form to be rendered in javascript, for example inside a modal.
*
* The required arguments as keys in the $args array are:
* cat {string} The category and category context ids comma separated.
* addonpage {int} The page id to add this question to.
* returnurl {string} URL to return to after form submission.
* cmid {int} The course module id the questions are being added to.
*
* @param array $args The fragment arguments.
* @return string The rendered mform fragment.
*/
function mod_quiz_output_fragment_add_random_question_form($args) {
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/addrandomform.php');
$contexts = new \question_edit_contexts($args['context']);
$formoptions = [
'contexts' => $contexts,
'cat' => $args['cat']
];
$formdata = [
'category' => $args['cat'],
'addonpage' => $args['addonpage'],
'returnurl' => $args['returnurl'],
'cmid' => $args['cmid']
];
$form = new quiz_add_random_form(
new \moodle_url('/mod/quiz/addrandom.php'),
$formoptions,
'post',
'',
null,
true,
$formdata
);
$form->set_data($formdata);
return $form->render();
}
@@ -0,0 +1,75 @@
{{!
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/>.
}}
{{!
@template mod_quiz/modal_add_random_question
Modal for adding a random question to a quiz activity.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* title A cleaned string (use clean_text()) to display.
* body HTML content for the boday
Example context (json):
{
"title": "Example modal",
"body": "Some example content for the body"
}
}}
{{< core/modal }}
{{$body}}
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active"
data-toggle="tab"
href="#existing-category-{{uniqid}}"
role="tab">
{{#str}} existingcategory, mod_quiz {{/str}}
</a>
</li>
<li class="nav-item">
<a class="nav-link"
data-toggle="tab"
href="#new-category-{{uniqid}}"
role="tab">
{{#str}} newcategory, mod_quiz {{/str}}
</a>
</li>
</ul>
<div class="tab-content" data-region="tab-content">
<div class="text-sm-center p-t-2" data-region="loading-container">
{{> core/loading }}
</div>
<div class="tab-pane active p-t-1"
id="existing-category-{{uniqid}}"
role="tabpanel"
data-region="existing-category-container">
</div>
<div class="tab-pane p-t-1"
id="new-category-{{uniqid}}"
role="tabpanel"
data-region="new-category-container">
</div>
</div>
{{/body}}
{{/ core/modal }}
@@ -0,0 +1,40 @@
{{!
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/>.
}}
{{!
@template mod_quiz/random_question_form_preview
A preview section for the list of questions that match the random
question criteria in the random question form.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* title A cleaned string (use clean_text()) to display.
* body HTML content for the boday
Example context (json):
{}
}}
<div class="m-t-2 position-relative" data-region="random-question-preview-container">
<div data-region="question-count-container"></div>
<div data-region="question-list-container"></div>
{{< core/overlay_loading }}{{$hiddenclass}}{{/hiddenclass}}{{/ core/overlay_loading }}
</div>
@@ -0,0 +1,58 @@
{{!
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/>.
}}
{{!
@template mod_quiz/random_question_form_preview_question_list
A preview section for the list of questions that match the random
question criteria in the random question form.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* title A cleaned string (use clean_text()) to display.
* body HTML content for the boday
Example context (json):
{
"questions": [
{
"name":"Example question 1"
},
{
"name":"Example question 2"
},
{
"name":"Example question 3"
},
{
"name":"Example question 4"
}
]
}
}}
<ul class="list-group" data-region="question-list">
{{#questions}}
<li class="list-group-item text-truncate">
{{#icon}}{{#pix}} {{key}}, {{component}}, {{{alttext}}} {{/pix}}{{/icon}}
{{name}}
</li>
{{/questions}}
</ul>
@@ -1,85 +0,0 @@
YUI.add('moodle-mod_quiz-randomquestion', 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/>.
/**
* Add a random question functionality for a popup in quiz editing page.
*
* @package mod_quiz
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
RANDOMQUESTIONFORM: 'div.randomquestionformforpopup',
PAGEHIDDENINPUT: 'input#rform_qpage',
RANDOMQUESTIONLINKS: '.menu [data-action="addarandomquestion"]'
};
var PARAMS = {
PAGE: 'addonpage',
HEADER: 'header',
FORM: 'form'
};
var POPUP = function() {
POPUP.superclass.constructor.apply(this, arguments);
};
Y.extend(POPUP, Y.Base, {
dialogue: function(header) {
// Create a dialogue on the page and hide it.
var config = {
headerContent: header,
bodyContent: Y.one(CSS.RANDOMQUESTIONFORM),
draggable: true,
modal: true,
zIndex: 1000,
centered: false,
width: 'auto',
visible: false,
postmethod: 'form',
footerContent: null
};
var popup = {dialog: null};
popup.dialog = new M.core.dialogue(config);
popup.dialog.show();
},
initializer: function() {
Y.one('body').delegate('click', this.display_dialogue, CSS.RANDOMQUESTIONLINKS, this);
},
display_dialogue: function(e) {
e.preventDefault();
Y.one(CSS.RANDOMQUESTIONFORM + ' ' + CSS.PAGEHIDDENINPUT).set('value',
e.currentTarget.getData(PARAMS.PAGE));
this.dialogue(e.currentTarget.getData(PARAMS.HEADER));
}
});
M.mod_quiz = M.mod_quiz || {};
M.mod_quiz.randomquestion = M.mod_quiz.randomquestion || {};
M.mod_quiz.randomquestion.init = function() {
return new POPUP();
};
}, '@VERSION@', {"requires": ["base", "event", "node", "io", "moodle-core-notification-dialogue"]});
@@ -1 +0,0 @@
YUI.add("moodle-mod_quiz-randomquestion",function(e,t){var n={RANDOMQUESTIONFORM:"div.randomquestionformforpopup",PAGEHIDDENINPUT:"input#rform_qpage",RANDOMQUESTIONLINKS:'.menu [data-action="addarandomquestion"]'},r={PAGE:"addonpage",HEADER:"header",FORM:"form"},i=function(){i.superclass.constructor.apply(this,arguments)};e.extend(i,e.Base,{dialogue:function(t){var r={headerContent:t,bodyContent:e.one(n.RANDOMQUESTIONFORM),draggable:!0,modal:!0,zIndex:1e3,centered:!1,width:"auto",visible:!1,postmethod:"form",footerContent:null},i={dialog:null};i.dialog=new M.core.dialogue(r),i.dialog.show()},initializer:function(){e.one("body").delegate("click",this.display_dialogue,n.RANDOMQUESTIONLINKS,this)},display_dialogue:function(t){t.preventDefault(),e.one(n.RANDOMQUESTIONFORM+" "+n.PAGEHIDDENINPUT).set("value",t.currentTarget.getData(r.PAGE)),this.dialogue(t.currentTarget.getData(r.HEADER))}}),M.mod_quiz=M.mod_quiz||{},M.mod_quiz.randomquestion=M.mod_quiz.randomquestion||{},M.mod_quiz.randomquestion.init=function(){return new i}},"@VERSION@",{requires:["base","event","node","io","moodle-core-notification-dialogue"]});
@@ -1,85 +0,0 @@
YUI.add('moodle-mod_quiz-randomquestion', 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/>.
/**
* Add a random question functionality for a popup in quiz editing page.
*
* @package mod_quiz
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
RANDOMQUESTIONFORM: 'div.randomquestionformforpopup',
PAGEHIDDENINPUT: 'input#rform_qpage',
RANDOMQUESTIONLINKS: '.menu [data-action="addarandomquestion"]'
};
var PARAMS = {
PAGE: 'addonpage',
HEADER: 'header',
FORM: 'form'
};
var POPUP = function() {
POPUP.superclass.constructor.apply(this, arguments);
};
Y.extend(POPUP, Y.Base, {
dialogue: function(header) {
// Create a dialogue on the page and hide it.
var config = {
headerContent: header,
bodyContent: Y.one(CSS.RANDOMQUESTIONFORM),
draggable: true,
modal: true,
zIndex: 1000,
centered: false,
width: 'auto',
visible: false,
postmethod: 'form',
footerContent: null
};
var popup = {dialog: null};
popup.dialog = new M.core.dialogue(config);
popup.dialog.show();
},
initializer: function() {
Y.one('body').delegate('click', this.display_dialogue, CSS.RANDOMQUESTIONLINKS, this);
},
display_dialogue: function(e) {
e.preventDefault();
Y.one(CSS.RANDOMQUESTIONFORM + ' ' + CSS.PAGEHIDDENINPUT).set('value',
e.currentTarget.getData(PARAMS.PAGE));
this.dialogue(e.currentTarget.getData(PARAMS.HEADER));
}
});
M.mod_quiz = M.mod_quiz || {};
M.mod_quiz.randomquestion = M.mod_quiz.randomquestion || {};
M.mod_quiz.randomquestion.init = function() {
return new POPUP();
};
}, '@VERSION@', {"requires": ["base", "event", "node", "io", "moodle-core-notification-dialogue"]});
@@ -1,10 +0,0 @@
{
"name": "moodle-mod_quiz-randomquestion",
"builds": {
"moodle-mod_quiz-randomquestion": {
"jsfiles": [
"randomquestion.js"
]
}
}
}
-80
View File
@@ -1,80 +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/>.
/**
* Add a random question functionality for a popup in quiz editing page.
*
* @package mod_quiz
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
RANDOMQUESTIONFORM: 'div.randomquestionformforpopup',
PAGEHIDDENINPUT: 'input#rform_qpage',
RANDOMQUESTIONLINKS: '.menu [data-action="addarandomquestion"]'
};
var PARAMS = {
PAGE: 'addonpage',
HEADER: 'header',
FORM: 'form'
};
var POPUP = function() {
POPUP.superclass.constructor.apply(this, arguments);
};
Y.extend(POPUP, Y.Base, {
dialogue: function(header) {
// Create a dialogue on the page and hide it.
var config = {
headerContent: header,
bodyContent: Y.one(CSS.RANDOMQUESTIONFORM),
draggable: true,
modal: true,
zIndex: 1000,
centered: false,
width: 'auto',
visible: false,
postmethod: 'form',
footerContent: null
};
var popup = {dialog: null};
popup.dialog = new M.core.dialogue(config);
popup.dialog.show();
},
initializer: function() {
Y.one('body').delegate('click', this.display_dialogue, CSS.RANDOMQUESTIONLINKS, this);
},
display_dialogue: function(e) {
e.preventDefault();
Y.one(CSS.RANDOMQUESTIONFORM + ' ' + CSS.PAGEHIDDENINPUT).set('value',
e.currentTarget.getData(PARAMS.PAGE));
this.dialogue(e.currentTarget.getData(PARAMS.HEADER));
}
});
M.mod_quiz = M.mod_quiz || {};
M.mod_quiz.randomquestion = M.mod_quiz.randomquestion || {};
M.mod_quiz.randomquestion.init = function() {
return new POPUP();
};
@@ -1,11 +0,0 @@
{
"moodle-mod_quiz-randomquestion": {
"requires": [
"base",
"event",
"node",
"io",
"moodle-core-notification-dialogue"
]
}
}