AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"modal_quiz_question_bank.min.js","sources":["../src/modal_quiz_question_bank.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Contain the logic for the question bank modal.\n *\n * @module mod_quiz/modal_quiz_question_bank\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copylef
t/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Modal from './add_question_modal';\nimport * as Fragment from 'core/fragment';\nimport * as FormChangeChecker from 'core_form/changechecker';\nimport * as ModalEvents from 'core/modal_events';\n\nconst SELECTORS = {\n ADD_TO_QUIZ_CONTAINER: 'td.addtoquizaction',\n ANCHOR: 'a[href]',\n PREVIEW_CONTAINER: 'td.previewquestionaction',\n ADD_QUESTIONS_FORM: 'form#questionsubmit',\n SORTERS: '.sorters',\n};\n\nexport default class ModalQuizQuestionBank extends Modal {\n static TYPE = 'mod_quiz-quiz-question-bank';\n\n /**\n * Create the question bank modal.\n *\n * @param {Number} contextId Current context id.\n */\n static init(contextId) {\n const selector = '.menu [data-action=\"questionbank\"]';\n document.addEventListener('click', (e) => {\n const trigger = e.target.closest(selector);\n if (!trigger) {\n return;\n }\n e.preventD
efault();\n\n ModalQuizQuestionBank.create({\n contextId,\n title: trigger.dataset.header,\n addOnPage: trigger.dataset.addonpage,\n templateContext: {\n hidden: true,\n },\n large: true,\n });\n });\n }\n\n /**\n * Override the parent show function.\n *\n * Reload the body contents when the modal is shown. The current\n * window URL is used to inform the new content that should be\n * displayed.\n *\n * @method show\n * @return {void}\n */\n show() {\n this.reloadBodyContent(window.location.search);\n return super.show(this);\n }\n\n /**\n * Replaces the current body contents with a new version of the question\n * bank.\n *\n * The contents of the question bank are generated using the provided\n * query string.\n *\n * @method reloadBodyContent\n * @param {string} querystring
URL encoded string.\n */\n reloadBodyContent(querystring) {\n // Load the question bank fragment to be displayed in the modal.\n this.setBody(Fragment.loadFragment(\n 'mod_quiz',\n 'quiz_question_bank',\n this.getContextId(),\n {\n querystring,\n }\n ));\n }\n\n /**\n * Update the URL of the anchor element that the user clicked on to make\n * sure that the question is added to the correct page.\n *\n * @method handleAddToQuizEvent\n * @param {event} e A JavaScript event\n * @param {object} anchorElement The anchor element that was triggered\n */\n handleAddToQuizEvent(e, anchorElement) {\n // If the user clicks the plus icon to add the question to the page\n // directly then we need to intercept the click in order to adjust the\n // href and include the correct add on page id before the page is\n // redirected.\n const href = new URL(anchorE
lement.attr('href'));\n href.searchParams.set('addonpage', this.getAddOnPageId());\n anchorElement.attr('href', href);\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n // Apply parent event listeners.\n super.registerEventListeners(this);\n\n this.getModal().on('submit', SELECTORS.ADD_QUESTIONS_FORM, (e) => {\n // If the user clicks on the \"Add selected questions to the quiz\" button to add some questions to the page\n // then we need to intercept the submit in order to include the correct \"add on page id\" before the form is\n // submitted.\n const formElement = $(e.currentTarget);\n\n $('<input />').attr('type', 'hidden')\n .attr('name', \"addonpage\")\n .attr('value', this.getAddOnPageId())\n .appendTo(formElement);\n });\n\n this.getModal().on
('click', SELECTORS.ANCHOR, (e) => {\n const anchorElement = $(e.currentTarget);\n\n // If the anchor element was the add to quiz link.\n if (anchorElement.closest(SELECTORS.ADD_TO_QUIZ_CONTAINER).length) {\n this.handleAddToQuizEvent(e, anchorElement);\n return;\n }\n\n // If the anchor element was a preview question link.\n if (anchorElement.closest(SELECTORS.PREVIEW_CONTAINER).length) {\n return;\n }\n\n // Sorting links have their own handler.\n if (anchorElement.closest(SELECTORS.SORTERS).length) {\n return;\n }\n\n // Anything else means reload the pop-up contents.\n e.preventDefault();\n this.reloadBodyContent(anchorElement.prop('search'));\n });\n\n // Disable the form change checker when the body is rendered.\n this.getRoot().on(ModalEvents.bodyRendered, () => {\n // M
ake sure the form change checker is disabled otherwise it'll stop the user from navigating away from the\n // page once the modal is hidden.\n FormChangeChecker.disableAllChecks();\n });\n }\n}\n\nModalQuizQuestionBank.registerModalType();\n"],"names":["SELECTORS","ModalQuizQuestionBank","Modal","contextId","document","addEventListener","e","trigger","target","closest","preventDefault","create","title","dataset","header","addOnPage","addonpage","templateContext","hidden","large","show","reloadBodyContent","window","location","search","super","this","querystring","setBody","Fragment","loadFragment","getContextId","handleAddToQuizEvent","anchorElement","href","URL","attr","searchParams","set","getAddOnPageId","registerEventListeners","getModal","on","formElement","currentTarget","appendTo","length","prop","getRoot","ModalEvents","bodyRendered","FormChangeChecker","disableAllChecks","registerModalType"],"mappings":"4kDA6BMA,gCACqB,qBADrBA,iBAEM,UAFNA,4BAGiB,2BAHjBA,6BAIkB,sBAJlBA
,kBAKO,iBAGQC,8BAA8BC,wCAQnCC,WAERC,SAASC,iBAAiB,SAAUC,UAC1BC,QAAUD,EAAEE,OAAOC,QAFZ,sCAGRF,UAGLD,EAAEI,iBAEFT,sBAAsBU,OAAO,CACzBR,UAAAA,UACAS,MAAOL,QAAQM,QAAQC,OACvBC,UAAWR,QAAQM,QAAQG,UAC3BC,gBAAiB,CACbC,QAAQ,GAEZC,OAAO,QAenBC,mBACSC,kBAAkBC,OAAOC,SAASC,QAChCC,MAAML,KAAKM,MAatBL,kBAAkBM,kBAETC,QAAQC,SAASC,aAClB,WACA,qBACAJ,KAAKK,eACL,CACIJ,YAAAA,eAaZK,qBAAqB1B,EAAG2B,qBAKdC,KAAO,IAAIC,IAAIF,cAAcG,KAAK,SACxCF,KAAKG,aAAaC,IAAI,YAAaZ,KAAKa,kBACxCN,cAAcG,KAAK,OAAQF,MAQ/BM,+BAEUA,uBAAuBd,WAExBe,WAAWC,GAAG,SAAU1C,8BAA+BM,UAIlDqC,aAAc,mBAAErC,EAAEsC,mCAEtB,aAAaR,KAAK,OAAQ,UACvBA,KAAK,OAAQ,aACbA,KAAK,QAASV,KAAKa,kBACnBM,SAASF,qBAGbF,WAAWC,GAAG,QAAS1C,kBAAmBM,UACrC2B,eAAgB,mBAAE3B,EAAEsC,eAGtBX,cAAcxB,QAAQT,iCAAiC8C,YAClDd,qBAAqB1B,EAAG2B,eAK7BA,cAAcxB,QAAQT,6BAA6B8C,QAKnDb,cAAcxB,QAAQT,mBAAmB8C,SAK7CxC,EAAEI,sBACGW,kBAAkBY,cAAcc,KAAK,oBAIzCC,UAAUN,GAAGO,YAAYC,cAAc,KAGxCC,kBAAkBC,6FApIZ,iDADGnD,6HA0IrBA,sBAAsBoD"}