/* 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.pages { /** */ lib_plankton.zoo_page.register( "caldav", async (parameters, target_element) => { target_element.innerHTML = ""; const conf = await _dali.backend.user_dav_conf(); target_element.innerHTML = await _dali.helpers.template_coin( "caldav", "main", { "label": lib_plankton.translate.get("page.caldav.title"), "content": ( (conf === null) ? await _dali.helpers.template_coin( "caldav", "unavailable", { "text": lib_plankton.translate.get("page.caldav.unavailable"), } ) : await _dali.helpers.template_coin( "caldav", "available", { "conf_title": lib_plankton.translate.get("page.caldav.conf.title"), "conf_content": ( (conf.password === null) ? await _dali.helpers.template_coin( "caldav", "conf-token_unset", { "text": lib_plankton.translate.get("page.caldav.conf.token_unset") } ) : await _dali.helpers.template_coin( "caldav", "conf-token_set", { "address_label": lib_plankton.translate.get("page.caldav.conf.address"), "address_value": conf.address, "username_label": lib_plankton.translate.get("page.caldav.conf.username"), "username_value": conf.username, "password_label": lib_plankton.translate.get("page.caldav.conf.password"), "password_value": conf.password, "setup_hints_label": lib_plankton.translate.get("page.caldav.conf.setup_hints"), "setup_hint_entries": ( await lib_plankton.call.promise_condense( conf.setup_hints .map( entry => () => _dali.helpers.template_coin( "caldav", "conf-setup_hint_entry", { "text": entry.label, "href": entry.link, "remark": ( (entry.remark === null) ? "" : lib_plankton.string.coin( " — {{content}}", { "content": entry.remark, } ) ) } ) ) ) ).join("") } ) ), "set_token_title": lib_plankton.translate.get("page.caldav.set_token.title"), "set_token_action": ( (conf.password === null) ? lib_plankton.translate.get("page.caldav.set_token.action.set") : lib_plankton.translate.get("page.caldav.set_token.action.overwrite") ), } ) ) } ); /** * logic: set token */ { if (conf !== null) { document.querySelector("#caldav-set_token > button").addEventListener( "click", async () => { await _dali.backend.user_dav_token(); lib_plankton.zoo_page.reload(); } ); } } return Promise.resolve(undefined); } ); }