!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 36 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/base/content/ABSearchDialog.js"
2
3 var searchSessionContractID = "@mozilla.org/messenger/searchSession;1";
4 var gSearchSession;
5
6 var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope;
7 var nsIMsgSearchTerm = Components.interfaces.nsIMsgSearchTerm;
8 var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp;
9 var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib;
10 var nsIAbDirectory = Components.interfaces.nsIAbDirectory;
11
12 var gStatusText;
13 var gSearchBundle;
14 var gAddressBookBundle;
15
16 var gSearchStopButton;
17 var gPropertiesButton;
18 var gComposeButton;
19 var gSearchPhoneticName = "false";
20
21 var gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
22
23 var gSearchAbViewListener = {
onSelectionChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
24 onSelectionChanged: function() {
25 UpdateCardView();
26 },
onCountChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
27 onCountChanged: function(total) {
28 var statusText;
29 switch (total) {
30 case 0:
31 statusText = gAddressBookBundle.getString("noMatchFound");
32 break;
33 case 1:
34 statusText = gAddressBookBundle.getString("matchFound");
35 break;
36 default:
37 statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
38 break;
39 }
40 gStatusText.setAttribute("label", statusText);
41 }
42 };
43
searchOnLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
44 function searchOnLoad()
45 {
46 initializeSearchWidgets();
47 initializeSearchWindowWidgets();
48
49 gSearchBundle = document.getElementById("bundle_search");
50 gSearchStopButton.setAttribute("label", gSearchBundle.getString("labelForSearchButton"));
51 gSearchStopButton.setAttribute("accesskey", gSearchBundle.getString("labelForSearchButton.accesskey"));
52 gAddressBookBundle = document.getElementById("bundle_addressBook");
53 gSearchSession = Components.classes[searchSessionContractID].createInstance(Components.interfaces.nsIMsgSearchSession);
54
55 // initialize a flag for phonetic name search
56 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
57 .getService(Components.interfaces.nsIPrefService);
58 var prefBranch = prefService.getBranch(null).QueryInterface(Components.interfaces.nsIPrefBranch2);
59 gSearchPhoneticName =
60 prefBranch.getComplexValue("mail.addr_book.show_phonetic_fields",
61 Components.interfaces.nsIPrefLocalizedString).data;
62
63 if (window.arguments && window.arguments[0])
64 SelectDirectory(window.arguments[0].directory);
65
66 // initialize globals, see abCommon.js, InitCommonJS()
67 abList = document.getElementById("abPopup");
68 gAbResultsTree = document.getElementById("abResultsTree");
69
70 onMore(null);
71 }
72
searchOnUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
73 function searchOnUnload()
74 {
75 CloseAbView();
76 }
77
initializeSearchWindowWidgets
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
78 function initializeSearchWindowWidgets()
79 {
80 gSearchStopButton = document.getElementById("search-button");
81 gPropertiesButton = document.getElementById("propertiesButton");
82 gComposeButton = document.getElementById("composeButton");
83 gStatusText = document.getElementById('statusText');
84 // matchAll doesn't make sense for address book search
85 hideMatchAllItem();
86 }
87
onSearchStop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
88 function onSearchStop()
89 {
90 }
91
onAbSearchReset
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
92 function onAbSearchReset(event)
93 {
94 gPropertiesButton.setAttribute("disabled","true");
95 gComposeButton.setAttribute("disabled","true");
96
97 CloseAbView();
98
99 onReset(event);
100 gStatusText.setAttribute("label", "");
101 }
102
SelectDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
103 function SelectDirectory(aURI)
104 {
105 var selectedAB = aURI;
106
107 if (!selectedAB)
108 selectedAB = kPersonalAddressbookURI;
109
110 // set popup with address book names
111 var abPopup = document.getElementById('abPopup');
112 if ( abPopup )
113 abPopup.value = selectedAB;
114
115 setSearchScope(GetScopeForDirectoryURI(selectedAB));
116 }
117
GetScopeForDirectoryURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
118 function GetScopeForDirectoryURI(aURI)
119 {
120 var directory = gRDF.GetResource(aURI).QueryInterface(nsIAbDirectory);
121 var booleanAnd = gSearchBooleanRadiogroup.selectedItem.value == "and";
122
123 if (directory.isRemote) {
124 if (booleanAnd)
125 return nsMsgSearchScope.LDAPAnd;
126 else
127 return nsMsgSearchScope.LDAP;
128 }
129 else {
130 if (booleanAnd)
131 return nsMsgSearchScope.LocalABAnd;
132 else
133 return nsMsgSearchScope.LocalAB;
134 }
135 }
136
onEnterInSearchTerm
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
137 function onEnterInSearchTerm()
138 {
139 // on enter
140 // if not searching, start the search
141 // if searching, stop and then start again
142 if (gSearchStopButton.getAttribute("label") == gSearchBundle.getString("labelForSearchButton")) {
143 onSearch();
144 }
145 else {
146 onSearchStop();
147 onSearch();
148 }
149 }
150
onSearch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
151 function onSearch()
152 {
153 gStatusText.setAttribute("label", "");
154 gPropertiesButton.setAttribute("disabled","true");
155 gComposeButton.setAttribute("disabled","true");
156
157 gSearchSession.clearScopes();
158
159 var currentAbURI = document.getElementById('abPopup').getAttribute('value');
160
161 gSearchSession.addDirectoryScopeTerm(GetScopeForDirectoryURI(currentAbURI));
162 saveSearchTerms(gSearchSession.searchTerms, gSearchSession);
163
164 var searchUri = currentAbURI + "?(";
165
166 var count = gSearchSession.searchTerms.Count();
167
168 for (var i=0; i<count; i++) {
169 var searchTerm = gSearchSession.searchTerms.GetElementAt(i).QueryInterface(nsIMsgSearchTerm);
170
171 // get the "and" / "or" value from the first term
172 if (i == 0) {
173 if (searchTerm.booleanAnd)
174 searchUri += "and";
175 else
176 searchUri += "or";
177 }
178
179 var attrs;
180
181 switch (searchTerm.attrib) {
182 case nsMsgSearchAttrib.Name:
183 if (gSearchPhoneticName == "false")
184 attrs = ["DisplayName","FirstName","LastName","NickName","_AimScreenName"];
185 else
186 attrs = ["DisplayName","FirstName","LastName","NickName","_AimScreenName","PhoneticFirstName","PhoneticLastName"];
187 break;
188 case nsMsgSearchAttrib.DisplayName:
189 attrs = ["DisplayName"];
190 break;
191 case nsMsgSearchAttrib.Email:
192 attrs = ["PrimaryEmail"];
193 break;
194 case nsMsgSearchAttrib.PhoneNumber:
195 attrs = ["HomePhone","WorkPhone","FaxNumber","PagerNumber","CellularNumber"];
196 break;
197 case nsMsgSearchAttrib.Organization:
198 attrs = ["Company"];
199 break;
200 case nsMsgSearchAttrib.Department:
201 attrs = ["Department"];
202 break;
203 case nsMsgSearchAttrib.City:
204 attrs = ["WorkCity"];
205 break;
206 case nsMsgSearchAttrib.Street:
207 attrs = ["WorkAddress"];
208 break;
209 case nsMsgSearchAttrib.Nickname:
210 attrs = ["NickName"];
211 break;
212 case nsMsgSearchAttrib.WorkPhone:
213 attrs = ["WorkPhone"];
214 break;
215 case nsMsgSearchAttrib.HomePhone:
216 attrs = ["HomePhone"];
217 break;
218 case nsMsgSearchAttrib.Fax:
219 attrs = ["FaxNumber"];
220 break;
221 case nsMsgSearchAttrib.Pager:
222 attrs = ["PagerNumber"];
223 break;
224 case nsMsgSearchAttrib.Mobile:
225 attrs = ["CellularNumber"];
226 break;
227 case nsMsgSearchAttrib.Title:
228 attrs = ["JobTitle"];
229 break;
230 case nsMsgSearchAttrib.AdditionalEmail:
231 attrs = ["SecondEmail"];
232 break;
233 case nsMsgSearchAttrib.ScreenName:
234 attrs = ["_AimScreenName"];
235 break;
236 default:
237 dump("XXX " + searchTerm.attrib + " not a supported search attr!\n");
238 attrs = ["DisplayName"];
239 break;
240 }
241
242 var opStr;
243
244 switch (searchTerm.op) {
245 case nsMsgSearchOp.Contains:
246 opStr = "c";
247 break;
248 case nsMsgSearchOp.DoesntContain:
249 opStr = "!c";
250 break;
251 case nsMsgSearchOp.Is:
252 opStr = "=";
253 break;
254 case nsMsgSearchOp.Isnt:
255 opStr = "!=";
256 break;
257 case nsMsgSearchOp.BeginsWith:
258 opStr = "bw";
259 break;
260 case nsMsgSearchOp.EndsWith:
261 opStr = "ew";
262 break;
263 case nsMsgSearchOp.SoundsLike:
264 opStr = "~=";
265 break;
266 default:
267 opStr = "c";
268 break;
269 }
270
271 // currently, we can't do "and" and "or" searches at the same time
272 // (it's either all "and"s or all "or"s)
273 var max_attrs = attrs.length;
274
275 for (var j=0;j<max_attrs;j++) {
276 // append the term(s) to the searchUri
277 searchUri += "(" + attrs[j] + "," + opStr + "," + encodeURIComponent(searchTerm.value.str) + ")";
278 }
279 }
280
281 searchUri += ")";
282 SetAbView(searchUri, null, null);
283 }
284
285 // used to toggle functionality for Search/Stop button.
onSearchButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
286 function onSearchButton(event)
287 {
288 if (event.target.label == gSearchBundle.getString("labelForSearchButton"))
289 onSearch();
290 else
291 onSearchStop();
292 }
293
GetAbViewListener
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 function GetAbViewListener()
295 {
296 return gSearchAbViewListener;
297 }
298
onProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
299 function onProperties()
300 {
301 AbEditSelectedCard();
302 }
303
onCompose
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
304 function onCompose()
305 {
306 AbNewMessage();
307 }
308
AbResultsPaneKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
309 function AbResultsPaneKeyPress(event)
310 {
311 if (event.keyCode == 13)
312 AbEditSelectedCard();
313 }
314
AbResultsPaneDoubleClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
315 function AbResultsPaneDoubleClick(card)
316 {
317 AbEditCard(card);
318 }
319
UpdateCardView
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
320 function UpdateCardView()
321 {
322 var numSelected = GetNumSelectedCards();
323
324 if (!numSelected) {
325 gPropertiesButton.setAttribute("disabled","true");
326 gComposeButton.setAttribute("disabled","true");
327 return;
328 }
329
330 gComposeButton.removeAttribute("disabled");
331
332 if (numSelected == 1)
333 gPropertiesButton.removeAttribute("disabled");
334 else
335 gPropertiesButton.setAttribute("disabled","true");
336 }
337
onChooseDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
338 function onChooseDirectory(event)
339 {
340 var directoryURI = event.id;
341 if (directoryURI) {
342 SelectDirectory(directoryURI);
343 }
344 }