AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"importmappingdialogue.min.js","sources":["../src/importmappingdialogue.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 module for deleting a database as a preset.\n *\n * @module mod_data/importmappingdialogue\n * @copyright 2022 Amaia Anabitarte <amaia@moodle.com>\n * @license http://www.gnu.org
/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from 'core/notification';\nimport Ajax from 'core/ajax';\nimport Url from 'core/url';\nimport Templates from 'core/templates';\nimport Modal from 'core/modal';\nimport {prefetchStrings} from 'core/prefetch';\nimport {getString} from 'core/str';\n\n// Load global strings.\nprefetchStrings('mod_data', ['mapping:dialogtitle:usepreset']);\n\nconst selectors = {\n selectPreset: '[data-action=\"selectpreset\"]',\n};\n\n/**\n * Initialize module\n */\nexport const init = () => {\n registerEventListeners();\n};\n\n/**\n * Register events.\n */\nconst registerEventListeners = () => {\n document.addEventListener('click', (event) => {\n const preset = event.target.closest(selectors.selectPreset);\n if (preset) {\n event.preventDefault();\n showMappingDialogue(preset);\n }\n });\n};\n\n/**\n * Show the confirmation modal for uploading a preset.\n *\n * @param {HTMLElement} usepreset the preset to imp
ort.\n */\nconst showMappingDialogue = (usepreset) => {\n const presetName = usepreset.dataset.presetname;\n const cmId = usepreset.dataset.cmid;\n\n getMappingInformation(cmId, presetName).then((result) => {\n if (result.data && result.data.needsmapping) {\n buildModal({\n title: getString('mapping:dialogtitle:usepreset', 'mod_data', result.data.presetname),\n body: Templates.render('mod_data/fields_mapping_body', result.data),\n footer: Templates.render('mod_data/fields_mapping_footer', getMappingButtons(cmId, presetName)),\n large: true,\n show: true,\n });\n } else {\n window.location.href = Url.relativeUrl(\n 'mod/data/field.php',\n {\n id: cmId,\n mode: 'usepreset',\n fullname: presetName,\n },\n false\n );\n }\n return true;\n }).
catch(Notification.exception);\n};\n\n/**\n * Given an object we want to build a modal ready to show\n *\n * @method buildModal\n * @param {Object} params the modal params\n * @param {Promise} params.title\n * @param {Promise} params.body\n * @param {Promise} params.footer\n * @return {Object} The modal ready to display immediately and render body in later.\n */\nconst buildModal = (params) => {\n return Modal.create({\n ...params,\n }).then(modal => {\n modal.showFooter();\n modal.registerCloseOnCancel();\n return modal;\n }).catch(Notification.exception);\n};\n\n/**\n * Add buttons to render on mapping modal.\n *\n * @param {int} cmId The id of the current database activity.\n * @param {string} presetName The preset name to delete.\n * @return {array} Same data with buttons.\n */\nconst getMappingButtons = (cmId, presetName) => {\n const data = {};\n\n data.mapfieldsbutton = Url.relativeUrl(\n 'mod/data/field.php',\n {\n id: cmId,\n
fullname: presetName,\n mode: 'usepreset',\n action: 'select',\n },\n false\n );\n\n data.applybutton = Url.relativeUrl(\n 'mod/data/field.php',\n {\n id: cmId,\n fullname: presetName,\n mode: 'usepreset',\n action: 'notmapping'\n },\n false\n );\n\n return data;\n};\n\n/**\n * Check whether we should show the mapping dialogue or not.\n *\n * @param {int} cmId The id of the current database activity.\n * @param {string} presetName The preset name to delete.\n * @return {promise} Resolved with the result and warnings of deleting a preset.\n */\nconst getMappingInformation = (cmId, presetName) => {\n const request = {\n methodname: 'mod_data_get_mapping_information',\n args: {\n cmid: cmId,\n importedpreset: presetName,\n }\n };\n return Ajax.call([request])[0];\n};\n"],"names":["selectors","registerEventListeners","document","addEventL
istener","event","preset","target","closest","preventDefault","showMappingDialogue","usepreset","presetName","dataset","presetname","cmId","cmid","getMappingInformation","then","result","data","needsmapping","buildModal","title","body","Templates","render","footer","getMappingButtons","large","show","window","location","href","Url","relativeUrl","id","mode","fullname","catch","Notification","exception","params","Modal","create","modal","showFooter","registerCloseOnCancel","mapfieldsbutton","action","applybutton","request","methodname","args","importedpreset","Ajax","call"],"mappings":";;;;;;;8TAgCgB,WAAY,CAAC,wCAEvBA,uBACY,6CAME,KAChBC,gCAMEA,uBAAyB,KAC3BC,SAASC,iBAAiB,SAAUC,cAC1BC,OAASD,MAAME,OAAOC,QAAQP,wBAChCK,SACAD,MAAMI,iBACNC,oBAAoBJ,aAU1BI,oBAAuBC,kBACnBC,WAAaD,UAAUE,QAAQC,WAC/BC,KAAOJ,UAAUE,QAAQG,KAE/BC,sBAAsBF,KAAMH,YAAYM,MAAMC,SACtCA,OAAOC,MAAQD,OAAOC,KAAKC,aAC3BC,WAAW,CACPC,OAAO,kBAAU,gCAAiC,WAAYJ,OAAOC,KAAKN,YAC1EU,KAAMC,mBAAUC,OAAO,+BAAgCP,OAAOC,MAC9DO,OAAQF,mBAAUC,OAAO,iCAAkCE,kBAAkBb,KAAMH,aAC
nFiB,OAAO,EACPC,MAAM,IAGVC,OAAOC,SAASC,KAAOC,aAAIC,YACvB,qBACA,CACIC,GAAIrB,KACJsB,KAAM,YACNC,SAAU1B,aAEd,IAGD,KACR2B,MAAMC,sBAAaC,YAapBnB,WAAcoB,QACTC,eAAMC,OAAO,IACbF,SACJxB,MAAK2B,QACJA,MAAMC,aACND,MAAME,wBACCF,SACRN,MAAMC,sBAAaC,WAUpBb,kBAAoB,CAACb,KAAMH,oBACvBQ,KAAO,UAEbA,KAAK4B,gBAAkBd,aAAIC,YACvB,qBACA,CACIC,GAAIrB,KACJuB,SAAU1B,WACVyB,KAAM,YACNY,OAAQ,WAEZ,GAGJ7B,KAAK8B,YAAchB,aAAIC,YACnB,qBACA,CACIC,GAAIrB,KACJuB,SAAU1B,WACVyB,KAAM,YACNY,OAAQ,eAEZ,GAGG7B,MAULH,sBAAwB,CAACF,KAAMH,oBAC3BuC,QAAU,CACZC,WAAY,mCACZC,KAAM,CACFrC,KAAMD,KACNuC,eAAgB1C,oBAGjB2C,cAAKC,KAAK,CAACL,UAAU"}