!import
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 var gMsgCompose = false;
38
GetAbViewListener
39 function GetAbViewListener()
40 {
41 // the ab panel doesn't care if the total changes, or if the selection changes
42 return null;
43 }
44
45 var gAddressBookPanelAbListener = {
onItemAdded
46 onItemAdded: function(parentDir, item) {
47 // will not be called
48 },
onItemRemoved
49 onItemRemoved: function(parentDir, item) {
50 // will only be called when an addressbook is deleted
51 try {
52 var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
53 // check if the item being removed is the directory
54 // that we are showing in the addressbook sidebar
55 // if so, select the person addressbook (it can't be removed)
56 if (directory == GetAbView().directory) {
57 var abPopup = document.getElementById('addressbookList');
58 abPopup.value = kPersonalAddressbookURI;
59 LoadPreviouslySelectedAB();
60 }
61 }
62 catch (ex) {
63 }
64 },
onItemPropertyChanged
65 onItemPropertyChanged: function(item, property, oldValue, newValue) {
66 try {
67 var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
68 // check if the item being changed is the directory
69 // that we are showing in the addressbook sidebar
70 if (directory == GetAbView().directory) {
71 LoadPreviouslySelectedAB();
72 }
73 }
74 catch (ex) {
75 }
76 }
77 };
78
79
80 // XXX todo
81 // can we combine some common code? see OnLoadNewMailList()
82 // set popup with address book names
LoadPreviouslySelectedAB
83 function LoadPreviouslySelectedAB()
84 {
85 var abPopup = document.getElementById('addressbookList');
86 var value = abPopup.value || kPersonalAddressbookURI;
87 abPopup.selectedItem = null;
88 abPopup.value = value;
89 ChangeDirectoryByURI(abPopup.selectedItem.id);
90 }
91
AbPanelLoad
92 function AbPanelLoad()
93 {
94 InitCommonJS();
95
96 UpgradeAddressBookResultsPaneUI("mailnews.ui.addressbook_panel_results.version");
97
98 SetupAbCommandUpdateHandlers();
99
100 LoadPreviouslySelectedAB();
101
102 // Add a listener, so we can switch directories if the current directory is
103 // deleted, and change the name if the selected directory's name is modified.
104 // This listener only cares when a directory is removed or modified.
105 Components.classes["@mozilla.org/abmanager;1"]
106 .getService(Components.interfaces.nsIAbManager)
107 .addAddressBookListener(gAddressBookAbListener,
108 nsIAbListener.directoryRemoved |
109 nsIAbListener.itemChanged);
110
111 gSearchInput = document.getElementById("searchInput");
112
113 // for the compose window we want to show To, Cc, Bcc and a separator
114 // for all other windows we want to show Compose Mail To
115 var popup = document.getElementById("composeMail");
116 gMsgCompose = parent.document.documentElement.getAttribute("windowtype") == "msgcompose";
117 for (var i = 0; i < 4; i++)
118 popup.childNodes[i].hidden = !gMsgCompose;
119 popup.childNodes[4].hidden = gMsgCompose;
120 }
121
AbPanelUnload
122 function AbPanelUnload()
123 {
124 Components.classes["@mozilla.org/abmanager;1"]
125 .getService(Components.interfaces.nsIAbManager)
126 .removeAddressBookListener(gAddressBookPanelAbListener);
127
128 CloseAbView();
129 }
130
AbPanelAdd
131 function AbPanelAdd(addrtype)
132 {
133 var cards = GetSelectedAbCards();
134 var count = cards.length;
135
136 for (var i = 0; i < count; i++) {
137 // turn each card into a properly formatted address
138 var address = GenerateAddressFromCard(cards[i]);
139 if (address)
140 top.awAddRecipient(addrtype, address);
141 else if (gPromptService)
142 gPromptService.alert(window,
143 gAddressBookBundle.getString("emptyEmailAddCardTitle"),
144 gAddressBookBundle.getString("emptyEmailAddCard"));
145 }
146 }
147
AbPanelNewCard
148 function AbPanelNewCard()
149 {
150 goNewCardDialog(abList.selectedItem.getAttribute('id'));
151 }
152
AbPanelNewList
153 function AbPanelNewList()
154 {
155 goNewListDialog(abList.selectedItem.getAttribute('id'));
156 }
157
ResultsPaneSelectionChanged
158 function ResultsPaneSelectionChanged()
159 {
160 // do nothing for ab panel
161 }
162
OnClickedCard
163 function OnClickedCard()
164 {
165 // do nothing for ab panel
166 }
167
AbResultsPaneDoubleClick
168 function AbResultsPaneDoubleClick(card)
169 {
170 // double click for ab panel means "send mail to this person / list"
171 if (gMsgCompose)
172 AbPanelAdd('addr_to');
173 else
174 AbNewMessage();
175 }
176
UpdateCardView
177 function UpdateCardView()
178 {
179 // do nothing for ab panel
180 }