Skip to content
Snippets Groups Projects
Commit b4ff7e76 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

refactor appointment lib to fit new lib-standard

parent e188e895
No related branches found
No related tags found
No related merge requests found
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var appointmentUtil = new AppointmentUtils();
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "ACCEPTED";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
}
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "ACCEPTED";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
AppointmentUtils.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = AppointmentUtils.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
}
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var appointmentUtil = new AppointmentUtils();
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "DECLINED";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
}
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "DECLINED";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
AppointmentUtils.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = AppointmentUtils.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
}
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var appointmentUtil = new AppointmentUtils();
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "TENTATIVE";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
appointmentUtil.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = appointmentUtil.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
import("system.calendars");
import("system.vars");
import("system.text");
import("system.neon");
import("Appointment_lib");
var currentUserEncodedString = calendars.getCalendarUser(vars.getString("$sys.user"));
var currentUserDecodedArray = text.decodeMS(currentUserEncodedString);
var currentUserUri = currentUserDecodedArray[0];
var newState = "TENTATIVE";
if(calendars.getBackendType() == calendars.BACKEND_EXCHANGEWS)
{
AppointmentUtils.sendExchangedAction(vars.get("$param.entry"), newState);
}
else
{
var currentAttendees = vars.get("$field.ATTENDEES");
var updatedAttendees = AppointmentUtils.setPartStat(currentUserUri, currentAttendees, newState);
neon.setFieldValue("$field.ATTENDEES", updatedAttendees);
}
\ No newline at end of file
import("system.neon");
import("system.text");
function AppointmentUtils()
{
/**
* Sets the partstat of the current users as given param state
* currentUserUri: string currentUserUri
* attendees: MSencoded calendarusers
* state: sets partstat
*/
this.setPartStat = function (currentUserUri, attendees, newState)
{
attendeesDecodedArray = text.decodeMS(attendees);
for(var i = 0; i < attendeesDecodedArray.length; i++)
{
var decoded = text.decodeMS(attendeesDecodedArray[i])
if(decoded[0] == currentUserUri)
{
var updated = new Array();
/**
* provides static methods for appointments
*
* do not create an instance of this
* @static
* @class
*/
function AppointmentUtils() {}
var isSet = false;
for (var j = 0; j < decoded.length; j++)
{
if (decoded[j].substr(0, 9) == "PARTSTAT:")
{
updated.push("PARTSTAT:" + newState);
isSet = true;
}
else
{
updated.push(decoded[j])
}
}
/**
* Sets the partstat of the current users as given param state
* @param {String} currentUserUri
* @param {String} attendees encoded as multistring
* @param {String} newState partstat
*
* @return {String} updated attendees encoded as multistring
* @static
*/
AppointmentUtils.setPartStat = function (currentUserUri, attendees, newState) {
attendeesDecodedArray = text.decodeMS(attendees);
if (!isSet)
{
updated.push("PARTSTAT:" + newState);
}
for(var i = 0; i < attendeesDecodedArray.length; i++)
{
var decoded = text.decodeMS(attendeesDecodedArray[i])
if(decoded[0] == currentUserUri)
{
var updated = new Array();
// Updaten Attendees
var newAttendees = new Array();
for (var x = 0; x < attendeesDecodedArray.length; x++)
var isSet = false;
for (var j = 0; j < decoded.length; j++)
{
if (decoded[j].substr(0, 9) == "PARTSTAT:")
{
if (text.decodeMS(attendeesDecodedArray[x])[0] == currentUserUri)
{
newAttendees.push(text.encodeMS( updated))
}
else
{
newAttendees.push(attendeesDecodedArray[x])
}
updated.push("PARTSTAT:" + newState);
isSet = true;
}
break;
else
{
updated.push(decoded[j])
}
}
}
return text.encodeMS(newAttendees);
}
this.sendExchangedAction = function(event, newState)
{
event["X-ADITO-STATUSACTION"] = newState; // "ACCEPT", "DECLINE", ""
event[calendars.AFFECTEDUSERS] = "";
calendars.updateEntry(event);
if (!isSet)
{
updated.push("PARTSTAT:" + newState);
}
// Updaten Attendees
var newAttendees = new Array();
for (var x = 0; x < attendeesDecodedArray.length; x++)
{
if (text.decodeMS(attendeesDecodedArray[x])[0] == currentUserUri)
{
newAttendees.push(text.encodeMS( updated))
}
else
{
newAttendees.push(attendeesDecodedArray[x])
}
}
break;
}
}
return text.encodeMS(newAttendees);
}
/**
* send an exchange action
* @param {String} event to send
* @param {String} newState state to send: "ACCEPT", "DECLINE", ""
*
* @static
*/
AppointmentUtils.sendExchangedAction = function(event, newState)
{
event["X-ADITO-STATUSACTION"] = newState; // "ACCEPT", "DECLINE", ""
event[calendars.AFFECTEDUSERS] = "";
calendars.updateEntry(event);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment