frontend-zackeneule/source/pages/invitation_list/logic.ts

109 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-04-12 10:19:59 +00:00
/*
Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Frontend
Copyright (C) 2024 Christian Fraß
This program 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.
This program 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 this program. If not, see
<https://www.gnu.org/licenses/>.
*/
lib_plankton.zoo_page.register(
2025-08-22 17:07:39 +02:00
"invitation_list",
2025-04-12 10:19:59 +00:00
async (parameters, target_element) => {
2025-07-02 18:33:14 +02:00
// types
2025-04-12 10:19:59 +00:00
type type_item = {
id : int;
2025-08-22 10:53:20 +02:00
preview : {
key : string;
expiry : (null | int);
name_value : string;
label_value : string;
};
2025-04-12 10:19:59 +00:00
};
2025-07-02 18:33:14 +02:00
// parameters
const term : (null | string) = (parameters["term"] ?? "");
// exec
2025-08-22 17:07:39 +02:00
target_element.appendChild(_espe.helpers.template_request("invitation_list"));
2025-04-12 10:19:59 +00:00
2025-08-22 17:07:39 +02:00
target_element.querySelector(".invitation_list-title").textContent = lib_plankton.translate.get("page.invitation_list.title");
2025-04-12 10:19:59 +00:00
2025-07-02 18:33:14 +02:00
// exec : create link
{
2025-08-22 17:07:39 +02:00
const element : HTMLElement = target_element.querySelector(".invitation_list-create");
2025-07-02 18:33:14 +02:00
element.setAttribute(
"href",
lib_plankton.zoo_page.encode(
{
2025-08-22 17:07:39 +02:00
"name": "invitation_create",
2025-07-02 18:33:14 +02:00
"parameters": {
}
}
)
);
2025-08-22 17:07:39 +02:00
element.textContent = lib_plankton.translate.get("page.invitation_create.title");
2025-07-02 18:33:14 +02:00
}
2025-04-12 10:19:59 +00:00
const search : lib_plankton.zoo_search.type_search<type_item> = lib_plankton.zoo_search.make<type_item>(
2025-08-22 17:07:39 +02:00
(term) => _espe.backend.invitation_list(),
2025-04-12 10:19:59 +00:00
{
"encode_item": (item) => lib_plankton.string.coin(
2025-08-22 10:53:20 +02:00
"{{label}}",
2025-04-12 10:19:59 +00:00
{
2025-08-22 10:53:20 +02:00
"label": item.preview.label_value,
2025-04-12 10:19:59 +00:00
}
),
"hooks_begin": [
(term) => {
2025-07-02 18:33:14 +02:00
lib_plankton.zoo_page.set(
{
2025-08-22 17:07:39 +02:00
"name": "invitation_list",
2025-07-02 18:33:14 +02:00
"parameters": {
"term": term,
}
}
);
2025-04-12 10:19:59 +00:00
}
],
"hooks_select": [
(item) => {
2025-07-02 18:33:14 +02:00
lib_plankton.zoo_page.set(
2025-04-12 10:19:59 +00:00
{
2025-08-22 17:07:39 +02:00
"name": "invitation_view",
2025-07-02 18:33:14 +02:00
"parameters": {
"id": item.id.toFixed(0),
}
2025-04-12 10:19:59 +00:00
}
);
}
]
}
);
lib_plankton.zoo_search.render(
search,
2025-08-22 17:07:39 +02:00
target_element.querySelector(".invitation_list-search"),
2025-04-12 10:19:59 +00:00
{
"state": {
"term": "",
}
}
);
/*
2025-08-22 17:07:39 +02:00
const data = await _espe.backend.invitation_list();
(target_element.querySelector(".invitation_list-data") as HTMLElement).textContent = JSON.stringify(
2025-04-12 10:19:59 +00:00
data,
undefined,
" "
);
*/
}
);