!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
GetAbViewListener
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
contactsListDoubleClick
44 function contactsListDoubleClick(event)
45 {
46 // we only care about button 0 (left click) events
47 if (event.button != 0)
48 return;
49
50 var contactsTree = document.getElementById("abResultsTree");
51 var row = contactsTree.treeBoxObject.getRowAt(event.clientX, event.clientY);
52 if (row == -1 || row > contactsTree.view.rowCount-1 || event.originalTarget.localName != "treechildren")
53 {
54 // double clicking on a non valid row should not open the edit filter dialog
55 return;
56 }
57
58 // ok, go ahead and add the entry
59 addSelectedAddresses('addr_to');
60 }
61
addSelectedAddresses
62 function addSelectedAddresses(recipientType)
63 {
64 var cards = GetSelectedAbCards();
65 var count = cards.length;
66
67
68 for (var i = 0; i < count; i++)
69 {
70 // turn each card into a properly formatted address
71 var address = GenerateAddressFromCard(cards[i]);
72 if (address != "")
73 parent.AddRecipient(recipientType, address);
74 }
75 }
76
77 var gAddressBookPanelAbListener = {
onItemAdded
78 onItemAdded: function(parentDir, item) {
79 // will not be called
80 },
onItemRemoved
81 onItemRemoved: function(parentDir, item) {
82 // will only be called when an addressbook is deleted
83 try {
84 var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
85 // check if the item being removed is the directory
86 // that we are showing in the addressbook sidebar
87 // if so, select the person addressbook (it can't be removed)
88 if (directory == GetAbView().directory) {
89 var abPopup = document.getElementById('addressbookList');
90 abPopup.value = kPersonalAddressbookURI;
91 LoadPreviouslySelectedAB();
92 }
93 }
94 catch (ex) {
95 }
96 },
onItemPropertyChanged
97 onItemPropertyChanged: function(item, property, oldValue, newValue) {
98 try {
99 var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
100 // check if the item being changed is the directory
101 // that we are showing in the addressbook sidebar
102 if (directory == GetAbView().directory) {
103 LoadPreviouslySelectedAB();
104 }
105 }
106 catch (ex) {
107 }
108 }
109 };
110
111
112 // XXX todo
113 // can we combine some common code? see OnLoadNewMailList()
114 // set popup with address book names
LoadPreviouslySelectedAB
115 function LoadPreviouslySelectedAB()
116 {
117 var abPopup = document.getElementById('addressbookList');
118 var value = abPopup.value || kPersonalAddressbookURI;
119 abPopup.selectedItem = null;
120 abPopup.value = value;
121 ChangeDirectoryByURI(abPopup.selectedItem.id);
122 }
123
124 function AddressBookMenuListChange()
125 {
126 if (gSearchInput.value && !gSearchInput.showingSearchCriteria)
127 onEnterInSearchBar();
128 else
129 {
130 var abPopup = document.getElementById('addressbookList');
131 ChangeDirectoryByURI(abPopup.selectedItem.id);
132 }
133 }
134
AbPanelOnComposerClose
135 function AbPanelOnComposerClose()
136 {
137 CloseAbView();
138 onClearSearch();
139 }
140
AbPanelOnComposerReOpen
141 function AbPanelOnComposerReOpen()
142 {
143 SetAbView(GetSelectedDirectory(), true);
144 }
145
AbPanelLoad
146 function AbPanelLoad()
147 {
148 InitCommonJS();
149
150 LoadPreviouslySelectedAB();
151
152 // Add a listener, so we can switch directories if the current directory is
153 // deleted, and change the name if the selected directory's name is modified.
154 // This listener only cares when a directory is removed or modified.
155 Components.classes["@mozilla.org/abmanager;1"]
156 .getService(Components.interfaces.nsIAbManager)
157 .addAddressBookListener(gAddressBookAbListener,
158 nsIAbListener.directoryRemoved |
159 nsIAbListener.itemChanged);
160
161 parent.document.getElementById("msgcomposeWindow").addEventListener('compose-window-close', AbPanelOnComposerClose, true);
162 parent.document.getElementById("msgcomposeWindow").addEventListener('compose-window-reopen', AbPanelOnComposerReOpen, true);
163 gSearchInput = document.getElementById("searchInput");
164 }
165
AbPanelUnload
166 function AbPanelUnload()
167 {
168 Components.classes["@mozilla.org/abmanager;1"]
169 .getService(Components.interfaces.nsIAbManager)
170 .removeAddressBookListener(gAddressBookPanelAbListener);
171
172 parent.document.getElementById("msgcomposeWindow").removeEventListener('compose-window-close', AbPanelOnComposerClose, true);
173 parent.document.getElementById("msgcomposeWindow").removeEventListener('compose-window-reopen', AbPanelOnComposerReOpen, true);
174
175 CloseAbView();
176 }
177
AbPanelNewCard
178 function AbPanelNewCard()
179 {
180 goNewCardDialog(abList.selectedItem.getAttribute('id'));
181 }
182
AbPanelNewList
183 function AbPanelNewList()
184 {
185 goNewListDialog(abList.selectedItem.getAttribute('id'));
186 }
187
ResultsPaneSelectionChanged
188 function ResultsPaneSelectionChanged()
189 {
190 // do nothing for ab panel
191 }
192
OnClickedCard
193 function OnClickedCard()
194 {
195 // do nothing for ab panel
196 }
197
AbResultsPaneDoubleClick
198 function AbResultsPaneDoubleClick(card)
199 {
200 // double click for ab panel means "send mail to this person / list"
201 AbNewMessage();
202 }
203
UpdateCardView
204 function UpdateCardView()
205 {
206 // do nothing for ab panel
207 }
208
onEnterInSearchBar
209 function onEnterInSearchBar()
210 {
211 if (!gQueryURIFormat)
212 gQueryURIFormat = gPrefs.getComplexValue("mail.addr_book.quicksearchquery.format",
213 Components.interfaces.nsIPrefLocalizedString).data;
214
215 var sortColumn = gAbResultsTree.getAttribute("sortCol");
216 var sortDirection = document.getElementById(sortColumn).getAttribute("sortDirection");
217 var searchURI = GetSelectedDirectory();
218
219 if (gSearchInput.value != "")
220 searchURI += gQueryURIFormat.replace(/@V/g, encodeURIComponent(gSearchInput.value));
221
222 SetAbView(searchURI, true, sortColumn, sortDirection);
223 }