Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"myrequestactions.min.js","sources":["../src/myrequestactions.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 to enable users to manage their own data requests.\n *\n * @module     tool_dataprivacy/myrequestactions\n * @copyright  2018 Jun Pataleta\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {getStrings} from 'core/str';\n\nconst SELECTORS = {\n    CANCEL_REQUEST: '[data-action=\"cancel\"][data-requestid]',\n};\n\n/**\n * Initialize module\n */\nexport const init = () => {\n    document.addEventListener('click', event => {\n        const triggerElement = event.target.closest(SELECTORS.CANCEL_REQUEST);\n        if (triggerElement === null) {\n            return;\n        }\n\n        event.preventDefault();\n\n        const requiredStrings = [\n            {key: 'cancelrequest', component: 'tool_dataprivacy'},\n            {key: 'cancelrequestconfirmation', component: 'tool_dataprivacy'},\n        ];\n\n        getStrings(requiredStrings).then(([cancelRequest, cancelConfirm]) => {\n            return Notification.confirm(cancelRequest, cancelConfirm, cancelRequest, null, () => {\n                const pendingPromise = new Pending('tool/dataprivacy:cancelRequest');\n                const request = {\n                    methodname: 'tool_dataprivacy_cancel_data_request',\n                    args: {requestid: triggerElement.dataset.requestid}\n                };\n\n                Ajax.call([request])[0].then(response => {\n                    if (response.result) {\n                        window.location.reload();\n                    } else {\n                        Notification.addNotification({\n                            type: 'error',\n                            message: response.warnings[0].message\n                        });\n                    }\n                    return pendingPromise.resolve();\n                }).catch(Notification.exception);\n            });\n        }).catch();\n    });\n};\n"],"names":["SELECTORS","document","addEventListener","event","triggerElement","target","closest","preventDefault","key","component","then","_ref","cancelRequest","cancelConfirm","Notification","confirm","pendingPromise","Pending","request","methodname","args","requestid","dataset","call","response","result","window","location","reload","addNotification","type","message","warnings","resolve","catch","exception"],"mappings":";;;;;;;0NA4BMA,yBACc,uDAMA,KAChBC,SAASC,iBAAiB,SAASC,cACzBC,eAAiBD,MAAME,OAAOC,QAAQN,6BACrB,OAAnBI,sBAIJD,MAAMI,qCAEkB,CACpB,CAACC,IAAK,gBAAiBC,UAAW,oBAClC,CAACD,IAAK,4BAA6BC,UAAW,sBAGtBC,MAAKC,WAAEC,cAAeC,2BACvCC,sBAAaC,QAAQH,cAAeC,cAAeD,cAAe,MAAM,WACrEI,eAAiB,IAAIC,iBAAQ,kCAC7BC,QAAU,CACZC,WAAY,uCACZC,KAAM,CAACC,UAAWjB,eAAekB,QAAQD,0BAGxCE,KAAK,CAACL,UAAU,GAAGR,MAAKc,WACrBA,SAASC,OACTC,OAAOC,SAASC,+BAEHC,gBAAgB,CACzBC,KAAM,QACNC,QAASP,SAASQ,SAAS,GAAGD,UAG/Bf,eAAeiB,aACvBC,MAAMpB,sBAAaqB,iBAE3BD"}