frontend-dali/source/pages/calendar_edit/logic.ts
2024-09-30 20:20:14 +02:00

163 lines
4.1 KiB
TypeScript

namespace _zeitbild.frontend_web.pages
{
/**
*/
lib_plankton.zoo_page.register(
"calendar_edit",
async (parameters, target_element) => {
const read_only : boolean = ((parameters["read_only"] ?? "yes") === "yes");
const calendar_id : int = parseInt(parameters["calendar_id"]);
target_element.innerHTML = "";
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
"calendar_edit",
{
"label": lib_plankton.translate.get("page.calendar_edit.title.regular")
}
);
const form : lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.calendar_object,
{
name : string;
access : {
default_level : _zeitbild.frontend_web.type.enum_access_level;
attributed : lib_plankton.map.type_map<
_zeitbild.frontend_web.type.user_id,
_zeitbild.frontend_web.type.enum_access_level
>;
};
}
> = new lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.calendar_object,
{
name : string;
access : {
default_level : _zeitbild.frontend_web.type.enum_access_level;
attributed : lib_plankton.map.type_map<
_zeitbild.frontend_web.type.user_id,
_zeitbild.frontend_web.type.enum_access_level
>;
};
}
>(
(calendar_object) => ({
"name": calendar_object.name,
"access": calendar_object.access,
}),
(raw) => ({
"name": raw.name,
"access": raw.access,
"resource": {
"kind": "local",
"data": {
"events": [],
}
},
}),
new lib_plankton.zoo_input.class_input_group<any>(
[
{
"name": "name",
"input": new lib_plankton.zoo_input.class_input_text(),
"label": lib_plankton.translate.get("calendar.name")
},
{
"name": "access",
"input": new lib_plankton.zoo_input.class_input_group(
[
{
"name": "default_level",
"input": _zeitbild.frontend_web.helpers.input_access_level(),
"label": lib_plankton.translate.get("calendar.access.default_level"),
},
{
"name": "attributed",
"input": await _zeitbild.frontend_web.helpers.input_attributed_access(),
"label": lib_plankton.translate.get("calendar.access.attributed"),
},
]
),
"label": lib_plankton.translate.get("calendar.access.access"),
},
]
),
(
read_only
?
[
]
:
[
{
"label": lib_plankton.translate.get("page.calendar_edit.actions.change"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
const value : any = await get_value();
try {
await _zeitbild.frontend_web.backend.calendar_change(
calendar_id,
value
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
{
"label": lib_plankton.translate.get("page.calendar_edit.actions.remove"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
try {
await _zeitbild.frontend_web.backend.calendar_remove(
calendar_id
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
]
)
);
await form.setup(document.querySelector("#calendar_edit_form"));
const calendar_object : _zeitbild.frontend_web.type.calendar_object = await _zeitbild.frontend_web.backend.calendar_get(
calendar_id
);
await form.input_write(calendar_object);
return Promise.resolve<void>(undefined);
}
);
}