AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"random_question_form_preview.min.js","sources":["../src/random_question_form_preview.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 * JavaScript for the random_question_form_preview of the\n * add_random_form class.\n *\n * @module mod_quiz/random_question_form_preview\n * @copyright 2018 Ryan Wyllie <ryan@moodle.co
m>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'jquery',\n 'core/ajax',\n 'core/str',\n 'core/notification',\n 'core/templates',\n 'core/paged_content_factory'\n ],\n function(\n $,\n Ajax,\n Str,\n Notification,\n Templates,\n PagedContentFactory\n ) {\n\n var ITEMS_PER_PAGE = 5;\n var TEMPLATE_NAME = 'mod_quiz/random_question_form_preview_question_list';\n var SELECTORS = {\n LOADING_ICON_CONTAINER: '[data-region=\"overlay-icon-container\"]',\n QUESTION_COUNT_CONTAINER: '[data-region=\"question-count-container\"]',\n QUESTION_LIST_CONTAINER: '[data-region=\"question-list-container\"]'\n };\n\n /**\n * Show the loading spinner over the preview section.\n *\n * @param {jquery} root The root element.\n */\n var showLoadingIcon = function(root) {\n root.find(SELECTORS.LOADING_ICON_CONTAINER).removeClass('hi
dden');\n };\n\n /**\n * Hide the loading spinner.\n *\n * @param {jquery} root The root element.\n */\n var hideLoadingIcon = function(root) {\n root.find(SELECTORS.LOADING_ICON_CONTAINER).addClass('hidden');\n };\n\n /**\n * Render the section of text to show the question count.\n *\n * @param {jquery} root The root element.\n * @param {int} questionCount The number of questions.\n */\n var renderQuestionCount = function(root, questionCount) {\n Str.get_string('questionsmatchingfilter', 'mod_quiz', questionCount)\n .then(function(string) {\n root.find(SELECTORS.QUESTION_COUNT_CONTAINER).html(string);\n return;\n })\n .fail(Notification.exception);\n };\n\n /**\n * Send a request to the server for more questions.\n *\n * @param {int} categoryId A question category id.\n * @param {bool} includeSubcategories If the results should include subcategory ques
tions\n * @param {int[]} tagIds The list of tag ids that each question must have.\n * @param {int} contextId The context where the questions will be added.\n * @param {int} limit How many questions to retrieve.\n * @param {int} offset How many questions to skip from the start of the result set.\n * @return {promise} Resolved when the preview section has rendered.\n */\n var requestQuestions = function(\n categoryId,\n includeSubcategories,\n tagIds,\n contextId,\n limit,\n offset\n ) {\n var request = {\n methodname: 'core_question_get_random_question_summaries',\n args: {\n categoryid: categoryId,\n includesubcategories: includeSubcategories,\n tagids: tagIds,\n contextid: contextId,\n limit: limit,\n offset: offset\n }\n };\n\n return Ajax.call([request])[0];\n };\n\n /**\n * Buil
d a paged content widget for questions with the given criteria. The\n * criteria is used to fetch more questions from the server as the user\n * requests new pages.\n *\n * @param {int} categoryId A question category id.\n * @param {bool} includeSubcategories If the results should include subcategory questions\n * @param {int[]} tagIds The list of tag ids that each question must have.\n * @param {int} contextId The context where the questions will be added.\n * @param {int} totalQuestionCount How many questions match the criteria above.\n * @param {object[]} firstPageQuestions List of questions for the first page.\n * @return {promise} A promise resolved with the HTML and JS for the paged content.\n */\n var renderQuestionsAsPagedContent = function(\n categoryId,\n includeSubcategories,\n tagIds,\n contextId,\n totalQuestionCount,\n firstPageQuestions\n ) {\n // Provide a callback, renderQuestionsPages,\n
// to control how the questions on each page are rendered.\n return PagedContentFactory.createFromAjax(\n totalQuestionCount,\n ITEMS_PER_PAGE,\n // Callback function to render the requested pages.\n function(pagesData) {\n return pagesData.map(function(pageData) {\n var limit = pageData.limit;\n var offset = pageData.offset;\n\n if (offset == 0) {\n // The first page is being requested and we've already got\n // that data so we can just render it immediately.\n return Templates.render(TEMPLATE_NAME, {questions: firstPageQuestions});\n } else {\n // Otherwise we need to ask the server for the data.\n return requestQuestions(\n categoryId,\n includeSubcategories,\n tagI
ds,\n contextId,\n limit,\n offset\n )\n .then(function(response) {\n var questions = response.questions;\n return Templates.render(TEMPLATE_NAME, {questions: questions});\n })\n .fail(Notification.exception);\n }\n });\n }\n );\n };\n\n /**\n * Re-render the preview section based on the provided filter criteria.\n *\n * @param {jquery} root The root element.\n * @param {int} categoryId A question category id.\n * @param {bool} includeSubcategories If the results should include subcategory questions\n * @param {int[]} tagIds The list of tag ids that each question must have.\n * @param {int} contextId The context where the questions will be added.\n * @return {promise} Resolved when the previe
w section has rendered.\n */\n var reload = function(root, categoryId, includeSubcategories, tagIds, contextId) {\n // Show the loading spinner to tell the user that something is happening.\n showLoadingIcon(root);\n // Load the first set of questions.\n return requestQuestions(categoryId, includeSubcategories, tagIds, contextId, ITEMS_PER_PAGE, 0)\n .then(function(response) {\n var totalCount = response.totalcount;\n // Show the help message for the user to indicate how many questions\n // match their filter criteria.\n renderQuestionCount(root, totalCount);\n return response;\n })\n .then(function(response) {\n var totalQuestionCount = response.totalcount;\n var questions = response.questions;\n\n if (questions.length) {\n // We received some questions so render them as paged content\n
// with a paging bar.\n return renderQuestionsAsPagedContent(\n categoryId,\n includeSubcategories,\n tagIds,\n contextId,\n totalQuestionCount,\n questions\n );\n } else {\n // If we didn't receive any questions then we can return empty\n // HTML and JS to clear the preview section.\n return $.Deferred().resolve('', '');\n }\n })\n .then(function(html, js) {\n // Show the user the question set.\n var container = root.find(SELECTORS.QUESTION_LIST_CONTAINER);\n Templates.replaceNodeContents(container, html, js);\n return;\n })\n .always(function() {\n hideLoadingIcon(root);\n })\n .fail(Notification.exception);
\n };\n\n return {\n reload: reload,\n showLoadingIcon: showLoadingIcon,\n hideLoadingIcon: hideLoadingIcon\n };\n});\n"],"names":["define","$","Ajax","Str","Notification","Templates","PagedContentFactory","TEMPLATE_NAME","SELECTORS","showLoadingIcon","root","find","removeClass","hideLoadingIcon","addClass","requestQuestions","categoryId","includeSubcategories","tagIds","contextId","limit","offset","request","methodname","args","categoryid","includesubcategories","tagids","contextid","call","reload","then","response","totalCount","totalcount","questionCount","get_string","string","html","fail","exception","renderQuestionCount","totalQuestionCount","questions","length","firstPageQuestions","createFromAjax","pagesData","map","pageData","render","renderQuestionsAsPagedContent","Deferred","resolve","js","container","replaceNodeContents","always"],"mappings":";;;;;;;;AAuBAA,+CACI,CACI,SACA,YACA,WACA,oBACA,iBACA,+BAEJ,SACIC,EACAC,KACAC,IACAC,aACAC,UACAC,yBAIAC,cAAgB,sDAChBC,iCACwB,yCA
DxBA,mCAE0B,2CAF1BA,kCAGyB,0CAQzBC,gBAAkB,SAASC,MAC3BA,KAAKC,KAAKH,kCAAkCI,YAAY,WAQxDC,gBAAkB,SAASH,MAC3BA,KAAKC,KAAKH,kCAAkCM,SAAS,WA6BrDC,iBAAmB,SACnBC,WACAC,qBACAC,OACAC,UACAC,MACAC,YAEIC,QAAU,CACVC,WAAY,8CACZC,KAAM,CACFC,WAAYT,WACZU,qBAAsBT,qBACtBU,OAAQT,OACRU,UAAWT,UACXC,MAAOA,MACPC,OAAQA,gBAITnB,KAAK2B,KAAK,CAACP,UAAU,UAmHzB,CACHQ,OA9CS,SAASpB,KAAMM,WAAYC,qBAAsBC,OAAQC,kBAElEV,gBAAgBC,MAETK,iBAAiBC,WAAYC,qBAAsBC,OAAQC,UAlJjD,EAkJ4E,GACxFY,MAAK,SAASC,cACPC,WAAaD,SAASE,kBApHZ,SAASxB,KAAMyB,eACrChC,IAAIiC,WAAW,0BAA2B,WAAYD,eACjDJ,MAAK,SAASM,QACX3B,KAAKC,KAAKH,oCAAoC8B,KAAKD,WAGtDE,KAAKnC,aAAaoC,WAiHfC,CAAoB/B,KAAMuB,YACnBD,YAEVD,MAAK,SAASC,cACPU,mBAAqBV,SAASE,WAC9BS,UAAYX,SAASW,iBAErBA,UAAUC,OAtEU,SAChC5B,WACAC,qBACAC,OACAC,U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