Proyectos de Subversion Moodle

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"usetemplate.min.js","sources":["../src/usetemplate.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 using an existing template\n *\n * @module      mod_feedback/usetemplate\n * @copyright   2021 Peter Dias\n * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalForm from 'core_form/modalform';\nimport Notification from 'core/notification';\nimport {getString} from 'core/str';\n\nconst selectors = {\n    modaltrigger: '[data-action=\"usetemplate\"]',\n};\n\nlet initialized = false;\n\n/**\n * Initialize module\n */\nexport const init = () => {\n\n    if (initialized) {\n        // We already added the event listeners (can be called multiple times).\n        return;\n    }\n\n    document.addEventListener('click', event => {\n        // Use the template.\n        const trigger = event.target.closest(selectors.modaltrigger);\n        if (trigger) {\n            event.preventDefault();\n\n            const modalForm = new ModalForm({\n                modalConfig: {\n                    title: getString('use_this_template', 'mod_feedback'),\n                },\n                formClass: 'mod_feedback\\\\form\\\\use_template_form',\n                args: {\n                    id: trigger.getAttribute('data-dataid'),\n                    templateid: trigger.getAttribute('data-templateid')\n                },\n                saveButtonText: getString('save', 'core')\n            });\n\n            // Show a toast notification when the form is submitted.\n            modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {\n                if (event.detail.result) {\n                    window.location.assign(event.detail.url);\n                } else {\n                    Notification.addNotification({\n                        type: 'error',\n                        message:  getString('saving_failed', 'mod_feedback')\n                    });\n                }\n            });\n\n            modalForm.show();\n        }\n    });\n\n    initialized = true;\n};\n"],"names":["selectors","initialized","document","addEventListener","event","trigger","target","closest","preventDefault","modalForm","ModalForm","modalConfig","title","formClass","args","id","getAttribute","templateid","saveButtonText","events","FORM_SUBMITTED","detail","result","window","location","assign","url","addNotification","type","message","show"],"mappings":";;;;;;;0LA2BMA,uBACY,kCAGdC,aAAc,gBAKE,KAEZA,cAKJC,SAASC,iBAAiB,SAASC,cAEzBC,QAAUD,MAAME,OAAOC,QAAQP,2BACjCK,QAAS,CACTD,MAAMI,uBAEAC,UAAY,IAAIC,mBAAU,CAC5BC,YAAa,CACTC,OAAO,kBAAU,oBAAqB,iBAE1CC,UAAW,wCACXC,KAAM,CACFC,GAAIV,QAAQW,aAAa,eACzBC,WAAYZ,QAAQW,aAAa,oBAErCE,gBAAgB,kBAAU,OAAQ,UAItCT,UAAUN,iBAAiBM,UAAUU,OAAOC,gBAAgBhB,QACpDA,MAAMiB,OAAOC,OACbC,OAAOC,SAASC,OAAOrB,MAAMiB,OAAOK,2BAEvBC,gBAAgB,CACzBC,KAAM,QACNC,SAAU,kBAAU,gBAAiB,qBAKjDpB,UAAUqB,WAIlB7B,aAAc"}