home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / sunbird / js / calAttendee.js < prev    next >
Encoding:
JavaScript  |  2007-05-23  |  7.3 KB  |  212 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.  
  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,
  124.     get isOrganizer() { return this.mIsOrganizer; },
  125.     set isOrganizer(bool) { this.mIsOrganizer = bool; },
  126.  
  127.     get rsvp() { return this.mRsvp == "TRUE"; },
  128.     set rsvp(aValue) { this.mRsvp = (aValue ? "TRUE" : "FALSE"); },
  129.  
  130.     // icalatt is a calIcalProperty of type attendee
  131.     set icalProperty (icalatt) {
  132.         this.modify();
  133.         this.id = icalatt.valueAsIcalString;
  134.         var promotedProps = { };
  135.         for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
  136.             var prop = this.icalAttendeePropMap[i];
  137.             this[prop.cal] = icalatt.getParameter(prop.ics);
  138.             // Don't copy these to the property bag.
  139.             promotedProps[prop.ics] = true;
  140.         }
  141.  
  142.         for (var paramname = icalatt.getFirstParameterName();
  143.              paramname;
  144.              paramname = icalatt.getNextParameterName()) {
  145.             if (promotedProps[paramname])
  146.                 continue;
  147.             this.setProperty(paramname, icalatt.getParameter(paramname));
  148.         }
  149.     },
  150.  
  151.     get icalProperty() {
  152.         const icssvc =
  153.             Components.classes["@mozilla.org/calendar/ics-service;1"].
  154.                 getService(Components.interfaces.calIICSService);
  155.  
  156.         var icalatt;
  157.         if (!this.mIsOrganizer) {
  158.             icalatt = icssvc.createIcalProperty("ATTENDEE");
  159.         } else {
  160.             icalatt = icssvc.createIcalProperty("ORGANIZER");
  161.         }
  162.  
  163.         if (!this.id)
  164.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  165.         icalatt.valueAsIcalString = this.id;
  166.         for (var i = 0; i < this.icalAttendeePropMap.length; i++) {
  167.             var prop = this.icalAttendeePropMap[i];
  168.             if (this[prop.cal])
  169.                 icalatt.setParameter(prop.ics, this[prop.cal]);
  170.         }
  171.         var bagenum = this.mProperties.enumerator;
  172.         while (bagenum.hasMoreElements()) {
  173.             var iprop = bagenum.getNext().
  174.                 QueryInterface(Components.interfaces.nsIProperty);
  175.             icalatt.setParameter(iprop.name, iprop.value);
  176.         }
  177.         return icalatt;
  178.     },
  179.  
  180.     get propertyEnumerator() { return this.mProperties.enumerator; },
  181.  
  182.     // The has/get/getUnproxied/set/deleteProperty methods are case-insensitive.
  183.     getProperty: function (aName) {
  184.         try {
  185.             return this.mProperties.getProperty(aName.toUpperCase());
  186.         } catch (e) {
  187.             return null;
  188.         }
  189.     },
  190.     setProperty: function (aName, aValue) {
  191.         this.modify();
  192.         this.mProperties.setProperty(aName.toUpperCase(), aValue);
  193.     },
  194.     deleteProperty: function (aName) {
  195.         this.modify();
  196.         try {
  197.             this.mProperties.deleteProperty(aName.toUpperCase());
  198.         } catch (e) {
  199.         }
  200.     }
  201. };
  202.  
  203. var makeMemberAttr;
  204. if (makeMemberAttr) {
  205.     makeMemberAttr(calAttendee, "mId", null, "id");
  206.     makeMemberAttr(calAttendee, "mCommonName", null, "commonName");
  207.     makeMemberAttr(calAttendee, "mRole", null, "role");
  208.     makeMemberAttr(calAttendee, "mParticipationStatus", "NEEDS-ACTION",
  209.                    "participationStatus");
  210.     makeMemberAttr(calAttendee, "mUserType", "INDIVIDUAL", "userType");
  211. }
  212.