{"version":3,"file":"learningnote.min.js","sources":["https:\/\/learn.greencultured.co\/local\/learningtools\/ltool\/note\/amd\/src\/learningnote.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 .\n\n\/**\n * Notes ltool define js.\n * @module ltool_note\n * @category Classes - autoloading\n * @copyright 2021, bdecent gmbh bdecent.de\n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\ndefine(['jquery', 'core\/modal_factory', 'core\/str', 'core\/fragment', 'core\/modal_events', 'core\/ajax', 'core\/notification'],\n function($, ModalFactory, String, Fragment, ModalEvents, Ajax, notification) {\n\n \/* global ltools *\/\n\n \/**\n * Controls notes tool action.\n * @param {int} contextid context id\n * @param {object} params notes info params\n *\/\n function learningToolNoteAction(contextid, params) {\n showModalLttool(contextid, params);\n var sorttypefilter = document.querySelector(\".ltnote-sortfilter i#notessorttype\");\n if (sorttypefilter) {\n sorttypefilter.addEventListener(\"click\", function() {\n var sorttype = this.getAttribute('data-type');\n noteSortActionPage(sorttype);\n });\n }\n }\n\n \/**\n * Clean the url parameters.\n * @param {string} url page url.\n * @param {string} parameter url parameter.\n * @return {url} sort url\n *\/\n function removeURLParameter(url, parameter) {\n \/\/ Prefer to use l.search if you have a location\/link object.\n var urlparts = url.split('?');\n if (urlparts.length >= 2) {\n\n var prefix = encodeURIComponent(parameter) + '=';\n var pars = urlparts[1].split(\/[&;]\/g);\n\n \/\/ Reverse iteration as may be destructive.\n for (var i = pars.length; i-- > 0;) {\n \/\/ Idiom for string.startsWith.\n if (pars[i].lastIndexOf(prefix, 0) !== -1) {\n pars.splice(i, 1);\n }\n }\n\n url = urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : \"\");\n return url;\n } else {\n return url;\n }\n }\n\n \/**\n * Display the modal popup.\n * @param {int} contextid context id\n * @param {object} params notes info params\n * @return {void}\n *\/\n function showModalLttool(contextid, params) {\n\n var notesinfo = document.querySelector(\".ltnoteinfo #ltnote-action\");\n if (notesinfo) {\n notesinfo.addEventListener(\"click\", function() {\n var newnote = String.get_string('newnote', 'local_learningtools');\n\n $.when(newnote).done(function(localizedEditString) {\n \/\/ Add class.\n var ltoolnotebody = document.getElementsByTagName('body')[0];\n if (!ltoolnotebody.classList.contains('learningtool-note')) {\n ltoolnotebody.classList.add('learningtool-note');\n }\n\n ModalFactory.create({\n title: localizedEditString + getPopoutAction(),\n type: ModalFactory.types.SAVE_CANCEL,\n body: getnoteaction(contextid, params),\n large: true\n }).then(function(modal) {\n\n modal.show();\n\n modal.getRoot().on(ModalEvents.hidden, function() {\n modal.destroy();\n });\n\n modal.getRoot().on(ModalEvents.save, function(e) {\n e.preventDefault();\n $(e.target).find(\"button[data-action=save]\").attr(\"disabled\", true);\n modal.getRoot().find('form').submit();\n });\n\n modal.getRoot().on('submit', 'form', e => {\n e.preventDefault();\n submitFormData(modal, contextid);\n });\n\n document.querySelector(\"#popout-action\").addEventListener('click', function() {\n var pageurlobj = params.pageurl.split(\"&\");\n var pageurljson = JSON.stringify(pageurlobj);\n var url = M.cfg.wwwroot + \"\/local\/learningtools\/ltool\/note\/pop_out.php?contextid=\" +\n params.contextid + \"&pagetype=\" + params.pagetype + \"&contextlevel=\" + params.contextlevel + \"&course=\"\n + params.course + \"&user=\" + params.user + \"&pageurl=\" + pageurljson + \"&pagetitle=\" + params.pagetitle\n + \"&heading=\" + params.heading + \"&sesskey=\" + params.sesskey;\n modal.hide();\n window.open(url, '_blank');\n });\n return modal;\n }).catch(notification.exception);\n });\n\n });\n \/\/ Hover color.\n var notehovercolor = notesinfo.getAttribute(\"data-hovercolor\");\n var notefontcolor = notesinfo.getAttribute(\"data-fontcolor\");\n if (notehovercolor && notefontcolor) {\n notesinfo.addEventListener(\"mouseover\", function() {\n document.querySelector('#ltnoteinfo p').style.background = notehovercolor;\n document.querySelector('#ltnoteinfo p').style.color = notefontcolor;\n });\n }\n }\n }\n\n \/**\n * Sort the notes list.\n * @param {string} sorttype sort type\n * @return {void}\n *\/\n function noteSortActionPage(sorttype) {\n\n var pageurl = window.location.href;\n pageurl = removeURLParameter(pageurl, 'sorttype');\n\n if (sorttype == 'asc') {\n sorttype = 'desc';\n } else if (sorttype == 'desc') {\n sorttype = 'asc';\n }\n var para = '';\n if (pageurl.indexOf('?') > -1) {\n para = '&';\n } else {\n para = '?';\n }\n\n pageurl = pageurl + para + 'sorttype=' + sorttype;\n window.open(pageurl, '_self');\n }\n\n \/**\n * Popout url action html.\n * @return {string} popout html\n *\/\n function getPopoutAction() {\n var popouthtml = \"