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

89 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-05-20 22:04:23 +02: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/>.
*/
2024-04-30 01:32:40 +02:00
lib_plankton.zoo_page.register(
"list",
(parameters, target_element) => {
type type_item = {
id : int;
preview : {
membership_number : string;
name_real_value : string;
name_real_index : int;
};
};
2024-05-01 09:53:59 +02:00
const term : (null | string) = (parameters["term"] ?? "");
2025-04-12 10:19:59 +00:00
2024-05-02 08:41:10 +02:00
target_element.appendChild(template_request("list"));
target_element.querySelector(".list-title").textContent = lib_plankton.translate.get("page.list.title");
2024-04-30 01:32:40 +02:00
const search : lib_plankton.zoo_search.type_search<type_item> = lib_plankton.zoo_search.make<type_item>(
(term) => _espe.backend.member_list(term),
{
"encode_item": (item) => lib_plankton.string.coin(
"{{membership_number}} | {{name}}{{addition}}",
{
"membership_number": item.preview.membership_number,
"name": item.preview.name_real_value,
"addition": (
(
(item.preview.name_real_index === null)
||
(item.preview.name_real_index <= 1)
)
? ""
: (" (" + item.preview.name_real_index.toFixed(0) + ")")
),
}
),
"hooks_begin": [
(term) => {
lib_plankton.zoo_page.set(
{
"name": "list",
"parameters": {
"term": term,
}
}
);
}
],
"hooks_select": [
(item) => {
lib_plankton.zoo_page.set(
{
"name": "view",
"parameters": {
"id": item.id.toFixed(0),
}
}
);
}
]
}
);
lib_plankton.zoo_search.render(
search,
2024-05-02 08:41:10 +02:00
target_element.querySelector(".list-search"),
2024-04-30 01:32:40 +02:00
{
"state": {
"term": term,
}
}
);
}
);