|
| 1 | +// This file is part of Moodle - http://moodle.org/ |
| 2 | +// |
| 3 | +// Moodle is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU General Public License as published by |
| 5 | +// the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// Moodle is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU General Public License |
| 14 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +/** |
| 17 | + * Theme Boost Union - JS code for course listing details modal. |
| 18 | + * |
| 19 | + * @module theme_boost_union/courselistingdetailsmodal |
| 20 | + * @copyright 2025 Alexander Bias, ssystems GmbH <[email protected]> |
| 21 | + * based on core_admin/themeselector/preview_modal by David Woloszyn <[email protected]> |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
| 25 | +import ModalCancel from 'core/modal_cancel'; |
| 26 | +import Notification from 'core/notification'; |
| 27 | +import Templates from 'core/templates'; |
| 28 | +import {getString} from 'core/str'; |
| 29 | + |
| 30 | +const SELECTORS = { |
| 31 | + DETAILS: '[data-action="courselisting-details"]', |
| 32 | +}; |
| 33 | + |
| 34 | +/** |
| 35 | + * Entrypoint of the js. |
| 36 | + * |
| 37 | + * @method init |
| 38 | + */ |
| 39 | +export const init = () => { |
| 40 | + registerListenerEvents(); |
| 41 | +}; |
| 42 | + |
| 43 | +/** |
| 44 | + * Register snippet related event listeners. |
| 45 | + * |
| 46 | + * @method registerListenerEvents |
| 47 | + */ |
| 48 | +const registerListenerEvents = () => { |
| 49 | + document.addEventListener('click', (e) => { |
| 50 | + const details = e.target.closest(SELECTORS.DETAILS); |
| 51 | + if (details) { |
| 52 | + buildModal(details).catch(Notification.exception); |
| 53 | + } |
| 54 | + }); |
| 55 | +}; |
| 56 | + |
| 57 | +/** |
| 58 | + * Build the modal with the provided data. |
| 59 | + * |
| 60 | + * @method buildModal |
| 61 | + * @param {object} element |
| 62 | + */ |
| 63 | +const buildModal = async(element) => { |
| 64 | + |
| 65 | + // Prepare data for modal. |
| 66 | + const data = { |
| 67 | + title: element.getAttribute('data-title'), |
| 68 | + summary: element.getAttribute('data-summary'), |
| 69 | + coursecontacts: element.getAttribute('data-coursecontacts'), |
| 70 | + customfields: element.getAttribute('data-customfields'), |
| 71 | + }; |
| 72 | + |
| 73 | + await ModalCancel.create({ |
| 74 | + title: data.title, |
| 75 | + body: Templates.render('theme_boost_union/courselistingdetailsmodal', data), |
| 76 | + large: true, |
| 77 | + buttons: { |
| 78 | + 'cancel': getString('closebuttontitle', 'moodle'), |
| 79 | + }, |
| 80 | + show: true, |
| 81 | + }); |
| 82 | +}; |
0 commit comments