Index: openacs-4/packages/calendar-portlet/www/calendar-full-portlet.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar-portlet/www/calendar-full-portlet.tcl,v diff -u -N -r1.44.2.4 -r1.44.2.5 --- openacs-4/packages/calendar-portlet/www/calendar-full-portlet.tcl 13 Oct 2022 12:00:37 -0000 1.44.2.4 +++ openacs-4/packages/calendar-portlet/www/calendar-full-portlet.tcl 21 Mar 2023 17:41:54 -0000 1.44.2.5 @@ -68,7 +68,50 @@ } set calendar_id [lindex $list_of_calendar_ids 0] -db_0or1row select_calendar_package_id {select package_id from calendars where calendar_id=:calendar_id} + +# +# Get the package_id of the calendar_id +# +if {$calendar_id == 0} { + + # + # A calendar_id 0 may happen when showcasing the portal layout in + # "Portal Templates". This will be a dummy calendar portlet, so we + # deactivate the UI by disabling all links and buttons. + # + set package_id 0 + set period_days [parameter::get -package_id $package_id -parameter ListView_DefaultPeriodDays -default 31] + template::add_body_handler -event load -script { + // Remove event listeners set on the mini-calendar + for (const day of document.querySelectorAll('[id^="mini-calendar-"]')) { + day.replaceWith(day.cloneNode(true)); + } + // Disable all links + for (const link of document.querySelectorAll('[name="calendar"] ~ * a')) { + link.addEventListener('click', function (e) { + link.removeAttribute('href'); + }); + } + // Disable all buttons + for (const input of document.querySelectorAll('[name="calendar"] ~ * input, [name="calendar"] ~ * button')) { + input.disabled = true; + } + } + +} elseif {![db_0or1row select_calendar_package_id { + select package_id from calendars + where calendar_id = :calendar_id +}]} { + + # + # Could not find the supplied calendar_id, we complain in this + # case. + # + ad_log error "Invalid calendar_id in portlet configuration (calendar_id '$calendar_id')" + ad_return_complaint 1 "Invalid calendar_id in portlet configuration (calendar_id '$calendar_id')" + ad_script_abort +} + if { ![info exists period_days] } { if { [info exists community_id] && $community_id ne "" } { set period_days [parameter::get -package_id $package_id -parameter ListView_DefaultPeriodDays -default 31]