229 lines
5.6 KiB
TypeScript
229 lines
5.6 KiB
TypeScript
|
|
namespace _dali.pages
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
lib_plankton.zoo_page.register(
|
||
|
|
"calendar_add",
|
||
|
|
async (parameters, target_element) => {
|
||
|
|
target_element.innerHTML = "";
|
||
|
|
target_element.innerHTML = await _dali.helpers.template_coin(
|
||
|
|
"calendar_add",
|
||
|
|
"default",
|
||
|
|
{
|
||
|
|
"label": lib_plankton.translate.get("page.calendar_add.title")
|
||
|
|
}
|
||
|
|
);
|
||
|
|
const form : lib_plankton.zoo_form.class_form<
|
||
|
|
{
|
||
|
|
name : string;
|
||
|
|
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
|
||
|
|
>;
|
||
|
|
};
|
||
|
|
resource_kind : string;
|
||
|
|
hue : (null | float);
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name : string;
|
||
|
|
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
|
||
|
|
>;
|
||
|
|
};
|
||
|
|
resource_kind : string;
|
||
|
|
hue : (null | float);
|
||
|
|
}
|
||
|
|
> = new lib_plankton.zoo_form.class_form<
|
||
|
|
{
|
||
|
|
name : string;
|
||
|
|
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
|
||
|
|
>;
|
||
|
|
};
|
||
|
|
resource_kind : string;
|
||
|
|
hue : (null | float);
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name : string;
|
||
|
|
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
|
||
|
|
>;
|
||
|
|
};
|
||
|
|
resource_kind : string;
|
||
|
|
hue : (null | float);
|
||
|
|
}
|
||
|
|
>(
|
||
|
|
(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"),
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "resource_kind",
|
||
|
|
"input": new lib_plankton.zoo_input.class_input_selection(
|
||
|
|
[
|
||
|
|
{
|
||
|
|
"value": "local",
|
||
|
|
"label": lib_plankton.translate.get("resource.kinds.local.title")
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"value": "caldav",
|
||
|
|
"label": lib_plankton.translate.get("resource.kinds.caldav.title")
|
||
|
|
},
|
||
|
|
]
|
||
|
|
),
|
||
|
|
"label": lib_plankton.translate.get("resource.kind")
|
||
|
|
},
|
||
|
|
]
|
||
|
|
),
|
||
|
|
[
|
||
|
|
{
|
||
|
|
"label": lib_plankton.translate.get("page.calendar_add.actions.do"),
|
||
|
|
"procedure": async (get_value, get_representation) => {
|
||
|
|
const value : any = await get_value();
|
||
|
|
const calendar_object : _dali.type.calendar_object = {
|
||
|
|
"name": value.name,
|
||
|
|
"access": {
|
||
|
|
"public": value.access.public,
|
||
|
|
"default_level": value.access.default_level,
|
||
|
|
"attributed": value.access.attributed,
|
||
|
|
},
|
||
|
|
"resource": (() => {
|
||
|
|
switch (value.resource_kind) {
|
||
|
|
case "local":
|
||
|
|
{
|
||
|
|
return {
|
||
|
|
"kind": "local",
|
||
|
|
"data": {
|
||
|
|
"events": [],
|
||
|
|
}
|
||
|
|
};
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case "caldav":
|
||
|
|
{
|
||
|
|
return {
|
||
|
|
"kind": "caldav",
|
||
|
|
"data": {
|
||
|
|
"url": "", // TODO
|
||
|
|
"read_only": true, // TODO
|
||
|
|
}
|
||
|
|
};
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
{
|
||
|
|
throw (new Error("invalid resource kind: " + value.resource_kind));
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}) (),
|
||
|
|
"hue": value.hue,
|
||
|
|
};
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await _dali.backend.calendar_add(
|
||
|
|
calendar_object
|
||
|
|
);
|
||
|
|
lib_plankton.zoo_page.set(
|
||
|
|
{
|
||
|
|
"name": "overview",
|
||
|
|
"parameters": {}
|
||
|
|
}
|
||
|
|
);
|
||
|
|
}
|
||
|
|
catch (error)
|
||
|
|
{
|
||
|
|
// do nothing
|
||
|
|
/*
|
||
|
|
lib_plankton.zoo_page.set(
|
||
|
|
{
|
||
|
|
"name": "event_add",
|
||
|
|
"parameters": {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
);
|
||
|
|
*/
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
]
|
||
|
|
);
|
||
|
|
await form.setup(document.querySelector("#calendar_add_form"));
|
||
|
|
await form.input_write(
|
||
|
|
{
|
||
|
|
"name": "",
|
||
|
|
"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),
|
||
|
|
)
|
||
|
|
),
|
||
|
|
},
|
||
|
|
"resource_kind": "local",
|
||
|
|
"hue": lib_plankton.random.generate_unit(),
|
||
|
|
}
|
||
|
|
);
|
||
|
|
return Promise.resolve<void>(undefined);
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
}
|