2025-04-03 11:47:47 +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(
|
|
|
|
"invite_handle",
|
|
|
|
async (parameters, target_element) => {
|
2025-07-02 18:33:14 +02:00
|
|
|
function set_state(
|
|
|
|
state : ("load" | "fill" | "wait" | "done"),
|
|
|
|
messages : Array<string> = []
|
|
|
|
) : void
|
|
|
|
{
|
|
|
|
target_element.querySelector(".invite_handle").setAttribute("rel", state);
|
|
|
|
target_element.querySelector(".invite_handle-message").textContent = "";
|
|
|
|
let dom_list = document.createElement("ul");
|
|
|
|
messages.forEach(
|
|
|
|
message => {
|
|
|
|
let dom_message = document.createElement("li");
|
|
|
|
dom_message.textContent = message;
|
|
|
|
dom_list.appendChild(dom_message);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
target_element.querySelector(".invite_handle-message").appendChild(dom_list);
|
|
|
|
}
|
|
|
|
|
2025-04-03 11:47:47 +00:00
|
|
|
// parameters
|
|
|
|
const key : string = parameters["key"];
|
|
|
|
|
2025-07-03 08:53:22 +00:00
|
|
|
update_nav({"mode": null});
|
2025-04-03 11:47:47 +00:00
|
|
|
target_element.appendChild(template_request("invite_handle"));
|
2025-07-02 18:33:14 +02:00
|
|
|
set_state(
|
|
|
|
"load",
|
|
|
|
[
|
|
|
|
]
|
|
|
|
);
|
2025-04-03 11:47:47 +00:00
|
|
|
|
2025-04-12 10:19:59 +00:00
|
|
|
target_element.querySelector(".invite_handle-title").textContent = lib_plankton.translate.get("page.invite_handle.title");
|
2025-04-03 11:47:47 +00:00
|
|
|
|
2025-07-02 18:33:14 +02:00
|
|
|
let data : (
|
|
|
|
null
|
|
|
|
|
|
2025-04-03 11:47:47 +00:00
|
|
|
{
|
2025-07-02 18:33:14 +02:00
|
|
|
membership_number_changeable : boolean;
|
2025-04-03 11:47:47 +00:00
|
|
|
membership_number_value : (null | string);
|
2025-07-02 18:33:14 +02:00
|
|
|
name_changeable : boolean;
|
2025-07-03 08:53:22 +00:00
|
|
|
name_value : (null | string);
|
2025-07-02 18:33:14 +02:00
|
|
|
email_address_changeable : boolean;
|
2025-04-03 11:47:47 +00:00
|
|
|
email_address_value : (null | string);
|
2025-07-02 18:33:14 +02:00
|
|
|
groups_changeable : boolean;
|
2025-04-03 11:47:47 +00:00
|
|
|
groups_value : Array<string>;
|
|
|
|
}
|
2025-07-02 18:33:14 +02:00
|
|
|
);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
data = await _espe.backend.invite_examine(key);
|
|
|
|
}
|
|
|
|
catch (error)
|
|
|
|
{
|
|
|
|
data = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data === null)
|
|
|
|
{
|
|
|
|
set_state(
|
|
|
|
"done",
|
2025-04-03 11:47:47 +00:00
|
|
|
[
|
2025-07-02 18:33:14 +02:00
|
|
|
lib_plankton.translate.get("page.invite_handle.message.invalid"),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const form = new lib_plankton.zoo_form.class_form<
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
membership_number : (null | string);
|
|
|
|
name : string;
|
|
|
|
email_address : (null | string);
|
|
|
|
groups : Array<string>;
|
|
|
|
password_value : string;
|
|
|
|
password_confirmation : string;
|
2025-07-02 18:33:14 +02:00
|
|
|
},
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
membership_number : string;
|
|
|
|
name : string;
|
|
|
|
email_address : string;
|
|
|
|
groups : Array<string>;
|
|
|
|
password_value : string;
|
|
|
|
password_confirmation : string;
|
2025-07-02 18:33:14 +02:00
|
|
|
}
|
|
|
|
>(
|
|
|
|
value => ({
|
2025-07-03 08:53:22 +00:00
|
|
|
"membership_number": (value.membership_number ?? ""),
|
|
|
|
"name": value.name,
|
|
|
|
"email_address": (value.email_address ?? ""),
|
|
|
|
"groups": value.groups,
|
|
|
|
"password_value": value.password_value,
|
|
|
|
"password_confirmation": value.password_confirmation,
|
2025-07-02 18:33:14 +02:00
|
|
|
}),
|
|
|
|
representation => ({
|
2025-07-03 08:53:22 +00:00
|
|
|
"membership_number": representation.membership_number,
|
|
|
|
"name": representation.name,
|
|
|
|
"email_address": representation.email_address,
|
|
|
|
"groups": representation.groups,
|
|
|
|
"password_value": representation.password_value,
|
|
|
|
"password_confirmation": representation.password_confirmation,
|
2025-07-02 18:33:14 +02:00
|
|
|
}),
|
|
|
|
new lib_plankton.zoo_input.class_input_group(
|
|
|
|
[
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
"name": "membership_number",
|
2025-07-02 18:33:14 +02:00
|
|
|
"input": new lib_plankton.zoo_input.class_input_text(
|
|
|
|
{
|
|
|
|
"read_only": (! data.membership_number_changeable),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"label": lib_plankton.translate.get("domain.member.membership_number.label"),
|
|
|
|
},
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
"name": "groups",
|
2025-07-02 18:33:14 +02:00
|
|
|
"input": new lib_plankton.zoo_input.class_input_list(
|
|
|
|
() => new lib_plankton.zoo_input.class_input_text(
|
|
|
|
{
|
|
|
|
"read_only": (! data.groups_changeable),
|
|
|
|
}
|
|
|
|
),
|
2025-04-12 10:19:59 +00:00
|
|
|
{
|
|
|
|
"read_only": (! data.groups_changeable),
|
|
|
|
}
|
|
|
|
),
|
2025-07-02 18:33:14 +02:00
|
|
|
"label": lib_plankton.translate.get("domain.member.groups.label"),
|
|
|
|
},
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
"name": "name",
|
2025-07-02 18:33:14 +02:00
|
|
|
"input": new lib_plankton.zoo_input.class_input_text(
|
|
|
|
{
|
|
|
|
"read_only": (! data.name_changeable),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"label": lib_plankton.translate.get("domain.member.name_real_value.label"),
|
|
|
|
},
|
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
"name": "email_address",
|
2025-07-02 18:33:14 +02:00
|
|
|
"input": new lib_plankton.zoo_input.class_input_text(
|
|
|
|
{
|
|
|
|
"read_only": (! data.email_address_changeable),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"label": lib_plankton.translate.get("domain.member.email_address_private.label"),
|
|
|
|
},
|
2025-07-03 08:53:22 +00:00
|
|
|
{
|
|
|
|
"name": "password_value",
|
|
|
|
"input": new lib_plankton.zoo_input.class_input_password(
|
|
|
|
),
|
|
|
|
"label": lib_plankton.translate.get("page.member_register.form.field.password_value.label"),
|
|
|
|
"help": lib_plankton.translate.get("page.member_register.form.field.password_value.help"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "password_confirmation",
|
|
|
|
"input": new lib_plankton.zoo_input.class_input_password(
|
|
|
|
),
|
|
|
|
"label": lib_plankton.translate.get("page.member_register.form.field.password_confirmation.label"),
|
|
|
|
},
|
2025-07-02 18:33:14 +02:00
|
|
|
]
|
|
|
|
),
|
|
|
|
[
|
2025-04-03 11:47:47 +00:00
|
|
|
{
|
2025-07-02 18:33:14 +02:00
|
|
|
"label": lib_plankton.translate.get("page.invite_handle.form.action.submit"),
|
|
|
|
"procedure": async (get_value, get_representation) => {
|
|
|
|
const value = await get_value();
|
2025-07-03 08:53:22 +00:00
|
|
|
let flaws : Array<{incident : string; details : Record<string, any>;}>;
|
2025-07-02 18:33:14 +02:00
|
|
|
set_state(
|
|
|
|
"wait",
|
|
|
|
[
|
|
|
|
]
|
|
|
|
);
|
2025-07-03 08:53:22 +00:00
|
|
|
if (value.password_value !== value.password_confirmation)
|
|
|
|
{
|
|
|
|
flaws = [
|
|
|
|
{"incident": "password_mismatch", "details": {}},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
2025-07-02 18:33:14 +02:00
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
flaws = await _espe.backend.invite_accept(
|
|
|
|
key,
|
|
|
|
{
|
|
|
|
"membership_number": value.membership_number,
|
|
|
|
"groups": value.groups,
|
|
|
|
"name": value.name,
|
|
|
|
"email_address": value.email_address,
|
|
|
|
"password": value.password_value,
|
|
|
|
}
|
|
|
|
);
|
2025-07-02 18:33:14 +02:00
|
|
|
}
|
2025-07-03 08:53:22 +00:00
|
|
|
catch (error)
|
|
|
|
{
|
|
|
|
flaws = [
|
|
|
|
{"incident": "unhandled_error", "details": {}},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flaws.length > 0)
|
|
|
|
{
|
|
|
|
set_state(
|
|
|
|
"fill",
|
|
|
|
flaws.map(
|
|
|
|
flaw => lib_plankton.string.coin(
|
|
|
|
lib_plankton.translate.get("page.member_register.flaw." + flaw.incident),
|
|
|
|
flaw.details
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_state(
|
|
|
|
"done",
|
|
|
|
[
|
|
|
|
// lib_plankton.translate.get("page.member_register.success")
|
|
|
|
lib_plankton.translate.get("page.invite_handle.message.successful"),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2025-07-02 18:33:14 +02:00
|
|
|
},
|
|
|
|
}
|
2025-04-03 11:47:47 +00:00
|
|
|
]
|
2025-07-02 18:33:14 +02:00
|
|
|
);
|
|
|
|
await form.setup(target_element.querySelector(".invite_handle-form") as HTMLElement);
|
|
|
|
form.input_write(
|
2025-04-03 11:47:47 +00:00
|
|
|
{
|
2025-07-03 08:53:22 +00:00
|
|
|
"membership_number": data.membership_number_value,
|
|
|
|
"name": data.name_value,
|
|
|
|
"email_address": data.email_address_value,
|
|
|
|
"groups": data.groups_value,
|
|
|
|
"password_value": "",
|
|
|
|
"password_confirmation": "",
|
2025-04-03 11:47:47 +00:00
|
|
|
}
|
2025-07-02 18:33:14 +02:00
|
|
|
);
|
|
|
|
set_state(
|
|
|
|
"fill",
|
|
|
|
[
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2025-04-03 11:47:47 +00:00
|
|
|
}
|
|
|
|
);
|