diff --git a/amd/build/bookingjslib.min.js b/amd/build/bookingjslib.min.js new file mode 100644 index 000000000..b0a823243 --- /dev/null +++ b/amd/build/bookingjslib.min.js @@ -0,0 +1,3 @@ +define("mod_booking/bookingjslib",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_exports.navigateToPage=function(select){select.url&&(window.location.href=select.url)};_exports.init=()=>{}})); + +//# sourceMappingURL=bookingjslib.min.js.map \ No newline at end of file diff --git a/amd/build/bookingjslib.min.js.map b/amd/build/bookingjslib.min.js.map new file mode 100644 index 000000000..37629d4b2 --- /dev/null +++ b/amd/build/bookingjslib.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bookingjslib.min.js","sources":["../src/bookingjslib.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 * Library containing general JS functions for the booking module.\n *\n * @module mod_booking/bookingjslib\n * @copyright 2025 Bernhard Fischer-Sengseis\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Init.\n */\nexport const init = () => {\n // Initialize if necessary.\n};\n\n/**\n * Navigate to a page.\n *\n * @param {object} select\n */\nexport function navigateToPage(select) {\n if (select.url) {\n window.location.href = select.url;\n }\n}"],"names":["select","url","window","location","href"],"mappings":"gLAmC+BA,QACvBA,OAAOC,MACPC,OAAOC,SAASC,KAAOJ,OAAOC,oBAXlB"} \ No newline at end of file diff --git a/amd/src/bookingjslib.js b/amd/src/bookingjslib.js new file mode 100755 index 000000000..b4b1292d2 --- /dev/null +++ b/amd/src/bookingjslib.js @@ -0,0 +1,40 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Library containing general JS functions for the booking module. + * + * @module mod_booking/bookingjslib + * @copyright 2025 Bernhard Fischer-Sengseis + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Init. + */ +export const init = () => { + // Initialize if necessary. +}; + +/** + * Navigate to a page. + * + * @param {object} select + */ +export function navigateToPage(select) { + if (select.url) { + window.location.href = select.url; + } +} \ No newline at end of file diff --git a/classes/booking.php b/classes/booking.php index b4c62fcdb..6f96af196 100755 --- a/classes/booking.php +++ b/classes/booking.php @@ -1769,7 +1769,8 @@ public static function generate_localized_css_for_navigation_labels(string $pref content: "' . get_string($prefix . 'label' . $scope, 'mod_booking') . '"; position: absolute; top: -10px; - padding: 0 5px; + left: 5px; + padding: 0 3px; font-weight: 200; font-size: small; background-color: white; diff --git a/report2.php b/report2.php index 270679aca..09a0cfce8 100644 --- a/report2.php +++ b/report2.php @@ -27,19 +27,22 @@ require_once($CFG->dirroot . '/mod/booking/lib.php'); use mod_booking\booking; +use mod_booking\option\dates_handler; use mod_booking\output\booked_users; use mod_booking\singleton_service; global $PAGE, $SITE; +$PAGE->requires->js_call_amd('mod_booking/bookingjslib'); + $optionid = optional_param('optionid', 0, PARAM_INT); $cmid = optional_param('cmid', 0, PARAM_INT); $courseid = optional_param('courseid', 0, PARAM_INT); $ticketicon = ' '; $linkicon = ' '; -$divider = " - +$divider = " + "; $r2syscontext = context_system::instance(); @@ -47,6 +50,7 @@ $r2systemurl = new moodle_url('/mod/booking/report2.php'); if (!empty($optionid)) { + // We are in option scope. $scopes = ['system', 'course', 'instance', 'option']; $optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid); $cmid = $optionsettings->cmid; @@ -99,8 +103,33 @@ $divider . "" . $linkicon . $optionsettings->get_title_with_prefix() . - ""; + ""; + + // Create a navigation dropdown for all optiondates (sessions) of the booking option. + $optiondates = $optionsettings->sessions; + if (!empty($optiondates) && count($optiondates) > 1) { + $data['optiondatesexist'] = true; + foreach ($optiondates as &$optiondate) { + $optiondate = (array) $optiondate; + $optiondate['prettydate'] = dates_handler::prettify_optiondates_start_end( + $optiondate['coursestarttime'], + $optiondate['courseendtime'], + current_language(), + true + ); + $dateurl = new moodle_url('/mod/booking/report2.php', [ + 'optionid' => $optionid, + 'optiondateid' => $optiondate['id'], + ]); + $optiondate['dateurl'] = $dateurl->out(false); + } + $data['optiondates'] = array_values((array) $optiondates); + // Now we just append the dropdown to the navigation HTML. + $navhtml .= $divider . $OUTPUT->render_from_template('mod_booking/report/navigation_dropdown', $data); + } + $navhtml .= ""; } else if (!empty($cmid)) { + // We are in instance scope. $scopes = ['system', 'course', 'instance']; $scope = 'instance'; $scopeid = $cmid; @@ -140,6 +169,7 @@ $linkicon . $bookingsettings->name . ""; } else if (!empty($courseid)) { + // We are in course scope. $scopes = ['system', 'course']; $scope = 'course'; // A moodle course containing (a) booking option(s). $scopeid = $courseid; @@ -169,6 +199,7 @@ $linkicon . $course->fullname . ""; } else { + // We are in system scope. $scopes = ['system']; require_login(1, false); $scope = 'system'; // The whole site. diff --git a/templates/report/navigation_dropdown.mustache b/templates/report/navigation_dropdown.mustache new file mode 100644 index 000000000..20267c8ba --- /dev/null +++ b/templates/report/navigation_dropdown.mustache @@ -0,0 +1,46 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_booking/report/navigation_dropdown + + Classes required for JS: + * none + + Data attributes required for JS: + * data-region + + Example context (json): + { + "prettydate" : "Mo, 28.01.2025, 12:00-13:00", + "dateurl" : "https://www.exampleurl.xyz" + } +}} +{{#optiondatesexist}} + + + +{{/optiondatesexist}} +{{#js}} + require(['mod_booking/bookingjslib'], function(fn) { + fn.init(); + }); +{{/js}}