home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 June / PCpro_2006_06.ISO / files / firefox / calendar_windows_latest.xpi / components / calAttendee.js < prev    next >
Encoding:
JavaScript  |  2005-11-26  |  6.5 KB  |  186 lines

  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.  
  39. function calAttendee() {
  40.     this.wrappedJSObject = this;
  41.     this.mProperties = Components.classes["@mozilla.org/hash-property-bag;1"].
  42.         createInstance(Components.interfaces.nsIWritablePropertyBag);
  43. }
  44.  
  45. var calAttendeeClassInfo = {
  46.     getInterfaces: function (count) {
  47.         var ifaces = [
  48.             Components.interfaces.nsISupports,
  49.             Components.interfaces.calIAttendee,
  50.             Components.interfaces.nsIClassInfo
  51.         ];
  52.         count.value = ifaces.length;
  53.         return ifaces;
  54.     },
  55.  
  56.     getHelperForLanguage: function (language) {
  57.         return null;
  58.     },
  59.  
  60.     contractID: "@mozilla.org/calendar/attendee;1",
  61.     classDescription: "Calendar Attendee",
  62.     classID: Components.ID("{5c8dcaa3-170c-4a73-8142-d531156f664d}"),
  63.     implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
  64.     flags: 0
  65. };
  66.  
  67.  
  68. calAttendee.prototype = {
  69.     QueryInterface: function (aIID) {
  70.         if (aIID.equals(Components.interfaces.nsIClassInfo))
  71.             return calAttendeeClassInfo;
  72.  
  73.         if (!aIID.equals(Components.interfaces.nsISupports) &&
  74.             !aIID.equals(Components.interfaces.calIAttendee))
  75.         {
  76.             throw Components.results.NS_ERROR_NO_INTERFACE;
  77.         }
  78.  
  79.         return this;
  80.     },
  81.  
  82.     mImmutable: false,
  83.     get isMutable() { return !this.mImmutable; },
  84.  
  85.     modify: function() {
  86.         if (this.mImmutable)
  87.             throw Components.results.NS_ERROR_FAILURE;
  88.     },
  89.  
  90.     makeImmutable : function() {
  91.         this.mImmutable = true;
  92.     },
  93.  
  94.     clone: function() {
  95.         var a = new calAttendee();
  96.         var allProps = ["id", "commonName", "rsvp", "role", "participantStatus",
  97.                         "userType"];
  98.         for (var i in allProps)
  99.             a[allProps[i]] = this[allProps[i]];
  100.         // clone properties!
  101.         return a;
  102.     },
  103.     // XXX enforce legal values for our properties;
  104.  
  105.     icalAttendeePropMap: [
  106.     { cal: "rsvp",                ics: "RSVP" },
  107.     { cal: "commonName",          ics: "CN" },
  108.     { cal: "participationStatus", ics: "PARTSTAT" },
  109.     { cal: "userType",            ics: "CUTYPE" },
  110.     { cal: "role",                ics: "ROLE" } ],
  111.  
  112.     // icalatt is a calIcalProperty of type attendee
  113.     set icalProperty (icalatt) {
  114.         this.modify();
  115.         this.id = icalatt.valueAsIcalString;
  116.         var promotedProps = { };
  117.         for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
  118.             var prop = this.icalAttendeePropMap[i];
  119.             this[prop.cal] = icalatt.getParameter(prop.ics);
  120.             // Don't copy these to the property bag.
  121.             promotedProps[prop.ics] = true;
  122.         }
  123.  
  124.         for (var paramname = icalatt.getFirstParameterName();
  125.              paramname;
  126.              paramname = icalatt.getNextParameterName()) {
  127.             if (promotedProps[paramname])
  128.                 continue;
  129.             this.setProperty(paramname, icalatt.getParameter(paramname));
  130.         }
  131.     },
  132.  
  133.     get icalProperty() {
  134.         const icssvc =
  135.             Components.classes["@mozilla.org/calendar/ics-service;1"].
  136.                 getService(Components.interfaces.calIICSService);
  137.         var icalatt = icssvc.createIcalProperty("ATTENDEE");
  138.         if (!this.id)
  139.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  140.         icalatt.valueAsIcalString = this.id;
  141.         for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
  142.             var prop = this.icalAttendeePropMap[i];
  143.             if (this[prop.cal])
  144.                 icalatt.setParameter(prop.ics, this[prop.cal]);
  145.         }
  146.         var bagenum = this.mProperties.enumerator;
  147.         while (bagenum.hasMoreElements()) {
  148.             var iprop = bagenum.getNext().
  149.                 QueryInterface(Components.interfaces.nsIProperty);
  150.             icalatt.setParameter(iprop.name, iprop.value);
  151.         }
  152.         return icalatt;
  153.     },
  154.  
  155.     get propertyEnumerator() { return this.mProperties.enumerator; },
  156.     getProperty: function (aName) {
  157.         try {
  158.             return this.mProperties.getProperty(aName);
  159.         } catch (e) {
  160.             return null;
  161.         }
  162.     },
  163.     setProperty: function (aName, aValue) {
  164.         this.modify();
  165.         this.mProperties.setProperty(aName, aValue);
  166.     },
  167.     deleteProperty: function (aName) {
  168.         this.modify();
  169.         try {
  170.             this.mProperties.deleteProperty(aName);
  171.         } catch (e) {
  172.         }
  173.     }
  174. };
  175.  
  176. var makeMemberAttr;
  177. if (makeMemberAttr) {
  178.     makeMemberAttr(calAttendee, "mId", null, "id");
  179.     makeMemberAttr(calAttendee, "mCommonName", null, "commonName");
  180.     makeMemberAttr(calAttendee, "mRsvp", null, "rsvp");
  181.     makeMemberAttr(calAttendee, "mRole", null, "role");
  182.     makeMemberAttr(calAttendee, "mParticipationStatus", "NEEDS-ACTION",
  183.                    "participationStatus");
  184.     makeMemberAttr(calAttendee, "mUserType", "INDIVIDUAL", "userType");
  185. }
  186.