Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"instance_form.min.js","sources":["../src/instance_form.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 * Our basic form manager for when a user either enters\n * their profile url or just wants to browse.\n *\n * This file is a mishmash of JS functions we need for both the standalone (M3.7, M3.8)\n * plugin & Moodle 3.9 functions. The 3.9 Functions have a base understanding that certain\n * things exist i.e. directory structures for templates. When this feature goes 3.9+ only\n * The goal is that we can quickly gut all AMD modules into bare JS files and use ES6 guidelines.\n * Till then this will have to do.\n *\n * @module     tool_moodlenet/instance_form\n * @copyright  2020 Mathew May <mathew.solutions>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['tool_moodlenet/validator',\n        'tool_moodlenet/selectors',\n        'core/loadingicon',\n        'core/templates',\n        'core/notification',\n        'jquery',\n        'theme_boost/bootstrap/carousel',\n        'core/normalise'],\n    function(Validator,\n             Selectors,\n             LoadingIcon,\n             Templates,\n             Notification,\n             $,\n             Carousel,\n             Normalise) {\n\n    /**\n     * Add the event listeners to our form.\n     *\n     * @method registerListenerEvents\n     * @param {HTMLElement} page The whole page element for our form area\n     */\n    var registerListenerEvents = function registerListenerEvents(page) {\n        page.addEventListener('click', function(e) {\n\n            // Our fake submit button / browse button.\n            if (e.target.matches(Selectors.action.submit)) {\n                var input = page.querySelector('[data-var=\"mnet-link\"]');\n                var overlay = page.querySelector(Selectors.region.spinner);\n                var validationArea = document.querySelector(Selectors.region.validationArea);\n\n                overlay.classList.remove('d-none');\n                var spinner = LoadingIcon.addIconToContainerWithPromise(overlay);\n                Validator.validation(input)\n                    .then(function(result) {\n                        spinner.resolve();\n                        overlay.classList.add('d-none');\n                        if (result.result) {\n                            input.classList.remove('is-invalid'); // Just in case the class has been applied already.\n                            input.classList.add('is-valid');\n                            validationArea.innerText = result.message;\n                            validationArea.classList.remove('text-danger');\n                            validationArea.classList.add('text-success');\n                            // Give the user some time to see their input is valid.\n                            setTimeout(function() {\n                                window.location = result.domain;\n                            }, 1000);\n                        } else {\n                            input.classList.add('is-invalid');\n                            validationArea.innerText = result.message;\n                            validationArea.classList.add('text-danger');\n                        }\n                        return;\n                }).catch(Notification.exception);\n            }\n        });\n    };\n\n    /**\n     * Given a user wishes to see the MoodleNet profile url form transition them there.\n     *\n     * @method chooserNavigateToMnet\n     * @param {HTMLElement} showMoodleNet The chooser's area for ment\n     * @param {Object} footerData Our footer object to render out\n     * @param {Element} carousel Our carousel instance to manage\n     * @param {jQuery} modal Our modal instance to manage\n     */\n    var chooserNavigateToMnet = function(showMoodleNet, footerData, carousel, modal) {\n        showMoodleNet.innerHTML = '';\n\n        // Add a spinner.\n        var spinnerPromise = LoadingIcon.addIconToContainer(showMoodleNet);\n\n        // Used later...\n        var transitionPromiseResolver = null;\n        var transitionPromise = new Promise(resolve => {\n            transitionPromiseResolver = resolve;\n        });\n\n        $.when(\n            spinnerPromise,\n            transitionPromise\n        ).then(function() {\n                Templates.replaceNodeContents(showMoodleNet, footerData.customcarouseltemplate, '');\n                return;\n        }).catch(Notification.exception);\n\n        // We apply our handlers in here to minimise plugin dependency in the Chooser.\n        registerListenerEvents(showMoodleNet);\n\n        // Move to the next slide, and resolve the transition promise when it's done.\n        carousel.addEventListener('slid.bs.carousel', function() {\n            transitionPromiseResolver();\n        }, {once: true});\n        // Trigger the transition between 'pages'.\n        Carousel.getInstance(carousel).to(2);\n        modal.setFooter(Templates.render('tool_moodlenet/chooser_footer_close_mnet', {}));\n    };\n\n    /**\n     * Given a user no longer wishes to see the MoodleNet profile url form transition them from there.\n     *\n     * @method chooserNavigateFromMnet\n     * @param {Element} carousel Our carousel instance to manage\n     * @param {jQuery} modal Our modal instance to manage\n     * @param {Object} footerData Our footer object to render out\n     */\n    var chooserNavigateFromMnet = function(carousel, modal, footerData) {\n        // Trigger the transition between 'pages'.\n        Carousel.getInstance(carousel).to(0);\n        modal.setFooter(footerData.customfootertemplate);\n    };\n\n        /**\n         * Create the custom listener that would handle anything in the footer.\n         *\n         * @param {Event} e The event being triggered.\n         * @param {Object} footerData The data generated from the exporter.\n         * @param {Object} modal The chooser modal.\n         */\n    var footerClickListener = function(e, footerData, modal) {\n        const modalBody = Normalise.getFirst(modal.getBody());\n        if (e.target.matches(Selectors.action.showMoodleNet) || e.target.closest(Selectors.action.showMoodleNet)) {\n            e.preventDefault();\n            const carousel = modalBody.querySelector(Selectors.region.carousel);\n            const showMoodleNet = carousel.querySelector(Selectors.region.moodleNet);\n\n            chooserNavigateToMnet(showMoodleNet, footerData, carousel, modal);\n        }\n        // From the help screen go back to the module overview.\n        if (e.target.matches(Selectors.action.closeOption)) {\n            const carousel = modalBody.querySelector(Selectors.region.carousel);\n\n            chooserNavigateFromMnet(carousel, modal, footerData);\n        }\n    };\n\n    return {\n        footerClickListener: footerClickListener\n    };\n});\n"],"names":["define","Validator","Selectors","LoadingIcon","Templates","Notification","$","Carousel","Normalise","chooserNavigateToMnet","showMoodleNet","footerData","carousel","modal","innerHTML","page","spinnerPromise","addIconToContainer","transitionPromiseResolver","transitionPromise","Promise","resolve","when","then","replaceNodeContents","customcarouseltemplate","catch","exception","addEventListener","e","target","matches","action","submit","input","querySelector","overlay","region","spinner","validationArea","document","classList","remove","addIconToContainerWithPromise","validation","result","add","innerText","message","setTimeout","window","location","domain","once","getInstance","to","setFooter","render","footerClickListener","modalBody","getFirst","getBody","closest","preventDefault","moodleNet","closeOption","customfootertemplate","chooserNavigateFromMnet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