From b4ff7e7674765a359a515f7c4872d44e12a8f980 Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Fri, 30 Nov 2018 15:41:46 +0100 Subject: [PATCH] refactor appointment lib to fit new lib-standard --- .../children/accept/onActionProcess.js | 46 +++---- .../children/decline/onActionProcess.js | 46 +++---- .../children/tentative/onActionProcess.js | 44 +++--- process/Appointment_lib/process.js | 129 ++++++++++-------- 4 files changed, 136 insertions(+), 129 deletions(-) diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js index fd31c4af45..db8e0169ef 100644 --- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js +++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/accept/onActionProcess.js @@ -1,24 +1,22 @@ -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); +} diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js index 831a49bcec..53d96d7143 100644 --- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js +++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/decline/onActionProcess.js @@ -1,24 +1,22 @@ -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); +} diff --git a/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js b/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js index 24a1e6e1c9..218c335ea1 100644 --- a/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js +++ b/entity/Appointment_entity/entityfields/partstatactiongroup/children/tentative/onActionProcess.js @@ -1,24 +1,22 @@ -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 diff --git a/process/Appointment_lib/process.js b/process/Appointment_lib/process.js index ee83066b4c..639130361b 100644 --- a/process/Appointment_lib/process.js +++ b/process/Appointment_lib/process.js @@ -1,70 +1,83 @@ 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 -- GitLab