242 lines
5.3 KiB
TypeScript
242 lines
5.3 KiB
TypeScript
namespace _dali.widgets.calendar_edit
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export type type_value = {
|
|
name : string;
|
|
hue : float;
|
|
access : {
|
|
public : boolean;
|
|
default_level : _dali.type.enum_access_level;
|
|
attributed : lib_plankton.map.type_map<
|
|
_dali.type.user_id,
|
|
_dali.type.enum_access_level
|
|
>;
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
*/
|
|
export class class_widget_calendar_edit
|
|
implements lib_plankton.zoo_widget.interface_widget
|
|
{
|
|
|
|
/**
|
|
*/
|
|
private read_only : boolean;
|
|
|
|
|
|
/**
|
|
*/
|
|
private action_cancel ?: (null | (() => void));
|
|
|
|
|
|
/**
|
|
*/
|
|
private action_add ?: (null | ((value : type_value) => void));
|
|
|
|
|
|
/**
|
|
*/
|
|
private action_change ?: (null | ((value : type_value) => void));
|
|
|
|
|
|
/**
|
|
*/
|
|
private action_remove ?: (null | ((value : type_value) => void));
|
|
|
|
|
|
/**
|
|
*/
|
|
private initial_value : (null | type_value);
|
|
|
|
|
|
/**
|
|
*/
|
|
public constructor(
|
|
{
|
|
"read_only": read_only = false,
|
|
"action_cancel": action_cancel = null,
|
|
"action_add": action_add = null,
|
|
"action_change": action_change = null,
|
|
"action_remove": action_remove = null,
|
|
"initial_value": initial_value = null,
|
|
}
|
|
:
|
|
{
|
|
read_only ?: boolean;
|
|
action_cancel ?: (null | (() => void));
|
|
action_add ?: (null | ((value : type_value) => void))
|
|
action_change ?: (null | ((value : type_value) => void));
|
|
action_remove ?: (null | ((value : type_value) => void));
|
|
initial_value ?: (null | type_value);
|
|
}
|
|
=
|
|
{
|
|
}
|
|
)
|
|
{
|
|
this.read_only = read_only;
|
|
this.action_cancel = action_cancel;
|
|
this.action_add = action_add;
|
|
this.action_change = action_change;
|
|
this.action_remove = action_remove;
|
|
this.initial_value = initial_value;
|
|
}
|
|
|
|
|
|
/**
|
|
* [implementation]
|
|
*/
|
|
public async load(
|
|
target_element : HTMLElement
|
|
) : Promise<void>
|
|
{
|
|
const form : lib_plankton.zoo_form.class_form<
|
|
type_value,
|
|
type_value
|
|
> = new lib_plankton.zoo_form.class_form<
|
|
type_value,
|
|
type_value
|
|
>(
|
|
(value) => value,
|
|
(raw) => raw,
|
|
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": "hue",
|
|
"input": new lib_plankton.zoo_input.class_input_hue(
|
|
),
|
|
"label": lib_plankton.translate.get("calendar.hue"),
|
|
},
|
|
{
|
|
"name": "access",
|
|
"input": new lib_plankton.zoo_input.class_input_group(
|
|
[
|
|
{
|
|
"name": "public",
|
|
"input": new lib_plankton.zoo_input.class_input_checkbox(),
|
|
"label": lib_plankton.translate.get("calendar.access.public"),
|
|
},
|
|
{
|
|
"name": "default_level",
|
|
"input": _dali.helpers.input_access_level(),
|
|
"label": lib_plankton.translate.get("calendar.access.default_level"),
|
|
},
|
|
{
|
|
"name": "attributed",
|
|
"input": await _dali.helpers.input_attributed_access(),
|
|
"label": lib_plankton.translate.get("calendar.access.attributed"),
|
|
},
|
|
]
|
|
),
|
|
"label": lib_plankton.translate.get("calendar.access.access"),
|
|
},
|
|
]
|
|
),
|
|
(
|
|
[]
|
|
// cancel
|
|
.concat(
|
|
(! (this.action_cancel === null))
|
|
?
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("common.cancel"),
|
|
"procedure": async () => {
|
|
this.action_cancel();
|
|
}
|
|
},
|
|
]
|
|
:
|
|
[]
|
|
)
|
|
// add
|
|
.concat(
|
|
((! this.read_only) && (! (this.action_add === null)))
|
|
?
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("widget.calendar_edit.actions.add"),
|
|
"procedure": async (get_value, get_representation) => {
|
|
const value : type_value = await get_value();
|
|
this.action_add(value);
|
|
}
|
|
},
|
|
]
|
|
:
|
|
[]
|
|
)
|
|
// change
|
|
.concat(
|
|
((! this.read_only) && (! (this.action_change === null)))
|
|
?
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("widget.calendar_edit.actions.change"),
|
|
"procedure": async (get_value, get_representation) => {
|
|
const value : type_value = await get_value();
|
|
this.action_change(value);
|
|
}
|
|
},
|
|
]
|
|
:
|
|
[]
|
|
)
|
|
// remove
|
|
.concat(
|
|
((! this.read_only) && (! (this.action_change === null)))
|
|
?
|
|
[
|
|
{
|
|
"label": lib_plankton.translate.get("widget.calendar_edit.actions.remove"),
|
|
"procedure": async (get_value, get_representation) => {
|
|
const value : type_value = await get_value();
|
|
this.action_remove(value);
|
|
}
|
|
},
|
|
]
|
|
:
|
|
[]
|
|
)
|
|
)
|
|
);
|
|
await form.setup(target_element);
|
|
await form.input_write(
|
|
(! (this.initial_value === null))
|
|
?
|
|
this.initial_value
|
|
:
|
|
{
|
|
"name": "",
|
|
"hue": lib_plankton.random.generate_unit(),
|
|
"access": {
|
|
"public": false,
|
|
"default_level": _dali.type.enum_access_level.view,
|
|
"attributed": lib_plankton.map.hashmap.implementation_map<
|
|
_dali.type.user_id,
|
|
_dali.type.enum_access_level
|
|
>(
|
|
lib_plankton.map.hashmap.make<
|
|
_dali.type.user_id,
|
|
_dali.type.enum_access_level
|
|
>(
|
|
user_id => user_id.toFixed(0),
|
|
)
|
|
),
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|