Your IP : 216.73.216.95


Current Path : /var/www/ljmtc/cbt/admin/tool/moodlenet/amd/build/
Upload File :
Current File : /var/www/ljmtc/cbt/admin/tool/moodlenet/amd/build/select_page.min.js.map

{"version":3,"sources":["../src/select_page.js"],"names":["define","Ajax","Templates","Selectors","Notification","importId","renderNoCourses","areaReplace","renderPix","then","img","temp","document","createElement","innerHTML","trim","render","nocoursesimg","firstChild","src","html","js","replaceNodeContents","classList","add","renderCourses","courses","remove","searchCourses","inputValue","page","searchIcon","querySelector","region","clearIcon","parentElement","call","methodname","args","searchvalue","result","length","forEach","course","viewurl","catch","exception","registerListenerEvents","input","searchInput","courseArea","addEventListener","value","debounce","addCourses","func","wait","immediate","timeout","context","arguments","callNow","clearTimeout","setTimeout","later","apply","init","importIdString","selectPage"],"mappings":"AAwBAA,OAAM,8BAAC,CACH,WADG,CAEH,gBAFG,CAGH,0BAHG,CAIH,mBAJG,CAAD,CAKH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAKD,IAIMC,CAAAA,CAJN,CAyBMC,CAAe,CAAG,SAASC,CAAT,CAAsB,CACxC,MAAOL,CAAAA,CAAS,CAACM,SAAV,CAAoB,SAApB,CAA+B,gBAA/B,EAAiDC,IAAjD,CAAsD,SAASC,CAAT,CAAc,CACvE,MAAOA,CAAAA,CACV,CAFM,EAEJD,IAFI,CAEC,SAASC,CAAT,CAAc,CAClB,GAAIC,CAAAA,CAAI,CAAGC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAX,CACAF,CAAI,CAACG,SAAL,CAAiBJ,CAAG,CAACK,IAAJ,EAAjB,CACA,MAAOb,CAAAA,CAAS,CAACc,MAAV,CAAiB,wBAAjB,CAA2C,CAC9CC,YAAY,CAAEN,CAAI,CAACO,UAAL,CAAgBC,GADgB,CAA3C,CAGV,CARM,EAQJV,IARI,CAQC,SAASW,CAAT,CAAeC,CAAf,CAAmB,CACvBnB,CAAS,CAACoB,mBAAV,CAA8Bf,CAA9B,CA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A,CAAU,CAAGpB,CAAI,CAACE,aAAL,CAAmB7B,CAAS,CAAC8B,MAAV,CAAiBP,OAApC,CAAjB,CACAE,CAAa,CAAC,EAAD,CAAKE,CAAL,CAAWoB,CAAX,CAChB,CA/HH,CA6IMG,CAAQ,CAAG,SAASE,CAAT,CAAeC,CAAf,CAAqBC,CAArB,CAAgC,CAC3C,GAAIC,CAAAA,CAAJ,CACA,MAAO,WAAW,IACVC,CAAAA,CAAO,CAAG,IADA,CAEVrB,CAAI,CAAGsB,SAFG,CASVC,CAAO,CAAGJ,CAAS,EAAI,CAACC,CATd,CAUdI,YAAY,CAACJ,CAAD,CAAZ,CACAA,CAAO,CAAGK,UAAU,CARR,QAARC,CAAAA,KAAQ,EAAW,CACnBN,CAAO,CAAG,IAAV,CACA,GAAI,CAACD,CAAL,CAAgB,CACZF,CAAI,CAACU,KAAL,CAAWN,CAAX,CAAoBrB,CAApB,CACH,CACJ,CAGmB,CAAQkB,CAAR,CAApB,CACA,GAAIK,CAAJ,CAAa,CACTN,CAAI,CAACU,KAAL,CAAWN,CAAX,CAAoBrB,CAApB,CACH,CACJ,CACJ,CA/JH,CAgKE,MAAO,CACH4B,IAAI,CArJG,QAAPA,CAAAA,IAAO,CAASC,CAAT,CAAyB,CAChC9D,CAAQ,CAAG8D,CAAX,CACA,GAAIrC,CAAAA,CAAI,CAAGlB,QAAQ,CAACoB,aAAT,CAAuB7B,CAAS,CAAC8B,MAAV,CAAiBmC,UAAxC,CAAX,CACArB,CAAsB,CAACjB,CAAD,CAAtB,CACAwB,CAAU,CAACxB,CAAD,CACb,CA+IM,CAGV,CA7KK,CAAN","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 * When returning to Moodle let the user select which course to add the resource to.\n *\n * @module     tool_moodlenet/select_page\n * @package    tool_moodlenet\n * @copyright  2020 Mathew May <mathew.solutions>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine([\n    'core/ajax',\n    'core/templates',\n    'tool_moodlenet/selectors',\n    'core/notification'\n], function(\n    Ajax,\n    Templates,\n    Selectors,\n    Notification\n) {\n    /**\n     * @var {string} The id corresponding to the import.\n     */\n    var importId;\n\n    /**\n     * Set up the page.\n     *\n     * @method init\n     * @param {string} importIdString the string ID of the import.\n     */\n    var init = function(importIdString) {\n        importId = importIdString;\n        var page = document.querySelector(Selectors.region.selectPage);\n        registerListenerEvents(page);\n        addCourses(page);\n    };\n\n    /**\n     * Renders the 'no-courses' template.\n     *\n     * @param {HTMLElement} areaReplace the DOM node to replace.\n     * @returns {Promise}\n     */\n    var renderNoCourses = function(areaReplace) {\n        return Templates.renderPix('courses', 'tool_moodlenet').then(function(img) {\n            return img;\n        }).then(function(img) {\n            var temp = document.createElement('div');\n            temp.innerHTML = img.trim();\n            return Templates.render('core_course/no-courses', {\n                nocoursesimg: temp.firstChild.src\n            });\n        }).then(function(html, js) {\n            Templates.replaceNodeContents(areaReplace, html, js);\n            areaReplace.classList.add('mx-auto');\n            areaReplace.classList.add('w-25');\n            return;\n        });\n    };\n\n    /**\n     * Render the course cards for those supplied courses.\n     *\n     * @param {HTMLElement} areaReplace the DOM node to replace.\n     * @param {Array<courses>} courses the courses to render.\n     * @returns {Promise}\n     */\n    var renderCourses = function(areaReplace, courses) {\n        return Templates.render('tool_moodlenet/view-cards', {\n            courses: courses\n        }).then(function(html, js) {\n            Templates.replaceNodeContents(areaReplace, html, js);\n            areaReplace.classList.remove('mx-auto');\n            areaReplace.classList.remove('w-25');\n            return;\n        });\n    };\n\n    /**\n     * For a given input, the page & what to replace fetch courses and manage icons too.\n     *\n     * @method searchCourses\n     * @param {string} inputValue What to search for\n     * @param {HTMLElement} page The whole page element for our page\n     * @param {HTMLElement} areaReplace The Element to replace the contents of\n     */\n    var searchCourses = function(inputValue, page, areaReplace) {\n        var searchIcon = page.querySelector(Selectors.region.searchIcon);\n        var clearIcon = page.querySelector(Selectors.region.clearIcon);\n\n        if (inputValue !== '') {\n            searchIcon.classList.add('d-none');\n            clearIcon.parentElement.classList.remove('d-none');\n        } else {\n            searchIcon.classList.remove('d-none');\n            clearIcon.parentElement.classList.add('d-none');\n        }\n        var args = {\n            searchvalue: inputValue,\n        };\n        Ajax.call([{\n            methodname: 'tool_moodlenet_search_courses',\n            args: args\n        }])[0].then(function(result) {\n            if (result.courses.length === 0) {\n                return renderNoCourses(areaReplace);\n            } else {\n                // Add the importId to the course link\n                result.courses.forEach(function(course) {\n                    course.viewurl += '&id=' + importId;\n                });\n                return renderCourses(areaReplace, result.courses);\n            }\n        }).catch(Notification.exception);\n    };\n\n    /**\n     * Add the event listeners to our page.\n     *\n     * @method registerListenerEvents\n     * @param {HTMLElement} page The whole page element for our page\n     */\n    var registerListenerEvents = function(page) {\n        var input = page.querySelector(Selectors.region.searchInput);\n        var courseArea = page.querySelector(Selectors.region.courses);\n        var clearIcon = page.querySelector(Selectors.region.clearIcon);\n        clearIcon.addEventListener('click', function() {\n            input.value = '';\n            searchCourses('', page, courseArea);\n        });\n\n        input.addEventListener('input', debounce(function() {\n            searchCourses(input.value, page, courseArea);\n        }, 300));\n    };\n\n    /**\n     * Fetch the courses to show the user. We use the same WS structure & template as the search for consistency.\n     *\n     * @method addCourses\n     * @param {HTMLElement} page The whole page element for our course page\n     */\n    var addCourses = function(page) {\n        var courseArea = page.querySelector(Selectors.region.courses);\n        searchCourses('', page, courseArea);\n    };\n\n    /**\n     * Define our own debounce function as Moodle 3.7 does not have it.\n     *\n     * @method debounce\n     * @from underscore.js\n     * @copyright 2009-2020 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n     * @licence MIT\n     * @param {function} func The function we want to keep calling\n     * @param {number} wait Our timeout\n     * @param {boolean} immediate Do we want to apply the function immediately\n     * @return {function}\n     */\n    var debounce = function(func, wait, immediate) {\n        var timeout;\n        return function() {\n            var context = this;\n            var args = arguments;\n            var later = function() {\n                timeout = null;\n                if (!immediate) {\n                    func.apply(context, args);\n                }\n            };\n            var callNow = immediate && !timeout;\n            clearTimeout(timeout);\n            timeout = setTimeout(later, wait);\n            if (callNow) {\n                func.apply(context, args);\n            }\n        };\n    };\n    return {\n        init: init,\n    };\n});\n"],"file":"select_page.min.js"}