frontend-dali/source/pages/event_edit/logic.ts
2024-09-30 13:37:30 +02:00

194 lines
5.3 KiB
TypeScript

namespace _zeitbild.frontend_web.pages
{
/**
*/
lib_plankton.zoo_page.register(
"event_edit",
async (parameters, target_element) => {
const read_only : boolean = ((parameters["read_only"] ?? "yes") === "yes");
const calendar_id : int = parseInt(parameters["calendar_id"]);
const event_id : int = parseInt(parameters["event_id"]);
target_element.innerHTML = "";
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
"event_edit",
{
"label": (
read_only
?
lib_plankton.translate.get("page.event_edit.title.read_only")
:
lib_plankton.translate.get("page.event_edit.title.regular")
)
}
);
const form : lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.event_object,
{
name : string;
begin : lib_plankton.pit.type_datetime;
end : (null | lib_plankton.pit.type_datetime);
location : (null | string);
description : (null | string);
}
> = new lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.event_object,
{
name : string;
begin : lib_plankton.pit.type_datetime;
end : (null | lib_plankton.pit.type_datetime);
location : (null | string);
description : (null | string);
}
>(
(value) => ({
"name": value.name,
"begin": value.begin,
"end": value.end,
"location": value.location,
"description": value.description,
}),
(representation) => ({
"name": representation.name,
"begin": representation.begin,
"end": representation.end,
"location": representation.location,
"description": representation.description,
}),
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("event.name")
},
{
"name": "begin",
"input": new lib_plankton.zoo_input.class_input_datetime(
{
"label_timezone_shift": lib_plankton.translate.get("common.timezone_shift"),
"label_date": lib_plankton.translate.get("common.date"),
"label_time": lib_plankton.translate.get("common.time"),
}
),
"label": lib_plankton.translate.get("event.begin")
},
{
"name": "end",
"input": new lib_plankton.zoo_input.class_input_soft<lib_plankton.pit.type_datetime>(
new lib_plankton.zoo_input.class_input_datetime(
{
"label_timezone_shift": lib_plankton.translate.get("common.timezone_shift"),
"label_date": lib_plankton.translate.get("common.date"),
"label_time": lib_plankton.translate.get("common.time"),
}
)
),
"label": lib_plankton.translate.get("event.end")
},
{
"name": "location",
"input": new lib_plankton.zoo_input.class_input_soft<string>(
new lib_plankton.zoo_input.class_input_text(
)
),
"label": lib_plankton.translate.get("event.location")
},
{
"name": "description",
"input": new lib_plankton.zoo_input.class_input_soft<string>(
new lib_plankton.zoo_input.class_input_text(
)
),
"label": lib_plankton.translate.get("event.description")
},
]
),
(
read_only
?
[
]
:
[
{
"label": lib_plankton.translate.get("page.event_edit.actions.change"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
const value : any = await get_value();
try {
await _zeitbild.frontend_web.backend.calendar_event_change(
calendar_id,
event_id,
value
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
lib_plankton.log.warning("page_event_edit_error", {"error": String(error)});
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
{
"label": lib_plankton.translate.get("page.event_edit.actions.remove"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
try {
await _zeitbild.frontend_web.backend.calendar_event_remove(
calendar_id,
event_id
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
lib_plankton.log.warning("page_event_edit_error", {"error": String(error)});
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
]
)
);
await form.setup(document.querySelector("#event_edit_form"));
const event_object : _zeitbild.frontend_web.type.event_object = await _zeitbild.frontend_web.backend.calendar_event_get(
calendar_id,
event_id
);
await form.input_write(
event_object
);
return Promise.resolve<void>(undefined);
}
);
}