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

177 lines
5.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-23 23:01:49 +02:00
lib_plankton.zoo_page.register(
2025-07-02 18:33:14 +02:00
"member_view",
2024-04-23 23:01:49 +02:00
async (parameters, target_element) => {
const id : int = parseInt(parameters["id"]);
2025-07-02 18:33:14 +02:00
let dom_fragment : DocumentFragment = template_request("member_view");
2024-05-01 09:53:59 +02:00
2025-07-02 18:33:14 +02:00
dom_fragment.querySelector(".member_view-title").textContent = lib_plankton.translate.get("page.member_view.title");
2024-05-01 09:53:59 +02:00
2025-08-21 21:45:39 +00:00
/**
* @todo cache
*/
const groups_as_array : Array<{id : int; name : string;}> = await _espe.backend.group_list();
const groups_as_map : Map<int, {name : string;}> = new Map<int, {name : string;}>();
for (const group_thingy of groups_as_array)
{
groups_as_map.set(group_thingy.id, {"name": group_thingy.name});
}
2024-05-01 09:53:59 +02:00
const member_data = await _espe.backend.member_get(id);
2024-04-30 01:32:40 +02:00
const form = new lib_plankton.zoo_form.class_form<
{
2025-08-21 21:45:39 +00:00
name : string;
groups : Array<int>;
2024-04-30 01:32:40 +02:00
enabled : boolean;
2025-08-21 21:45:39 +00:00
email_address : (null | string);
2024-04-30 08:46:19 +02:00
password_set : boolean;
2024-04-30 01:32:40 +02:00
},
{
2025-08-21 21:45:39 +00:00
name : string;
groups : Set<string>;
2024-04-30 01:32:40 +02:00
enabled : boolean;
2025-08-21 21:45:39 +00:00
email_address : (null | string);
2024-04-30 08:46:19 +02:00
password_set : boolean;
2024-04-30 01:32:40 +02:00
}
>(
2025-08-21 21:45:39 +00:00
value => ({
"name": value.name,
"groups": new Set<string>(value.groups.map(group_id => group_id.toFixed(0))),
"enabled": value.enabled,
"email_address": value.email_address,
"password_set": value.password_set,
}),
representation => ({
"name": representation.name,
"groups": (() => {
const array : Array<int> = [];
for (const group_id_encoded of representation.groups)
{
array.push(parseInt(group_id_encoded));
}
return array;
}) (),
"enabled": representation.enabled,
"email_address": representation.email_address,
"password_set": representation.password_set,
}),
2024-04-23 23:01:49 +02:00
new lib_plankton.zoo_input.class_input_group(
[
{
2025-08-21 21:45:39 +00:00
"name": "name",
2024-05-02 08:41:10 +02:00
"input": new lib_plankton.zoo_input.class_input_text({"read_only": true}),
2025-08-21 21:45:39 +00:00
"label": lib_plankton.translate.get("domain.member.name.label"),
2024-05-02 08:41:10 +02:00
},
2025-01-17 09:52:03 +01:00
{
"name": "groups",
2025-08-21 21:45:39 +00:00
/*
2025-01-17 09:52:03 +01:00
"input": new lib_plankton.zoo_input.class_input_list(
2025-08-21 21:45:39 +00:00
() => new lib_plankton.zoo_input.class_input_number()
),
*/
"input": new _espe.class_input_set(
groups_as_array.map(
group_thingy => group_thingy.id.toFixed(0)
),
group_id_encoded => groups_as_map.get(parseInt(group_id_encoded)).name
2025-01-17 09:52:03 +01:00
),
2025-07-02 18:33:14 +02:00
"label": lib_plankton.translate.get("domain.member.groups.label"),
2025-01-17 09:52:03 +01:00
},
2024-04-30 01:32:40 +02:00
{
"name": "enabled",
"input": new lib_plankton.zoo_input.class_input_checkbox(),
2025-07-02 18:33:14 +02:00
"label": lib_plankton.translate.get("domain.member.enabled.label"),
2024-04-23 23:01:49 +02:00
},
2024-05-02 08:41:10 +02:00
{
"name": "password_set",
"input": new lib_plankton.zoo_input.class_input_checkbox({"read_only": true}),
2025-07-02 18:33:14 +02:00
"label": lib_plankton.translate.get("domain.member.password_set.label"),
2024-05-02 08:41:10 +02:00
},
2024-04-23 23:01:49 +02:00
{
2025-08-21 21:45:39 +00:00
"name": "email_address",
2024-04-30 08:46:19 +02:00
"input": new lib_plankton.zoo_input.class_input_text(),
2025-08-21 21:45:39 +00:00
"label": lib_plankton.translate.get("domain.member.email_address.label"),
2024-04-23 23:01:49 +02:00
},
]
),
2024-05-01 09:53:59 +02:00
(
[
{
2025-07-02 18:33:14 +02:00
"label": lib_plankton.translate.get("page.member_view.form.action.save"),
2024-05-01 09:53:59 +02:00
"procedure": async (get_value, get_representation) => {
const value = await get_value();
await _espe.backend.member_modify(
id,
2024-04-23 23:01:49 +02:00
{
2025-08-21 21:45:39 +00:00
"email_address": value.email_address,
2025-01-17 09:52:03 +01:00
"groups": value.groups,
2024-05-01 09:53:59 +02:00
"enabled": value.enabled,
2024-04-23 23:01:49 +02:00
}
2024-05-01 09:53:59 +02:00
);
},
2024-04-23 23:01:49 +02:00
},
2024-04-29 00:15:48 +02:00
]
2025-08-21 21:45:39 +00:00
/*
2024-05-01 09:53:59 +02:00
.concat(
member_data.registered
? []
: [
2024-04-30 01:32:40 +02:00
{
2025-07-02 18:33:14 +02:00
"label": lib_plankton.translate.get("page.member_view.form.action.summon"),
2024-05-01 09:53:59 +02:00
"procedure": async (get_value, get_representation) => {
2024-05-27 21:27:09 +02:00
const url : string = await _espe.backend.member_summon(
id,
2024-05-01 09:53:59 +02:00
lib_plankton.zoo_page.encode(
{
2025-07-03 08:53:22 +00:00
"name": "member_register",
2024-05-01 09:53:59 +02:00
"parameters": {
"id": id,
"verification": "{{verification}}",
}
}
)
);
if (_espe.conf.get().settings.test_mode) {
2025-07-02 18:33:14 +02:00
alert(lib_plankton.translate.get("page.member_view.misc.test_info", {"url": url}));
2024-05-01 09:53:59 +02:00
}
else {
2025-07-02 18:33:14 +02:00
alert(lib_plankton.translate.get("page.member_view.misc.summoned"));
2024-05-01 09:53:59 +02:00
}
},
},
]
)
2025-08-21 21:45:39 +00:00
*/
2024-04-29 00:15:48 +02:00
)
);
2025-07-02 18:33:14 +02:00
await form.setup(dom_fragment.querySelector(".member_view-form") as HTMLElement);
2024-05-01 09:53:59 +02:00
await form.input_write(
{
2025-08-21 21:45:39 +00:00
"name": member_data.name,
2025-01-17 09:52:03 +01:00
"groups": member_data.groups,
2024-05-01 09:53:59 +02:00
"enabled": member_data.enabled,
2025-08-21 21:45:39 +00:00
"email_address": member_data.email_address,
2024-05-01 09:53:59 +02:00
"password_set": member_data.password_set,
}
);
2024-04-23 23:01:49 +02:00
target_element.appendChild(dom_fragment);
},
);