AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"categoriesactions.min.js","sources":["../src/categoriesactions.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 * AMD module for categories actions.\n *\n * @module tool_dataprivacy/categoriesactions\n * @copyright 2018 David Monllao\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimpo
rt * as Ajax from 'core/ajax';\nimport * as Notification from 'core/notification';\nimport * as Str from 'core/str';\nimport ModalEvents from 'core/modal_events';\nimport ModalSaveCancel from 'core/modal_save_cancel';\n\n/**\n * List of action selectors.\n *\n * @type {{DELETE: string}}\n */\nconst ACTIONS = {\n DELETE: '[data-action=\"deletecategory\"]',\n};\n\nexport default class CategoriesActions {\n\n static init() {\n return new this();\n }\n\n /**\n * CategoriesActions class.\n */\n constructor() {\n this.registerEvents();\n }\n\n deleteCategory(id) {\n return Ajax.call([{\n methodname: 'tool_dataprivacy_delete_category',\n args: {id}\n }])[0];\n }\n\n handleCategoryRemoval(id) {\n this.deleteCategory(id)\n .then((data) => {\n if (data.result) {\n document.querySelector(`tr[data-categoryid=\"${id}\"]`)?.remove();\n } else {\n Notific
ation.addNotification({\n message: data.warnings[0].message,\n type: 'error'\n });\n }\n\n return;\n })\n .catch(Notification.exception);\n\n }\n\n /**\n * Register event listeners.\n */\n registerEvents() {\n document.addEventListener('click', (e) => {\n const target = e.target.closest(ACTIONS.DELETE);\n if (!target) {\n return;\n }\n\n e.preventDefault();\n\n this.confirmCategoryRemoval(target);\n });\n }\n\n confirmCategoryRemoval(target) {\n const id = target.dataset.id;\n var categoryname = target.dataset.name;\n var stringkeys = [\n {\n key: 'deletecategory',\n component: 'tool_dataprivacy'\n },\n {\n key: 'deletecategorytext',\n component: 'tool_dataprivacy',\n
param: categoryname\n },\n {\n key: 'delete'\n }\n ];\n\n Str.get_strings(stringkeys).then(([\n title,\n body,\n save,\n ]) => ModalSaveCancel.create({\n title,\n body,\n buttons: {\n save,\n },\n show: true,\n removeOnClose: true,\n }))\n .then((modal) => {\n // Handle save event.\n modal.getRoot().on(ModalEvents.save, () => this.handleCategoryRemoval(id));\n\n return modal;\n })\n .catch(Notification.exception);\n }\n}\n"],"names":["ACTIONS","this","constructor","registerEvents","deleteCategory","id","Ajax","call","methodname","args","handleCategoryRemoval","then","data","result","document","querySelector","remove","Notification","addNotification","message","warnings","type","catch","exception","addEventListener","e","target","closest","preventDefault","con
firmCategoryRemoval","dataset","stringkeys","key","component","param","name","Str","get_strings","_ref","title","body","save","ModalSaveCancel","create","buttons","show","removeOnClose","modal","getRoot","on","ModalEvents"],"mappings":";;;;;;;oUAiCMA,eACM,oFAMG,IAAIC,KAMfC,mBACSC,iBAGTC,eAAeC,WACJC,KAAKC,KAAK,CAAC,CACdC,WAAY,mCACZC,KAAM,CAACJ,GAAAA,OACP,GAGRK,sBAAsBL,SACbD,eAAeC,IACfM,MAAMC,iCACCA,KAAKC,qCACLC,SAASC,4CAAqCV,kEAASW,SAEvDC,aAAaC,gBAAgB,CACzBC,QAASP,KAAKQ,SAAS,GAAGD,QAC1BE,KAAM,aAMjBC,MAAML,aAAaM,WAO5BpB,iBACIW,SAASU,iBAAiB,SAAUC,UAC1BC,OAASD,EAAEC,OAAOC,QAAQ3B,gBAC3B0B,SAILD,EAAEG,sBAEGC,uBAAuBH,YAIpCG,uBAAuBH,cACbrB,GAAKqB,OAAOI,QAAQzB,OAEtB0B,WAAa,CACb,CACIC,IAAK,iBACLC,UAAW,oBAEf,CACID,IAAK,qBACLC,UAAW,mBACXC,MATWR,OAAOI,QAAQK,MAW9B,CACIH,IAAK,WAIbI,IAAIC,YAAYN,YAAYpB,MAAK2B,WAC7BC,MACAC,KACAC,kBACEC,2BAAgBC,OAAO,CACzBJ,MAAAA,MACAC,KAAAA,KACAI,QAAS,CACLH,KAAAA,MAEJI,MAAM,EACNC,eAAe,OAElBnC,MAAMoC,QAEHA,MAAMC,UAAUC,GAAGC,sBAAYT,MAAM,IAAMxC,KAAKS,sBAAsBL,MAE/D0C,SAEVzB,MAAML,aAAaM"}