152 lines
3.4 KiB
TypeScript
152 lines
3.4 KiB
TypeScript
namespace mod_view.rental.web
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export function setup
|
|
(
|
|
platform : lib_mvc.type_model<mod_platform.rental.web.type_state>
|
|
) : Promise<void>
|
|
{
|
|
let context_dom : HTMLElement = platform.state.element_dom;
|
|
// container
|
|
{
|
|
context_dom.setAttribute("rel", platform.state.model.state.id);
|
|
context_dom.classList.add
|
|
(
|
|
(
|
|
(rental_state) =>
|
|
{
|
|
switch (rental_state)
|
|
{
|
|
case mod_model.rental.enum_condition.prior: return "prior";
|
|
case mod_model.rental.enum_condition.running: return "running";
|
|
case mod_model.rental.enum_condition.paused: return "paused";
|
|
}
|
|
}
|
|
) (platform.state.model.state.condition),
|
|
);
|
|
}
|
|
// bike
|
|
{
|
|
let bike_dom : HTMLInputElement = (context_dom.querySelector(".rental_bike > input") as HTMLInputElement)
|
|
lib_loc.translate_item
|
|
(
|
|
".rental_bike > input",
|
|
"bikename",
|
|
{
|
|
"context": context_dom,
|
|
"kind": "attribute",
|
|
"parameters": {"key": "placeholder"},
|
|
}
|
|
);
|
|
bike_dom.value = (platform.state.model.state.bike_name ?? "");
|
|
const disabled : boolean = (
|
|
(
|
|
(rental_state) =>
|
|
{
|
|
switch (rental_state)
|
|
{
|
|
case mod_model.rental.enum_condition.prior: return false;
|
|
case mod_model.rental.enum_condition.running: return true;
|
|
case mod_model.rental.enum_condition.paused: return true;
|
|
}
|
|
}
|
|
) (platform.state.model.state.condition)
|
|
);
|
|
if (! disabled)
|
|
{
|
|
// do nothing
|
|
}
|
|
else
|
|
{
|
|
bike_dom.setAttribute("disabled", "disabled");
|
|
}
|
|
}
|
|
// start
|
|
{
|
|
lib_loc.translate_item(".rental_start > button", "start", {"context": context_dom});
|
|
}
|
|
// open
|
|
{
|
|
lib_loc.translate_item(".rental_open > button", "open", {"context": context_dom});
|
|
}
|
|
// pause
|
|
{
|
|
lib_loc.translate_item(".rental_pause > button", "pause", {"context": context_dom});
|
|
}
|
|
// finish
|
|
{
|
|
lib_loc.translate_item(".rental_finish > button", "finish", {"context": context_dom});
|
|
}
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function update
|
|
(
|
|
platform : lib_mvc.type_model<mod_platform.rental.web.type_state>,
|
|
event : lib_mvc.type_event<any>
|
|
) : Promise<void>
|
|
{
|
|
switch (event.type)
|
|
{
|
|
default:
|
|
{
|
|
// do nothing
|
|
break;
|
|
}
|
|
case "start":
|
|
{
|
|
let container_dom : HTMLElement = document.querySelector
|
|
(
|
|
lib_string.coin(".rental[rel=\"{{rel}}\"]", {"rel": event.data["id"]})
|
|
);
|
|
container_dom.classList.remove("prior");
|
|
container_dom.classList.remove("paused");
|
|
container_dom.classList.add("running");
|
|
break;
|
|
}
|
|
case "pause":
|
|
{
|
|
let container_dom : HTMLElement = document.querySelector
|
|
(
|
|
lib_string.coin(".rental[rel=\"{{rel}}\"]", {"rel": event.data["id"]})
|
|
);
|
|
container_dom.classList.remove("prior");
|
|
container_dom.classList.remove("running");
|
|
container_dom.classList.add("paused");
|
|
break;
|
|
}
|
|
case "open":
|
|
{
|
|
let container_dom : HTMLElement = document.querySelector
|
|
(
|
|
lib_string.coin(".rental[rel=\"{{rel}}\"]", {"rel": event.data["id"]})
|
|
);
|
|
container_dom.classList.remove("prior");
|
|
container_dom.classList.remove("paused");
|
|
container_dom.classList.add("running");
|
|
break;
|
|
}
|
|
}
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export function implementation_view
|
|
(
|
|
) : lib_mvc.type_view<mod_platform.rental.web.type_state>
|
|
{
|
|
return {
|
|
"setup": (model) => setup(model),
|
|
"update": (model, event) => update(model, event),
|
|
};
|
|
}
|
|
|
|
}
|