namespace _dali.widgets.calendar_edit { /** */ export class class_widget_calendar_edit implements lib_plankton.zoo_widget.interface_widget { /** */ private users : Array<{id : _dali.type_user_id; name : string;}>; /** */ private read_only : boolean; /** */ private action_cancel ?: (null | (() => void)); /** */ private action_add ?: (null | ((value : _dali.type_calendar_object) => void)); /** */ private action_change ?: (null | ((value : _dali.type_calendar_object) => void)); /** */ private action_remove ?: (null | ((value : _dali.type_calendar_object) => void)); /** */ private initial_value : (null | _dali.type_calendar_object); /** */ public constructor( users : Array<{id : _dali.type_user_id; name : string;}>, { "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 : _dali.type_calendar_object) => void)) action_change ?: (null | ((value : _dali.type_calendar_object) => void)); action_remove ?: (null | ((value : _dali.type_calendar_object) => void)); initial_value ?: (null | _dali.type_calendar_object); } = { } ) { this.users = users; 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 { const form : lib_plankton.zoo_form.class_form< _dali.type_calendar_object, _dali.type_calendar_object > = new lib_plankton.zoo_form.class_form< _dali.type_calendar_object, _dali.type_calendar_object >( (value) => value, (raw) => raw, new lib_plankton.zoo_input.class_input_group( [ { "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": _dali.helpers.input_attributed_access(this.users), "label": lib_plankton.translate.get("calendar.access.attributed"), }, ] ), "label": lib_plankton.translate.get("calendar.access.access"), }, { "name": "resource", "input": new lib_plankton.zoo_input.class_input_hidden( ), "label": lib_plankton.translate.get("calendar.resource"), }, ] ), ( [] // 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 : _dali.type_calendar_object = 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 : _dali.type_calendar_object = 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 : _dali.type_calendar_object = await get_value(); this.action_remove(value); } }, ] : [] ) // cancel .concat( (! (this.action_cancel === null)) ? [ { "label": lib_plankton.translate.get("common.cancel"), "procedure": async () => { this.action_cancel(); } }, ] : [] ) ) ); 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.enum_access_level.view, "attributed": lib_plankton.map.hashmap.implementation_map< _dali.type_user_id, _dali.enum_access_level >( lib_plankton.map.hashmap.make< _dali.type_user_id, _dali.enum_access_level >( user_id => user_id.toFixed(0), ) ), }, /** * @todo */ "resource_id": 0, } ); } } }