Source: Appointment_lib/process.js

import("system.neon");
import("system.logging");
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();       

                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])
                    }            
                }

                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);
    }
    
    
    this.sendExchangedAction = function(event, newState)
    {
        event["X-ADITO-STATUSACTION"] = newState;    // "ACCEPT", "DECLINE", ""
        event[calendars.AFFECTEDUSERS] = "";
        calendars.updateEntry(event);
    }
}