Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{"version":3,"file":"activity_picker_input_switcher.min.js","sources":["../src/activity_picker_input_switcher.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 * unilabel helper for activity picker\n *\n * @author      Andreas Grabs <info@grabs-edv.de>\n * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}\n * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport log from 'core/log';\n\n/**\n * Switch the input to a visible activity link.\n *\n * @param {Element} currentinput The url input field which is bound to the picker\n * @param {Element} activitylinksrc The activity element from the picker list to be cloned to the url input\n * @param {String} url\n * @param {Boolean} makedirty Should the from be dirty after switching\n * @param {String} deletestr The delete string for the delete button.\n */\nexport const switchInput = (currentinput, activitylinksrc, url, makedirty, deletestr) => {\n    /**\n     * Go recursive through all child elements given from element and apply the callback function.\n     *\n     * @param {Element} element\n     * @param {CallableFunction} callback\n     */\n    const childrenAll = (element, callback) => {\n        for (const child of element.children) {\n            childrenAll(child, callback);\n        }\n        callback(element);\n    };\n\n    /**\n     * Make the form dirty so the changechecker is aware of.\n     *\n     * @param {Element} currentinput\n     */\n    const makeFormDirty = (currentinput) => {\n        // To make the moodle form aware of the change, we set the data-initial-value to its original value.\n        currentinput.closest('form').dataset.formDirty = true;\n    };\n\n    currentinput.value = url;\n    currentinput.type = 'hidden';\n    currentinput.dataset.initialValue = currentinput.value;\n    let activitylink = activitylinksrc.closest('.activitytitle').cloneNode(true); // The new clone might have ids.\n\n    log.debug('Remove all links from clone');\n    childrenAll(activitylink, (e) => {\n        e.removeAttribute('id'); // Remove all ids.\n        if (e.nodeName.toLowerCase() == 'div' && e.classList.contains('unilabel-activity-picker-info')) {\n            e.remove();\n        }\n        if (e.nodeName.toLowerCase() == 'a') {\n            e.target = '_blank';\n            e.classList.remove('stretched-link');\n        }\n    });\n\n    activitylink.classList.add('unilabel-input-replacement', 'border-primary', 'rounded');\n    let deletelinkcontainer = document.createElement('div');\n    let deletelink = document.createElement('a');\n    let deleteicon = document.createElement('i');\n\n    deleteicon.classList.add('fa', 'fa-times', 'text-danger');\n    deleteicon.dataset.inputid = currentinput.id; // Add data attribute because it often is the click target.\n    deleteicon.title = deletestr;\n\n    deletelink.insertAdjacentElement('afterbegin', deleteicon);\n    deletelink.classList.add('unilabel-replacement-delete');\n    deletelink.href = '#';\n    deletelink.dataset.inputid = currentinput.id; // Add the data attribute to find the input field.\n    deletelink.title = deletestr;\n\n    deletelinkcontainer.insertAdjacentElement('afterbegin', deletelink);\n    activitylink.insertAdjacentElement('beforeend', deletelinkcontainer);\n    currentinput.insertAdjacentElement('afterend', activitylink);\n\n    if (makedirty) {\n        makeFormDirty(currentinput);\n    }\n\n    deletelink.addEventListener('click', (e) => {\n        e.preventDefault();\n        activitylink.remove();\n        let currentinput = document.querySelector('#' + e.target.dataset.inputid);\n        currentinput.value = '';\n        currentinput.type = 'text';\n        currentinput.focus();\n\n        makeFormDirty(currentinput);\n    });\n};\n"],"names":["currentinput","activitylinksrc","url","makedirty","deletestr","childrenAll","element","callback","child","children","makeFormDirty","closest","dataset","formDirty","value","type","initialValue","activitylink","cloneNode","debug","e","removeAttribute","nodeName","toLowerCase","classList","contains","remove","target","add","deletelinkcontainer","document","createElement","deletelink","deleteicon","inputid","id","title","insertAdjacentElement","href","addEventListener","preventDefault","querySelector","focus"],"mappings":";;;;;;;gKAkC2B,CAACA,aAAcC,gBAAiBC,IAAK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