1 /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Oracle Corporation code.
16 *
17 * The Initial Developer of the Original Code is
18 * Oracle Corporation
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Mike Shaver <shaver@off.net>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
calAttendee
39 function calAttendee() {
40 this.wrappedJSObject = this;
41 this.mProperties = new calPropertyBag();
42 }
43
44 var calAttendeeClassInfo = {
getInterfaces
45 getInterfaces: function (count) {
46 var ifaces = [
47 Components.interfaces.nsISupports,
48 Components.interfaces.calIAttendee,
49 Components.interfaces.nsIClassInfo
50 ];
51 count.value = ifaces.length;
52 return ifaces;
53 },
54
getHelperForLanguage
55 getHelperForLanguage: function (language) {
56 return null;
57 },
58
59 contractID: "@mozilla.org/calendar/attendee;1",
60 classDescription: "Calendar Attendee",
61 classID: Components.ID("{5c8dcaa3-170c-4a73-8142-d531156f664d}"),
62 implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
63 flags: 0
64 };
65
66
67 calAttendee.prototype = {
QueryInterface
68 QueryInterface: function (aIID) {
69 if (aIID.equals(Components.interfaces.nsIClassInfo))
70 return calAttendeeClassInfo;
71
72 if (!aIID.equals(Components.interfaces.nsISupports) &&
73 !aIID.equals(Components.interfaces.calIAttendee))
74 {
75 throw Components.results.NS_ERROR_NO_INTERFACE;
76 }
77
78 return this;
79 },
80
81 mImmutable: false,
get_isMutable
82 get isMutable() { return !this.mImmutable; },
83
modify
84 modify: function() {
85 if (this.mImmutable) {
86 throw Components.results.NS_ERROR_OBJECT_IS_IMMUTABLE;
87 }
88 },
89
makeImmutable
90 makeImmutable : function() {
91 this.mImmutable = true;
92 },
93
clone
94 clone: function() {
95 var a = new calAttendee();
96
97 if (this.mIsOrganizer) {
98 a.isOrganizer = true;
99 }
100
101 var allProps = ["id", "commonName", "rsvp", "role", "participationStatus",
102 "userType"];
103 for (var i in allProps)
104 a[allProps[i]] = this[allProps[i]];
105
106 var bagenum = this.propertyEnumerator;
107 while (bagenum.hasMoreElements()) {
108 var iprop = bagenum.getNext().QueryInterface(Components.interfaces.nsIProperty);
109 a.setProperty(iprop.name, iprop.value);
110 }
111
112 return a;
113 },
114 // XXX enforce legal values for our properties;
115
116 icalAttendeePropMap: [
117 { cal: "mRsvp", ics: "RSVP" },
118 { cal: "commonName", ics: "CN" },
119 { cal: "participationStatus", ics: "PARTSTAT" },
120 { cal: "userType", ics: "CUTYPE" },
121 { cal: "role", ics: "ROLE" } ],
122
123 mIsOrganizer: false,
get_isOrganizer
124 get isOrganizer() { return this.mIsOrganizer; },
set_isOrganizer
125 set isOrganizer(bool) { this.mIsOrganizer = bool; },
126
get_rsvp
127 get rsvp() {
128 return this.mRsvp == "TRUE";
129 },
set_rsvp
130 set rsvp(aValue) {
131 this.modify();
132 this.mRsvp = (aValue ? "TRUE" : "FALSE");
133 },
134
135 // icalatt is a calIcalProperty of type attendee
set_icalProperty
136 set icalProperty (icalatt) {
137 this.modify();
138 this.id = icalatt.valueAsIcalString;
139 var promotedProps = { };
140 for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
141 var prop = this.icalAttendeePropMap[i];
142 this[prop.cal] = icalatt.getParameter(prop.ics);
143 // Don't copy these to the property bag.
144 promotedProps[prop.ics] = true;
145 }
146
147 for (var paramname = icalatt.getFirstParameterName();
148 paramname;
149 paramname = icalatt.getNextParameterName()) {
150 if (promotedProps[paramname])
151 continue;
152 this.setProperty(paramname, icalatt.getParameter(paramname));
153 }
154 },
155
get_icalProperty
156 get icalProperty() {
157 var icssvc = getIcsService();
158 var icalatt;
159 if (!this.mIsOrganizer) {
160 icalatt = icssvc.createIcalProperty("ATTENDEE");
161 } else {
162 icalatt = icssvc.createIcalProperty("ORGANIZER");
163 }
164
165 if (!this.id)
166 throw Components.results.NS_ERROR_NOT_INITIALIZED;
167 icalatt.valueAsIcalString = this.id;
168 for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
169 var prop = this.icalAttendeePropMap[i];
170 if (this[prop.cal])
171 icalatt.setParameter(prop.ics, this[prop.cal]);
172 }
173 var bagenum = this.mProperties.enumerator;
174 while (bagenum.hasMoreElements()) {
175 var iprop = bagenum.getNext();
176 icalatt.setParameter(iprop.name, iprop.value);
177 }
178 return icalatt;
179 },
180
get_propertyEnumerator
181 get propertyEnumerator() { return this.mProperties.enumerator; },
182
183 // The has/get/getUnproxied/set/deleteProperty methods are case-insensitive.
getProperty
184 getProperty: function (aName) {
185 return this.mProperties.getProperty(aName.toUpperCase());
186 },
setProperty
187 setProperty: function (aName, aValue) {
188 this.modify();
189 this.mProperties.setProperty(aName.toUpperCase(), aValue);
190 },
deleteProperty
191 deleteProperty: function (aName) {
192 this.modify();
193 this.mProperties.deleteProperty(aName.toUpperCase());
194 },
195
get_id
196 get id() {
197 return this.mId;
198 },
set_id
199 set id(aId) {
200 this.modify();
201 return this.mId = aId.replace(/^mailto:/i, "MAILTO:");
202 }
203 };
204
205 var makeMemberAttr;
206 if (makeMemberAttr) {
207 makeMemberAttr(calAttendee, "mCommonName", null, "commonName");
208 makeMemberAttr(calAttendee, "mRole", null, "role");
209 makeMemberAttr(calAttendee, "mParticipationStatus", "NEEDS-ACTION",
210 "participationStatus");
211 makeMemberAttr(calAttendee, "mUserType", "INDIVIDUAL", "userType");
212 }