зеркало из https://github.com/mozilla/pjs.git
fix mAttendees typo
This commit is contained in:
Родитель
6c343c46fc
Коммит
69d4ea526b
|
@ -78,7 +78,7 @@ calItemBase.prototype = {
|
|||
|
||||
m.mAttendees = [];
|
||||
for (var i = 0; i < this.mAttendees.length; i++)
|
||||
mAttendees[i] = this.mAttendees[i].clone();
|
||||
m.mAttendees[i] = this.mAttendees[i].clone();
|
||||
|
||||
|
||||
m.mAttachments = this.mAttachments;
|
||||
|
|
|
@ -1,396 +0,0 @@
|
|||
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
|
||||
* Mike Shaver <shaver@off.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// calItemBase.js
|
||||
//
|
||||
|
||||
const ICAL = Components.interfaces.calIIcalComponent;
|
||||
|
||||
function calItemBase() { }
|
||||
|
||||
calItemBase.prototype = {
|
||||
QueryInterface: function (aIID) {
|
||||
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
||||
!aIID.equals(Components.interfaces.calIItemBase))
|
||||
{
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
mImmutable: false,
|
||||
get isMutable() { return !this.mImmutable; },
|
||||
|
||||
makeItemBaseImmutable: function() {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
|
||||
// make all our components immutable
|
||||
this.mCreationDate.makeImmutable();
|
||||
|
||||
if (this.mRecurrenceInfo)
|
||||
this.mRecurrenceInfo.makeImmutable();
|
||||
if (this.mAlarmTime)
|
||||
this.mAlarmTime.makeImmutable();
|
||||
|
||||
for (var i = 0; i < this.mAttendees.length; i++)
|
||||
this.mAttendees[i].makeImmutable();
|
||||
this.mImmutable = true;
|
||||
},
|
||||
|
||||
// initialize this class's members
|
||||
initItemBase: function () {
|
||||
this.mCreationDate = new CalDateTime();
|
||||
this.mAlarmTime = new CalDateTime();
|
||||
this.mLastModifiedTime = new CalDateTime();
|
||||
|
||||
this.mCreationDate.jsDate = new Date();
|
||||
this.mLastModifiedTime.jsDate = new Date();
|
||||
|
||||
this.mProperties = Components.classes["@mozilla.org/hash-property-bag;1"].
|
||||
createInstance(Components.interfaces.nsIWritablePropertyBag);
|
||||
|
||||
this.mAttendees = [];
|
||||
|
||||
this.mRecurrenceInfo = null;
|
||||
|
||||
this.mAttachments = null;
|
||||
},
|
||||
|
||||
// for subclasses to use; copies the ItemBase's values
|
||||
// into m
|
||||
cloneItemBaseInto: function (m) {
|
||||
m.mImmutable = false;
|
||||
m.mGeneration = this.mGeneration;
|
||||
m.mLastModifiedTime = this.mLastModifiedTime.clone();
|
||||
m.mParent = this.mParent;
|
||||
m.mId = this.mId;
|
||||
m.mTitle = this.mTitle;
|
||||
m.mPriority = this.mPriority;
|
||||
m.mPrivacy = this.mPrivacy;
|
||||
m.mStatus = this.mStatus;
|
||||
m.mHasAlarm = this.mHasAlarm;
|
||||
|
||||
m.mCreationDate = this.mCreationDate.clone();
|
||||
|
||||
if (this.mRecurrenceInfo) {
|
||||
m.mRecurrenceInfo = this.mRecurrenceInfo.clone();
|
||||
dump ("old recurType: " + this.mRecurrenceInfo.recurType + " new type: " + m.mRecurrenceInfo.recurType + "\n");
|
||||
}
|
||||
if (this.mAlarmTime)
|
||||
m.mAlarmTime = this.mAlarmTime.clone();
|
||||
|
||||
m.mAttendees = [];
|
||||
for (var i = 0; i < this.mAttendees.length; i++)
|
||||
mAttendees[i] = this.mAttendees[i].clone();
|
||||
|
||||
// these need fixing
|
||||
m.mAttachments = this.mAttachments;
|
||||
|
||||
m.mProperties = Components.classes["@mozilla.org/hash-property-bag;1"].
|
||||
createInstance(Components.interfaces.nsIWritablePropertyBag);
|
||||
|
||||
var e = this.mProperties.enumerator;
|
||||
while (e.hasMoreElements()) {
|
||||
var prop = e.getNext().QueryInterface(Components.interfaces.nsIProperty);
|
||||
m.mProperties.setProperty (prop.name, prop.value);
|
||||
}
|
||||
|
||||
return m;
|
||||
},
|
||||
|
||||
#define MEMBER_ATTR(varname, initvalue, attrname) \
|
||||
varname: initvalue, \
|
||||
get attrname() { return this.varname; }, \
|
||||
set attrname(v) { if (this.mImmutable) throw Components.results.NS_ERROR_FAILURE; else this.varname = v; dump("set " + #attrname + " to " + v + "\n");}
|
||||
|
||||
MEMBER_ATTR(mGeneration, 0, generation),
|
||||
MEMBER_ATTR(mCreationDate, null, creationDate),
|
||||
MEMBER_ATTR(mLastModifiedTime, null, lastModifiedTime),
|
||||
MEMBER_ATTR(mParent, null, parent),
|
||||
MEMBER_ATTR(mId, null, id),
|
||||
MEMBER_ATTR(mTitle, "", title),
|
||||
MEMBER_ATTR(mPriority, 0, priority),
|
||||
MEMBER_ATTR(mPrivacy, "PUBLIC", privacy),
|
||||
MEMBER_ATTR(mStatus, null, status),
|
||||
MEMBER_ATTR(mHasAlarm, false, hasAlarm),
|
||||
MEMBER_ATTR(mAlarmTime, null, alarmTime),
|
||||
MEMBER_ATTR(mRecurrenceInfo, null, recurrenceInfo),
|
||||
MEMBER_ATTR(mAttachments, null, attachments),
|
||||
MEMBER_ATTR(mProperties, null, properties),
|
||||
|
||||
#undef MEMBER_ATTR
|
||||
|
||||
get propertyEnumerator() { return this.mProperties.enumerator; },
|
||||
|
||||
getProperty: function (aName) {
|
||||
try {
|
||||
return this.mProperties.getProperty(aName);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
setProperty: function (aName, aValue) {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
this.mProperties.setProperty(aName, aValue);
|
||||
},
|
||||
|
||||
deleteProperty: function (aName) {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
try {
|
||||
this.mProperties.deleteProperty(aName);
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
|
||||
getAttendees: function (countObj) {
|
||||
countObj.value = this.mAttendees.length;
|
||||
return this.mAttendees.concat([]); // clone
|
||||
},
|
||||
|
||||
getAttendeeById: function (id) {
|
||||
for (var i = 0; i < this.mAttendees.length; i++)
|
||||
if (this.mAttendees[i].id == id)
|
||||
return this.mAttendees[i];
|
||||
return null;
|
||||
},
|
||||
|
||||
removeAttendee: function (attendee) {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
var found = false, newAttendees = [];
|
||||
for (var i = 0; i < this.mAttendees.length; i++) {
|
||||
if (this.mAttendees[i] != attendee)
|
||||
newAttendees.push(this.mAttendees[i]);
|
||||
else
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
this.mAttendees = newAttendees;
|
||||
else
|
||||
throw Component.results.NS_ERROR_INVALID_ARG;
|
||||
},
|
||||
|
||||
removeAllAttendees: function() {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
this.mAttendees = [];
|
||||
},
|
||||
|
||||
addAttendee: function (attendee) {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
this.mAttendees.push(attendee);
|
||||
},
|
||||
|
||||
/* MEMBER_ATTR(mIcalString, "", icalString), */
|
||||
get icalString() {
|
||||
throw Components.results.NS_NOT_IMPLEMENTED;
|
||||
},
|
||||
|
||||
set icalString() {
|
||||
throw Components.results.NS_NOT_IMPLEMENTED;
|
||||
},
|
||||
|
||||
itemBasePromotedProps: {
|
||||
"CREATED": true,
|
||||
"UID": true,
|
||||
"LASTMODIFIED": true,
|
||||
"SUMMARY": true,
|
||||
"PRIORITY": true,
|
||||
"METHOD": true,
|
||||
"STATUS": true,
|
||||
"CLASS": true,
|
||||
"DTALARM": true,
|
||||
"X-MOZILLA-GENERATION": true,
|
||||
},
|
||||
|
||||
mapPropsFromICS: function(icalcomp, propmap) {
|
||||
for (var i = 0; i < propmap.length; i++) {
|
||||
var prop = propmap[i];
|
||||
var val = icalcomp[prop.ics];
|
||||
if (val != null && val != ICAL.INVALID_VALUE)
|
||||
this[prop.cal] = val;
|
||||
}
|
||||
},
|
||||
|
||||
mapPropsToICS: function(icalcomp, propmap) {
|
||||
for (var i = 0; i < propmap.length; i++) {
|
||||
var prop = propmap[i];
|
||||
if (!(prop.cal in this))
|
||||
continue;
|
||||
var val = this[prop.cal];
|
||||
if (val != null && val != ICAL.INVALID_VALUE)
|
||||
icalcomp[prop.ics] = val;
|
||||
}
|
||||
},
|
||||
|
||||
icsBasePropMap: [
|
||||
{ cal: "mCreationDate", ics: "createdTime" },
|
||||
{ cal: "mLastModifiedTime", ics: "lastModified" },
|
||||
{ cal: "mId", ics: "uid" },
|
||||
{ cal: "mTitle", ics: "summary" },
|
||||
{ cal: "mPriority", ics: "priority" },
|
||||
{ cal: "mStatus", ics: "status" },
|
||||
{ cal: "mPrivacy", ics: "icalClass" }],
|
||||
|
||||
setItemBaseFromICS: function (icalcomp) {
|
||||
if (this.mImmutable)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
this.mapPropsFromICS(icalcomp, this.icsBasePropMap);
|
||||
this.mPrivacy = icalcomp.icalClass;
|
||||
|
||||
for (var attprop = icalcomp.getFirstProperty("ATTENDEE");
|
||||
attprop;
|
||||
attprop = icalcomp.getNextProperty("ATTENDEE")) {
|
||||
|
||||
var att = new CalAttendee();
|
||||
att.icalProperty = attprop;
|
||||
this.addAttendee(att);
|
||||
}
|
||||
|
||||
var gen = icalcomp.getFirstProperty("X-MOZILLA-GENERATION");
|
||||
if (gen)
|
||||
this.mGeneration = parseInt(gen.stringValue);
|
||||
},
|
||||
|
||||
importUnpromotedProperties: function (icalcomp, promoted) {
|
||||
for (var prop = icalcomp.getFirstProperty("ANY");
|
||||
prop;
|
||||
prop = icalcomp.getNextProperty("ANY")) {
|
||||
if (!promoted[prop.propertyName]) {
|
||||
// XXX keep parameters around, sigh
|
||||
this.setProperty(prop.propertyName, prop.stringValue);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get icalComponent() {
|
||||
throw Components.results.NS_NOT_IMPLEMENTED;
|
||||
},
|
||||
|
||||
fillIcalComponentFromBase: function (icalcomp) {
|
||||
this.mapPropsToICS(icalcomp, this.icsBasePropMap);
|
||||
icalcomp.icalClass = this.mPrivacy;
|
||||
for (var i = 0; i < this.mAttendees.length; i++)
|
||||
icalcomp.addProperty(this.mAttendees[i].icalProperty);
|
||||
if (this.mGeneration != 0) {
|
||||
var genprop = icalProp("X-MOZILLA-GENERATION");
|
||||
genprop.stringValue = String(this.mGeneration);
|
||||
icalcomp.addProperty(genprop);
|
||||
}
|
||||
if (this.mRecurrenceInfo)
|
||||
icalcomp.addProperty(this.mRecurrenceInfo.icalProperty);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
function calItemOccurrence () {
|
||||
this.wrappedJSObject = this;
|
||||
|
||||
this.occurrenceStartDate = new CalDateTime();
|
||||
this.occurrenceEndDate = new CalDateTime();
|
||||
}
|
||||
|
||||
calItemOccurrence.prototype = {
|
||||
QueryInterface: function (aIID) {
|
||||
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
||||
!aIID.equals(Components.interfaces.calIItemOccurrence))
|
||||
{
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
initialize: function (aItem, aStartDate, aEndDate) {
|
||||
this.item = aItem;
|
||||
this.occurrenceStartDate = aStartDate.clone();
|
||||
this.occurrenceStartDate.makeImmutable();
|
||||
this.occurrenceEndDate = aEndDate.clone();
|
||||
this.occurrenceEndDate.makeImmutable();
|
||||
},
|
||||
|
||||
item: null,
|
||||
occurrenceStartDate: null,
|
||||
occurrenceEndDate: null,
|
||||
|
||||
get next() {
|
||||
if (this.item.recurrenceInfo)
|
||||
return this.item.recurrenceInfo.getNextOccurrence(this.item, aEndDate);
|
||||
return null;
|
||||
},
|
||||
get previous() {
|
||||
if (this.item.recurrenceInfo)
|
||||
return this.item.recurrenceInfo.getPreviousOccurrence(this.item, aStartDate);
|
||||
return null;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
|
||||
const CalDateTime =
|
||||
new Components.Constructor("@mozilla.org/calendar/datetime;1",
|
||||
Components.interfaces.calIDateTime);
|
||||
|
||||
const CalAttendee =
|
||||
new Components.Constructor("@mozilla.org/calendar/attendee;1",
|
||||
Components.interfaces.calIAttendee);
|
||||
|
||||
function icalFromString(str)
|
||||
{
|
||||
const icssvc = Components.classes["@mozilla.org/calendar/ics-service;1"].
|
||||
getService(Components.interfaces.calIICSService);
|
||||
return icssvc.parseICS(str);
|
||||
}
|
||||
|
||||
function icalProp(kind)
|
||||
{
|
||||
const icssvc = Components.classes["@mozilla.org/calendar/ics-service;1"].
|
||||
getService(Components.interfaces.calIICSService);
|
||||
return icssvc.createIcalProperty(kind);
|
||||
}
|
Загрузка…
Ссылка в новой задаче