frontend-dali/source/pages/caldav/logic.ts

140 lines
3.8 KiB
TypeScript
Raw Normal View History

2025-10-23 23:16:11 +02:00
/*
This file is part of »dali«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»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 <http://www.gnu.org/licenses/>.
*/
2025-09-25 17:54:20 +02:00
namespace _dali.pages
{
/**
*/
lib_plankton.zoo_page.register(
"caldav",
async (parameters, target_element) => {
target_element.innerHTML = "";
2025-09-25 17:54:20 +02:00
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)
?
2025-09-25 17:54:20 +02:00
await _dali.helpers.template_coin(
"caldav",
"unavailable",
{
"text": lib_plankton.translate.get("page.caldav.unavailable"),
}
)
:
2025-09-25 17:54:20 +02:00
await _dali.helpers.template_coin(
"caldav",
"available",
{
"conf_title": lib_plankton.translate.get("page.caldav.conf.title"),
"conf_content": (
(conf.password === null)
?
2025-09-25 17:54:20 +02:00
await _dali.helpers.template_coin(
"caldav",
"conf-token_unset",
{
"text": lib_plankton.translate.get("page.caldav.conf.token_unset")
}
)
:
2025-09-25 17:54:20 +02:00
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<string, unknown>(
conf.setup_hints
.map(
2025-09-25 17:54:20 +02:00
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 () => {
2025-09-25 17:54:20 +02:00
await _dali.backend.user_dav_token();
lib_plankton.zoo_page.reload();
}
);
}
}
return Promise.resolve<void>(undefined);
}
);
}