AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"userfeedback.min.js","sources":["../src/userfeedback.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 * Handle clicking on action links of the feedback alert.\n *\n * @module core/userfeedback\n * @copyright 2020 Shamim Rezaie <shamim@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or lat
er\n */\n\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\nconst Selectors = {\n regions: {\n root: '[data-region=\"core/userfeedback\"]',\n },\n actions: {},\n};\nSelectors.actions.give = `${Selectors.regions.root} [data-action=\"give\"]`;\nSelectors.actions.remind = `${Selectors.regions.root} [data-action=\"remind\"]`;\n\n/**\n * Attach the necessary event handlers to the action links\n */\nexport const registerEventListeners = () => {\n document.addEventListener('click', e => {\n const giveAction = e.target.closest(Selectors.actions.give);\n if (giveAction) {\n e.preventDefault();\n\n if (!window.open(giveAction.href)) {\n throw new Error('Unable to open popup');\n }\n\n Promise.resolve(giveAction)\n .then(hideRoot)\n .then(recordAction)\n .catch(Notification.exception);\n }\n\n const remindAction = e.target.closest(Selectors
.actions.remind);\n if (remindAction) {\n e.preventDefault();\n\n Promise.resolve(remindAction)\n .then(hideRoot)\n .then(recordAction)\n .catch(Notification.exception);\n }\n });\n};\n\n/**\n * Record the action that the user took.\n *\n * @param {HTMLElement} clickedItem The action element that the user chose.\n * @returns {Promise}\n */\nconst recordAction = clickedItem => {\n if (clickedItem.dataset.record) {\n return Ajax.call([{\n methodname: 'core_create_userfeedback_action_record',\n args: {\n action: clickedItem.dataset.action,\n contextid: M.cfg.contextid,\n }\n }])[0];\n }\n\n return Promise.resolve();\n};\n\n/**\n * Hide the root node of the CTA notification.\n *\n * @param {HTMLElement} clickedItem The action element that the user chose.\n * @returns {HTMLElement}\n */\nconst hideRoot = clickedItem => {\n if (clickedItem.data
set.hide) {\n clickedItem.closest(Selectors.regions.root).remove();\n }\n\n return clickedItem;\n};\n"],"names":["Selectors","regions","root","actions","give","remind","document","addEventListener","e","giveAction","target","closest","preventDefault","window","open","href","Error","Promise","resolve","then","hideRoot","recordAction","catch","Notification","exception","remindAction","clickedItem","dataset","record","Ajax","call","methodname","args","action","contextid","M","cfg","hide","remove"],"mappings":";;;;;;;kMA0BMA,UAAY,CACdC,QAAS,CACLC,KAAM,qCAEVC,QAAS,IAEbH,UAAUG,QAAQC,eAAUJ,UAAUC,QAAQC,8BAC9CF,UAAUG,QAAQE,iBAAYL,UAAUC,QAAQC,gEAKV,KAClCI,SAASC,iBAAiB,SAASC,UACzBC,WAAaD,EAAEE,OAAOC,QAAQX,UAAUG,QAAQC,SAClDK,WAAY,IACZD,EAAEI,kBAEGC,OAAOC,KAAKL,WAAWM,YAClB,IAAIC,MAAM,wBAGpBC,QAAQC,QAAQT,YACXU,KAAKC,UACLD,KAAKE,cACLC,MAAMC,sBAAaC,iBAGtBC,aAAejB,EAAEE,OAAOC,QAAQX,UAAUG,QAAQE,QACpDoB,eACAjB,EAAEI,iBAEFK,QAAQC,QAAQO,cACXN,KAAKC,UACLD,KAAKE,cACLC,MAAMC,sBAAaC,sBAW9BH,aAAeK,aACbA,YAAYC,QAAQC,OACbC
,cAAKC,KAAK,CAAC,CACdC,WAAY,yCACZC,KAAM,CACFC,OAAQP,YAAYC,QAAQM,OAC5BC,UAAWC,EAAEC,IAAIF,cAErB,GAGDjB,QAAQC,UASbE,SAAWM,cACTA,YAAYC,QAAQU,MACpBX,YAAYf,QAAQX,UAAUC,QAAQC,MAAMoC,SAGzCZ"}