home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / messenger.jar / content / messenger / addressbook / addressbook-panel.js < prev    next >
Text File  |  2005-07-29  |  6KB  |  172 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla addressbook.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Seth Spitzer <sspitzer@netscape.com>.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. function GetAbViewListener()
  38. {
  39.   // the ab panel doesn't care if the total changes, or if the selection changes
  40.   return null;
  41. }
  42.  
  43. var gAddressBookPanelAbListener = {
  44.   onItemAdded: function(parentDir, item) {
  45.     // will not be called
  46.   },
  47.   onItemRemoved: function(parentDir, item) {
  48.     // will only be called when an addressbook is deleted
  49.     try {
  50.       var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
  51.       // check if the item being removed is the directory
  52.       // that we are showing in the addressbook sidebar
  53.       // if so, select the person addressbook (it can't be removed)
  54.       if (directory == GetAbView().directory) {
  55.           var abPopup = document.getElementById('addressbookList');
  56.           abPopup.setAttribute("selectedAB", kPersonalAddressbookURI);
  57.           LoadPreviouslySelectedAB();
  58.       } 
  59.     }
  60.     catch (ex) {
  61.     }
  62.   },
  63.   onItemPropertyChanged: function(item, property, oldValue, newValue) {
  64.     try {
  65.       var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
  66.       // check if the item being changed is the directory
  67.       // that we are showing in the addressbook sidebar
  68.       if (directory == GetAbView().directory) {
  69.           LoadPreviouslySelectedAB();
  70.       }
  71.     }
  72.     catch (ex) {
  73.     }
  74.   }
  75. };
  76.  
  77.  
  78. // XXX todo
  79. // can we combine some common code?  see OnLoadNewMailList()
  80. // set popup with address book names
  81. function LoadPreviouslySelectedAB()
  82. {
  83.   var abPopup = document.getElementById('addressbookList');
  84.   if ( abPopup )
  85.   {
  86.     var menupopup = document.getElementById('addressbookList-menupopup');
  87.     var selectedAB = abPopup.getAttribute("selectedAB");
  88.     if (!selectedAB) 
  89.       selectedAB = kPersonalAddressbookURI;
  90.       
  91.     if ( selectedAB && menupopup && menupopup.childNodes )
  92.     {
  93.       for ( var index = menupopup.childNodes.length - 1; index >= 0; index-- )
  94.       {
  95.         if ( menupopup.childNodes[index].getAttribute('value') == selectedAB )
  96.         {
  97.           abPopup.label = menupopup.childNodes[index].getAttribute('label');
  98.           abPopup.value = menupopup.childNodes[index].getAttribute('value');
  99.           break;
  100.         }
  101.       }
  102.     }
  103.   }
  104.   ChangeDirectoryByURI(abPopup.selectedItem.id);
  105. }
  106.  
  107. function AbPanelLoad() 
  108. {
  109.   InitCommonJS(); 
  110.  
  111.   UpgradeAddressBookResultsPaneUI("mailnews.ui.addressbook_panel_results.version");
  112.  
  113.   LoadPreviouslySelectedAB();
  114.  
  115.   // add a listener, so we can switch directories if
  116.   // the current directory is deleted, and change the name if the
  117.   // selected directory's name is modified
  118.   var addrbookSession = Components.classes["@mozilla.org/addressbook/services/session;1"].getService().QueryInterface(Components.interfaces.nsIAddrBookSession);
  119.   // this listener only cares when a directory is removed or modified
  120.   addrbookSession.addAddressBookListener(gAddressBookPanelAbListener,
  121.                   Components.interfaces.nsIAbListener.directoryRemoved | Components.interfaces.nsIAbListener.changed);
  122.  
  123.   gSearchInput = document.getElementById("searchInput");
  124. }
  125.  
  126.  
  127. function AbPanelOnChange(event)
  128. {
  129.   var abPopup = document.getElementById('addressbookList');
  130.   abPopup.setAttribute("selectedAB", abPopup.value);
  131. }
  132.  
  133. function AbPanelUnload()
  134. {
  135.   var addrbookSession = Components.classes["@mozilla.org/addressbook/services/session;1"].getService().QueryInterface(Components.interfaces.nsIAddrBookSession);
  136.   addrbookSession.removeAddressBookListener(gAddressBookPanelAbListener);
  137.  
  138.   CloseAbView();
  139. }
  140.  
  141. function AbPanelNewCard() 
  142. {
  143.   goNewCardDialog(abList.selectedItem.getAttribute('id'));
  144. }
  145.  
  146. function AbPanelNewList() 
  147. {
  148.   goNewListDialog(abList.selectedItem.getAttribute('id'));
  149. }
  150.  
  151. function ResultsPaneSelectionChanged() 
  152. {
  153.   // do nothing for ab panel
  154. }
  155.  
  156. function OnClickedCard() 
  157. {
  158.   // do nothing for ab panel
  159. }
  160.  
  161. function AbResultsPaneDoubleClick(card) 
  162. {
  163.   // double click for ab panel means "send mail to this person / list"
  164.   AbNewMessage();
  165. }
  166.  
  167. function UpdateCardView() 
  168. {
  169.   // do nothing for ab panel
  170. }
  171.  
  172.