/* This file is part of »dali«. Copyright 2025 'kcf' »dali« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »dali« 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »dali«. If not, see . */ namespace _dali.widgets.multiview { /** */ type type_get_entries = ( ( from_pit : lib_plankton.pit.type_pit, to_pit : lib_plankton.pit.type_pit, calendar_ids : Array<_dali.type_calendar_id> ) => Promise> ); /** */ type type_create_event = ( ( stuff ?: { date ?: lib_plankton.pit.type_date; } ) => Promise ); /** */ type type_edit_event = ( ( event_key : _dali.type_event_key ) => Promise ); /** */ export class class_widget_multiview implements lib_plankton.zoo_widget.interface_widget { /** */ private initial_view_mode : _dali.enum_view_mode; /** */ private get_entries : type_get_entries; /** */ private action_create_event : type_create_event; /** */ private action_edit_event : type_edit_event; /** */ private dom_context : (null | HTMLElement); /** */ private widget_mode_switcher : _dali.widgets.mode_switcher.class_widget_mode_switcher; /** */ private widget_weekview : _dali.widgets.weekview.class_widget_weekview; /** */ private widget_listview : _dali.widgets.listview.class_widget_listview; /** */ public constructor( get_entries : type_get_entries, { "initial_view_mode": initial_view_mode = _dali.enum_view_mode.week, "action_create_event": action_create_event = ((stuff) => Promise.resolve(undefined)), "action_edit_event": action_edit_event = ((event_key) => Promise.resolve(undefined)), } : { initial_view_mode ?: _dali.enum_view_mode; action_create_event ?: type_create_event; action_edit_event ?: type_edit_event; } = { } ) { this.get_entries = get_entries; this.initial_view_mode = initial_view_mode; this.action_create_event = action_create_event; this.action_edit_event = action_edit_event; this.dom_context = null; } /** */ public toggle_calendar_visibilty( calendar_id : _dali.type_calendar_id, { "mode": mode = null, } : { mode ?: (null | boolean); } = { } ) : void { this.widget_weekview.toggle_visibility(calendar_id, {"mode": mode}); this.widget_listview.toggle_visibility(calendar_id, {"mode": mode}); } /** */ private set_view_mode ( view_mode : _dali.enum_view_mode ) : void { this.dom_context.setAttribute("rel", _dali.view_mode_encode(view_mode)); } /** */ public update_entries( ) : Promise { return this.widget_weekview.update_entries(); } /** * [implementation] */ public async load( target_element : Element ) : Promise { this.dom_context = (target_element as HTMLElement); this.dom_context.classList.add("widget-multiview"); // mode switcher { this.widget_mode_switcher = ( new _dali.widgets.mode_switcher.class_widget_mode_switcher( [ { "mode": _dali.enum_view_mode.week, "label": lib_plankton.translate.get("page.overview.mode.week"), }, { "mode": _dali.enum_view_mode.list, "label": lib_plankton.translate.get("page.overview.mode.list"), }, ], { "initial_selection": this.initial_view_mode, "action_change": (view_mode) => { console.warn("todo"); /* lib_plankton.zoo_page.set( { "name": "overview", "parameters": { "mode": _dali.view_mode_encode(view_mode), } } ); */ this.set_view_mode(view_mode); } } ) ); let dom_wrapper = document.createElement("div"); dom_wrapper.classList.add("widget-multiview-mode_switcher"); await this.widget_mode_switcher.load(dom_wrapper); this.dom_context.appendChild(dom_wrapper); } // weekview { this.widget_weekview = ( new _dali.widgets.weekview.class_widget_weekview( this.get_entries, { "action_select_event": (event_key) => this.action_edit_event(event_key), "action_select_day": (date) => this.action_create_event({"date": date}), } ) ); let dom_wrapper = document.createElement("div"); dom_wrapper.classList.add("widget-multiview-weekview"); await this.widget_weekview.load(dom_wrapper); this.dom_context.appendChild(dom_wrapper); } // listview { this.widget_listview = ( new _dali.widgets.listview.class_widget_listview( this.get_entries, { "action_select": (event_key) => this.action_edit_event(event_key), "action_add": () => this.action_create_event(), } ) ); let dom_wrapper = document.createElement("div"); dom_wrapper.classList.add("widget-multiview-listview"); await this.widget_listview.load(dom_wrapper); this.dom_context.appendChild(dom_wrapper); } this.set_view_mode(this.initial_view_mode); return Promise.resolve(undefined); } } }