pfisjs/lib/eventutils.js

87 lines
2.1 KiB
JavaScript

function create_empty_thereafter() {
return {
name : "",
name_secondary : "",
visibility : "publ",
end : "",
end_is_vague : false,
locations: [],
involved : [],
involved_roles : [],
description : "",
annotations : ""
};
}
exports.create_empty_thereafter = create_empty_thereafter;
function copy_thereafter(dest, source) {
dest.uuid = source.uuid;
dest.name = source.name;
dest.name_secondary = source.name_secondary;
dest.visibility = source.visibility;
dest.end = source.end;
dest.end_is_vague = source.end_is_vague;
dest.locations = source.locations;
dest.involved = source.involved;
dest.involved_roles = source.involved_roles;
dest.description = source.description;
dest.annotations = source.annotations;
}
exports.copy_thereafter = copy_thereafter;
function create_empty_event() {
var event = create_empty_thereafter();
event.punit = { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" };
event.start = "";
return event;
}
exports.create_empty_event = create_empty_event;
function copy_event_without_thereafter(dest, source) {
copy_thereafter(dest, source);
dest.punit = source.punit;
dest.start = source.start;
}
exports.copy_event_without_thereafter = copy_event_without_thereafter;
function add_uids_to_event(ev) {
for(var idx in ev.involved)
{
ev.involved[idx].uid = generateUID();
console.log(ev.involved[idx]);
}
for(var idx in ev.involved_roles)
{
ev.involved_roles[idx].uid = generateUID();
for(var inv_idx in ev.involved_roles[idx].involved)
ev.involved_roles[idx].involved[inv_idx].uid = generateUID();
}
for(var idx in ev.locations)
{
ev.locations[idx].uid = generateUID();
console.log(ev.locations[idx]);
}
}
exports.add_uids_to_event = add_uids_to_event;
function delete_event_if_nothing_is_edited(day, event) {
if(event.in_editing)
return;
console.log(Object.keys(event.thereafter).length);
if(Object.keys(event.thereafter).length === 0) {
console.log('DELETING EVENT: ', event.uuid);
delete day.events[event.uuid];
}
}
exports.delete_event_if_nothing_is_edited = delete_event_if_nothing_is_edited;