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 / calItipItem.js < prev    next >
Encoding:
JavaScript  |  2007-05-23  |  9.7 KB  |  287 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 Lightning code.
  16.  *
  17.  * The Initial Developer of the Original Code is Simdesk Technologies Inc.
  18.  * Portions created by the Initial Developer are Copyright (C) 2006
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Clint Talbert <ctalbert.moz@gmail.com>
  23.  *   Matthew Willis <lilmatt@mozilla.com>
  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. /**
  40.  * Constructor of calItipItem object
  41.  */
  42. function calItipItem() {
  43.     this.wrappedJSObject = this;
  44.     this.mIsInitialized = false;
  45.     this.mCurrentItemIndex = 0;
  46. }
  47.  
  48. calItipItem.prototype = {
  49.     getInterfaces: function ciiGI(count) {
  50.         var ifaces = [
  51.             Ci.nsIClassInfo,
  52.             Ci.nsISupports,
  53.             Ci.calIItipItem
  54.         ];
  55.         count.value = ifaces.length;
  56.         return ifaces;
  57.     },
  58.  
  59.     getHelperForLanguage: function ciiGHFL(aLanguage) {
  60.         return null;
  61.     },
  62.  
  63.     contractID: "@mozilla.org/calendar/itip-item;1",
  64.     classDescription: "Calendar iTIP item",
  65.     classID: Components.ID("{f41392ab-dcad-4bad-818f-b3d1631c4d93}"),
  66.     implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
  67.     flags: 0,
  68.  
  69.     QueryInterface: function ciiQI(aIid) {
  70.         if (!aIid.equals(Ci.nsISupports) && !aIid.equals(Ci.calIItipItem)) {
  71.             throw Components.results.NS_ERROR_NO_INTERFACE;
  72.         }
  73.  
  74.         return this;
  75.     },
  76.  
  77.     mIsSend: false,
  78.     get isSend() {
  79.         return this.mIsSend;
  80.     },
  81.     set isSend(aValue) {
  82.         return (this.mIsSend = aValue);
  83.     },
  84.  
  85.     mReceivedMethod: null,
  86.     get receivedMethod() {
  87.         return this.mReceivedMethod;
  88.     },
  89.     set receivedMethod(aMethod) {
  90.         return (this.mReceivedMethod = aMethod.toUpperCase());
  91.     },
  92.  
  93.     mResponseMethod: null,
  94.     get responseMethod() {
  95.         if (this.mIsInitialized) {
  96.             var method = null;
  97.             for each (var prop in this.mPropertiesList) {
  98.                 if (prop.propertyName == "METHOD") {
  99.                     method = prop.value;
  100.                     break;
  101.                 }
  102.             }
  103.             return method;
  104.         } else {
  105.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  106.         }
  107.     },
  108.     set responseMethod(aMethod) {
  109.         this.mResponseMethod = aMethod.toUpperCase();
  110.         // Setting this also sets the global method attribute inside the
  111.         // encapsulated VCALENDAR.
  112.         if (this.mIsInitialized) {
  113.             var methodExists = false;
  114.             for each (var prop in this.mPropertiesList) {
  115.                 if (prop.propertyName == "METHOD") {
  116.                     methodExists = true;
  117.                     prop.value = this.mResponseMethod;
  118.                 }
  119.             }
  120.  
  121.             if (!methodExists) {
  122.                 var newProp = { propertyName: "METHOD",
  123.                                 value: this.mResponseMethod };
  124.                 this.mPropertiesList.push(newProp);
  125.             }
  126.         } else {
  127.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  128.         }
  129.         return this.mResponseMethod;
  130.     },
  131.  
  132.     mAutoResponse: null,
  133.     get autoResponse() {
  134.         return this.mAutoResponse;
  135.     },
  136.     set autoResponse(aValue) {
  137.         return (this.mAutoResponse = aValue);
  138.     },
  139.  
  140.     mTargetCalendar: null,
  141.     get targetCalendar() {
  142.         return this.mTargetCalendar;
  143.     },
  144.     set targetCalendar(aValue) {
  145.         return (this.mTargetCalendar = aValue);
  146.     },
  147.  
  148.     mLocalStatus: null,
  149.     get localStatus() {
  150.         return this.mLocalStatus;
  151.     },
  152.     set localStatus(aValue) {
  153.         return (this.mLocalStatus = aValue);
  154.      },
  155.  
  156.     modifyItem: function ciiMI(item) {
  157.         // Bug 348666: This will be used when we support delegation and COUNTER.
  158.         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  159.     },
  160.  
  161.     mItemList: null,
  162.     mPropertiesList: null,
  163.  
  164.     init: function ciiI(aIcalString) {
  165.         var parser = Cc["@mozilla.org/calendar/ics-parser;1"].
  166.                      createInstance(Ci.calIIcsParser);
  167.         parser.parseString(aIcalString);
  168.         this.mItemList = parser.getItems({});
  169.         this.mPropertiesList = parser.getProperties({});
  170.  
  171.         // We set both methods now for safety's sake. It's the ItipProcessor's
  172.         // responsibility to properly ascertain what the correct response
  173.         // method is (using user feedback, prefs, etc.) for the given
  174.         // receivedMethod.  The RFC tells us to treat items without a METHOD
  175.         // as if they were METHOD:REQUEST.
  176.         var method;
  177.         for each (var prop in this.mPropertiesList) {
  178.             if (prop.propertyName == "METHOD") {
  179.                 method = prop.value;
  180.             }
  181.         }
  182.         this.mReceivedMethod = method;
  183.         this.mResponseMethod = method;
  184.  
  185.         this.mIsInitialized = true;
  186.     },
  187.  
  188.     clone: function ciiC() {
  189.         // Iterate through all the calItems in the original calItipItem to
  190.         // concatenate all the calItems' icalStrings.
  191.         var icalString = "";
  192.  
  193.         var itemList = this.getItemList({ });
  194.         for (var i = 0; i < itemList.length; i++) {
  195.             icalString += itemList[i].icalString;
  196.         }
  197.  
  198.         // Create a new calItipItem and initialize it using the icalString
  199.         // from above.
  200.         var newItem = Cc["@mozilla.org/calendar/itip-item;1"].
  201.                       createInstance(Ci.calIItipItem);
  202.         newItem.init(icalString);
  203.  
  204.         // Copy over the exposed attributes.
  205.         newItem.receivedMethod = this.receivedMethod;
  206.         newItem.responseMethod = this.responseMethod;
  207.         newItem.autoResponse = this.autoResponse;
  208.         newItem.targetCalendar = this.targetCalendar;
  209.         newItem.localStatus = this.localStatus;
  210.         newItem.isSend = this.isSend;
  211.  
  212.         return newItem;
  213.     },
  214.  
  215.     /**
  216.      * This returns both the array and the number of items. An easy way to
  217.      * call it is: var itemArray = itipItem.getItemList({ });
  218.      */
  219.     getItemList: function ciiGIL(itemCountRef) {
  220.         if (!this.mIsInitialized || (this.mItemList.length == 0)) {
  221.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  222.         }
  223.         itemCountRef.value = this.mItemList.length;
  224.         return this.mItemList;
  225.     },
  226.  
  227.     /*getFirstItem: function ciiGFI() {
  228.         if (!this.mIsInitialized || (this.mItemList.length == 0)) {
  229.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  230.         }
  231.         this.mCurrentItemIndex = 0;
  232.         return this.mItemList[0];
  233.     },
  234.  
  235.     getNextItem: function ciiGNI() {
  236.         if (!this.mIsInitialized || (this.mItemList.length == 0)) {
  237.             throw Components.results.NS_ERROR_NOT_INITIALIZED;
  238.         }
  239.         ++this.mCurrentItemIndex;
  240.         if (this.mCurrentItemIndex < this.mItemList.length) {
  241.             return this.mItemList[this.mCurrentItemIndex];
  242.         } else {
  243.             return null;
  244.         }
  245.     },*/
  246.  
  247.     /**
  248.      * Note that this code forces the user to respond to all items in the same
  249.      * way, which is a current limitation of the spec.
  250.      */
  251.     setAttendeeStatus: function ciiSAS(aAttendeeId, aStatus) {
  252.         // Append "mailto:" to the attendee if it is missing it.
  253.         var attId = aAttendeeId.toLowerCase();
  254.         if (!attId.match(/mailto:/i)) {
  255.             attId = "mailto:" + attId;
  256.         }
  257.  
  258.         for each (var item in this.mItemList) {
  259.             var attendee = item.getAttendeeById(attId);
  260.             if (attendee) {
  261.                 // XXX BUG 351589: workaround for updating an attendee
  262.                 item.removeAttendee(attendee);
  263.  
  264.                 // Replies should not have the RSVP property.
  265.                 // Since attendee.deleteProperty("RSVP") doesn't work, we must
  266.                 // create a new attendee from scratch WITHOUT the RSVP
  267.                 // property and copy in the other relevant data.
  268.                 // XXX use deleteProperty after bug 358498 is fixed.
  269.                 newAttendee = Cc["@mozilla.org/calendar/attendee;1"].
  270.                               createInstance(Ci.calIAttendee);
  271.                 if (attendee.commonName) {
  272.                     newAttendee.commonName = attendee.commonName;
  273.                 }
  274.                 if (attendee.role) {
  275.                     newAttendee.role = attendee.role;
  276.                 }
  277.                 if (attendee.userType) {
  278.                     newAttendee.userType = attendee.userType;
  279.                 }
  280.                 newAttendee.id = attendee.id;
  281.                 newAttendee.participationStatus = aStatus;
  282.                 item.addAttendee(newAttendee);
  283.             }
  284.         }
  285.     }
  286. };
  287.