AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"purposesactions.min.js","sources":["../src/purposesactions.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 purposes actions.\n *\n * @module tool_dataprivacy/purposesactions\n * @copyright 2018 David Monllao\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n// 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 * Module for purpose actions.\n *\n * @module tool_dataprivacy/purposeactions\n * @copyright 2018 David Monllao\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as Ajax from 'core/ajax';\nimport * as Notification from 'core/notification';\nimport * as Str from 'core/str';\nimport Modal
Events 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=\"deletepurpose\"]',\n};\n\nexport default class PurposeActions {\n\n static init() {\n return new this();\n }\n\n constructor() {\n this.registerEvents();\n }\n\n deletePurpose(id) {\n return Ajax.call([{\n methodname: 'tool_dataprivacy_delete_purpose',\n args: {id}\n }])[0];\n }\n\n handleRemoval(id) {\n this.deletePurpose(id)\n .then((data) => {\n if (data.result) {\n document.querySelector(`tr[data-purposeid=\"${id}\"]`)?.remove();\n } else {\n Notification.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.confirmRemoval(target);\n });\n }\n\n confirmRemoval(target) {\n const id = target.dataset.id;\n var purposename = target.dataset.name;\n var stringkeys = [\n {\n key: 'deletepurpose',\n component: 'tool_dataprivacy'\n },\n {\n key: 'deletepurposetext',\n component: 'tool_dataprivacy',\n param: purposename\n },\n {\n key: 'delete'\n }\n ];\n\n Str.get_strings(stringkeys).then(([\n title,\n body,\n sa
ve,\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.handleRemoval(id));\n\n return modal;\n })\n .catch(Notification.exception);\n }\n}\n"],"names":["ACTIONS","this","constructor","registerEvents","deletePurpose","id","Ajax","call","methodname","args","handleRemoval","then","data","result","document","querySelector","remove","Notification","addNotification","message","warnings","type","catch","exception","addEventListener","e","target","closest","preventDefault","confirmRemoval","dataset","stringkeys","key","component","param","name","Str","get_strings","_ref","title","body","save","ModalSaveCancel","create","buttons","show","removeOnClose","modal","getRoot","on","ModalEve
nts"],"mappings":";;;;;;;;;;;;;;oUAuDMA,eACM,mFAMG,IAAIC,KAGfC,mBACSC,iBAGTC,cAAcC,WACHC,KAAKC,KAAK,CAAC,CACdC,WAAY,kCACZC,KAAM,CAACJ,GAAAA,OACP,GAGRK,cAAcL,SACLD,cAAcC,IACdM,MAAMC,iCACCA,KAAKC,qCACLC,SAASC,2CAAoCV,kEAASW,SAEtDC,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,eAAeH,YAI5BG,eAAeH,cACLrB,GAAKqB,OAAOI,QAAQzB,OAEtB0B,WAAa,CACb,CACIC,IAAK,gBACLC,UAAW,oBAEf,CACID,IAAK,oBACLC,UAAW,mBACXC,MATUR,OAAOI,QAAQK,MAW7B,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,OAEdnC,MAAMoC,QAEHA,MAAMC,UAAUC,GAAGC,sBAAYT,MAAM,IAAMxC,KAAKS,cAAcL,MAEvD0C,SAEVzB,MAAML,aAAaM"}