!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 41 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/components/addrbook/content/abCardViewOverlay.js"
2
3 //NOTE: gAddressBookBundle must be defined and set or this Overlay won't work
4
5 var gPrefs = Components.classes["@mozilla.org/preferences-service;1"];
6 gPrefs = gPrefs.getService();
7 gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPrefBranch);
8
9 var gProfileDirURL;
10
11 var gMapItURLFormat = gPrefs.getComplexValue("mail.addr_book.mapit_url.format",
12 Components.interfaces.nsIPrefLocalizedString).data;
13
14 var gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
15 var gFileHandler = gIOService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
16
17 var zListName;
18 var zPrimaryEmail;
19 var zSecondaryEmail;
20 var zScreenName;
21 var zNickname;
22 var zDisplayName;
23 var zWork;
24 var zHome;
25 var zFax;
26 var zCellular;
27 var zPager;
28 var zCustom1;
29 var zCustom2;
30 var zCustom3;
31 var zCustom4;
32
33 var cvData;
34
OnLoadCardView
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
35 function OnLoadCardView()
36 {
37 zPrimaryEmail = gAddressBookBundle.getString("propertyPrimaryEmail");
38 zSecondaryEmail = gAddressBookBundle.getString("propertySecondaryEmail");
39 zScreenName = gAddressBookBundle.getString("propertyScreenName");
40 zNickname = gAddressBookBundle.getString("propertyNickname");
41 zDisplayName = gAddressBookBundle.getString("propertyDisplayName");
42 zListName = gAddressBookBundle.getString("propertyListName");
43 zWork = gAddressBookBundle.getString("propertyWork");
44 zHome = gAddressBookBundle.getString("propertyHome");
45 zFax = gAddressBookBundle.getString("propertyFax");
46 zCellular = gAddressBookBundle.getString("propertyCellular");
47 zPager = gAddressBookBundle.getString("propertyPager");
48 zCustom1 = gAddressBookBundle.getString("propertyCustom1");
49 zCustom2 = gAddressBookBundle.getString("propertyCustom2");
50 zCustom3 = gAddressBookBundle.getString("propertyCustom3");
51 zCustom4 = gAddressBookBundle.getString("propertyCustom4");
52
53 var doc = document;
54
55 /* data for address book, prefixes: "cvb" = card view box
56 "cvh" = crad view header
57 "cv" = card view (normal fields) */
58 cvData = new Object;
59
60 // Card View Box
61 cvData.CardViewBox = doc.getElementById("CardViewInnerBox");
62 // Title
63 cvData.CardTitle = doc.getElementById("CardTitle");
64 // Name section
65 cvData.cvbContact = doc.getElementById("cvbContact");
66 cvData.cvhContact = doc.getElementById("cvhContact");
67 cvData.cvNickname = doc.getElementById("cvNickname");
68 cvData.cvDisplayName = doc.getElementById("cvDisplayName");
69 cvData.cvEmail1Box = doc.getElementById("cvEmail1Box");
70 cvData.cvEmail1 = doc.getElementById("cvEmail1");
71 cvData.cvScreennameBox = doc.getElementById("cvScreennameBox");
72 cvData.cvAimPresence = doc.getElementById("cvAimPresence");
73 cvData.cvScreenname = doc.getElementById("cvScreenname");
74 cvData.cvBuddyIcon = doc.getElementById("cvBuddyIcon");
75 cvData.cvListNameBox = doc.getElementById("cvListNameBox");
76 cvData.cvListName = doc.getElementById("cvListName");
77 cvData.cvEmail2Box = doc.getElementById("cvEmail2Box");
78 cvData.cvEmail2 = doc.getElementById("cvEmail2");
79 // Home section
80 cvData.cvbHome = doc.getElementById("cvbHome");
81 cvData.cvhHome = doc.getElementById("cvhHome");
82 cvData.cvHomeAddress = doc.getElementById("cvHomeAddress");
83 cvData.cvHomeAddress2 = doc.getElementById("cvHomeAddress2");
84 cvData.cvHomeCityStZip = doc.getElementById("cvHomeCityStZip");
85 cvData.cvHomeCountry = doc.getElementById("cvHomeCountry");
86 cvData.cvbHomeMapItBox = doc.getElementById("cvbHomeMapItBox");
87 cvData.cvHomeMapIt = doc.getElementById("cvHomeMapIt");
88 cvData.cvHomeWebPageBox = doc.getElementById("cvHomeWebPageBox");
89 cvData.cvHomeWebPage = doc.getElementById("cvHomeWebPage");
90 // Other section
91 cvData.cvbOther = doc.getElementById("cvbOther");
92 cvData.cvhOther = doc.getElementById("cvhOther");
93 cvData.cvCustom1 = doc.getElementById("cvCustom1");
94 cvData.cvCustom2 = doc.getElementById("cvCustom2");
95 cvData.cvCustom3 = doc.getElementById("cvCustom3");
96 cvData.cvCustom4 = doc.getElementById("cvCustom4");
97 cvData.cvNotes = doc.getElementById("cvNotes");
98 // Description section (mailing lists only)
99 cvData.cvbDescription = doc.getElementById("cvbDescription");
100 cvData.cvhDescription = doc.getElementById("cvhDescription");
101 cvData.cvDescription = doc.getElementById("cvDescription");
102 // Addresses section (mailing lists only)
103 cvData.cvbAddresses = doc.getElementById("cvbAddresses");
104 cvData.cvhAddresses = doc.getElementById("cvhAddresses");
105 cvData.cvAddresses = doc.getElementById("cvAddresses");
106 // Phone section
107 cvData.cvbPhone = doc.getElementById("cvbPhone");
108 cvData.cvhPhone = doc.getElementById("cvhPhone");
109 cvData.cvPhWork = doc.getElementById("cvPhWork");
110 cvData.cvPhHome = doc.getElementById("cvPhHome");
111 cvData.cvPhFax = doc.getElementById("cvPhFax");
112 cvData.cvPhCellular = doc.getElementById("cvPhCellular");
113 cvData.cvPhPager = doc.getElementById("cvPhPager");
114 // Work section
115 cvData.cvbWork = doc.getElementById("cvbWork");
116 cvData.cvhWork = doc.getElementById("cvhWork");
117 cvData.cvJobTitle = doc.getElementById("cvJobTitle");
118 cvData.cvDepartment = doc.getElementById("cvDepartment");
119 cvData.cvCompany = doc.getElementById("cvCompany");
120 cvData.cvWorkAddress = doc.getElementById("cvWorkAddress");
121 cvData.cvWorkAddress2 = doc.getElementById("cvWorkAddress2");
122 cvData.cvWorkCityStZip = doc.getElementById("cvWorkCityStZip");
123 cvData.cvWorkCountry = doc.getElementById("cvWorkCountry");
124 cvData.cvbWorkMapItBox = doc.getElementById("cvbWorkMapItBox");
125 cvData.cvWorkMapIt = doc.getElementById("cvWorkMapIt");
126 cvData.cvWorkWebPageBox = doc.getElementById("cvWorkWebPageBox");
127 cvData.cvWorkWebPage = doc.getElementById("cvWorkWebPage");
128 }
129
130 // XXX todo
131 // some similar code (in spirit) already exists, see OnLoadEditList()
132 // perhaps we could combine and put in abCommon.js?
GetAddressesFromURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
133 function GetAddressesFromURI(uri)
134 {
135 var addresses = "";
136
137 var editList = GetDirectoryFromURI(uri);
138 var addressList = editList.addressLists;
139 if (addressList) {
140 var total = addressList.Count();
141 if (total > 0)
142 addresses = addressList.GetElementAt(0).QueryInterface(Components.interfaces.nsIAbCard).primaryEmail;
143 for (var i = 1; i < total; i++ ) {
144 addresses += ", " + addressList.GetElementAt(i).QueryInterface(Components.interfaces.nsIAbCard).primaryEmail;
145 }
146 }
147 return addresses;
148 }
149
GoIM
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
150 function GoIM()
151 {
152 LaunchUrl(top.cvData.cvAimPresence.getAttribute("url"));
153 }
154
DisplayCardViewPane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
155 function DisplayCardViewPane(card)
156 {
157 var generatedName = card.generateName(gPrefs.getIntPref("mail.addr_book.lastnamefirst"));
158
159 var data = top.cvData;
160 var visible;
161
162 var titleString;
163 if (generatedName == "")
164 titleString = card.primaryEmail; // if no generatedName, use email
165 else
166 titleString = generatedName;
167
168 // set fields in card view pane
169 if (card.isMailList)
170 cvSetNode(data.CardTitle, gAddressBookBundle.getFormattedString("viewListTitle", [generatedName]));
171 else
172 cvSetNode(data.CardTitle, gAddressBookBundle.getFormattedString("viewCardTitle", [titleString]));
173
174 // Contact section
175 cvSetNodeWithLabel(data.cvNickname, zNickname, card.nickName);
176
177 if (card.isMailList) {
178 // email1, display name and screenname always hidden when a mailing list.
179 cvSetVisible(data.cvDisplayName, false);
180 cvSetVisible(data.cvEmail1Box, false);
181 cvSetVisible(data.cvScreennameBox, false);
182
183 visible = HandleLink(data.cvListName, zListName, card.displayName, data.cvListNameBox, "mailto:" + encodeURIComponent(GenerateAddressFromCard(card))) || visible;
184 }
185 else {
186 // listname always hidden if not a mailing list
187 cvSetVisible(data.cvListNameBox, false);
188
189 cvSetNodeWithLabel(data.cvDisplayName, zDisplayName, card.displayName);
190
191 visible = HandleLink(data.cvEmail1, zPrimaryEmail, card.primaryEmail, data.cvEmail1Box, "mailto:" + card.primaryEmail) || visible;
192 }
193
194 var goimURL = "aim:goim?screenname=" + card.aimScreenName;
195 var hasScreenName = HandleLink(data.cvScreenname, zScreenName, card.aimScreenName, data.cvScreennameBox, goimURL);
196
197 data.cvAimPresence.removeAttribute("src");
198 data.cvAimPresence.removeAttribute("url");
199 data.cvAimPresence.setAttribute("width","0");
200
201 //@line 247 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/components/addrbook/content/abCardViewOverlay.js"
202
203 visible = hasScreenName || visible;
204 visible = HandleLink(data.cvEmail2, zSecondaryEmail, card.secondEmail, data.cvEmail2Box, "mailto:" + card.secondEmail) || visible;
205
206 // Home section
207 visible = cvSetNode(data.cvHomeAddress, card.homeAddress);
208 visible = cvSetNode(data.cvHomeAddress2, card.homeAddress2) || visible;
209 visible = cvSetCityStateZip(data.cvHomeCityStZip, card.homeCity, card.homeState, card.homeZipCode) || visible;
210 visible = cvSetNode(data.cvHomeCountry, card.homeCountry) || visible;
211 if (visible) {
212 var homeMapItUrl = CreateMapItURL(card.homeAddress, card.homeAddress2, card.homeCity, card.homeState, card.homeZipCode, card.homeCountry);
213 if (homeMapItUrl) {
214 cvSetVisible(data.cvbHomeMapItBox, true);
215 data.cvHomeMapIt.setAttribute('url', homeMapItUrl);
216 }
217 else {
218 cvSetVisible(data.cvbHomeMapItBox, false);
219 }
220 }
221 else {
222 cvSetVisible(data.cvbHomeMapItBox, false);
223 }
224
225 visible = HandleLink(data.cvHomeWebPage, "", card.webPage2, data.cvHomeWebPageBox, card.webPage2) || visible;
226
227 cvSetVisible(data.cvhHome, visible);
228 cvSetVisible(data.cvbHome, visible);
229 if (card.isMailList) {
230 // Description section
231 visible = cvSetNode(data.cvDescription, card.notes)
232 cvSetVisible(data.cvbDescription, visible);
233
234 // Addresses section
235 visible = cvAddAddressNodes(data.cvAddresses, card.mailListURI);
236 cvSetVisible(data.cvbAddresses, visible);
237
238 // Other section, not shown for mailing lists.
239 cvSetVisible(data.cvbOther, false);
240 }
241 else {
242 // Other section
243 visible = cvSetNodeWithLabel(data.cvCustom1, zCustom1, card.custom1);
244 visible = cvSetNodeWithLabel(data.cvCustom2, zCustom2, card.custom2) || visible;
245 visible = cvSetNodeWithLabel(data.cvCustom3, zCustom3, card.custom3) || visible;
246 visible = cvSetNodeWithLabel(data.cvCustom4, zCustom4, card.custom4) || visible;
247 visible = cvSetNode(data.cvNotes, card.notes) || visible;
248 visible = setBuddyIcon(card, data.cvBuddyIcon) || visible;
249
250 cvSetVisible(data.cvhOther, visible);
251 cvSetVisible(data.cvbOther, visible);
252
253 // hide description section, not show for non-mailing lists
254 cvSetVisible(data.cvbDescription, false);
255
256 // hide addresses section, not show for non-mailing lists
257 cvSetVisible(data.cvbAddresses, false);
258 }
259
260 // Phone section
261 visible = cvSetNodeWithLabel(data.cvPhWork, zWork, card.workPhone);
262 visible = cvSetNodeWithLabel(data.cvPhHome, zHome, card.homePhone) || visible;
263 visible = cvSetNodeWithLabel(data.cvPhFax, zFax, card.faxNumber) || visible;
264 visible = cvSetNodeWithLabel(data.cvPhCellular, zCellular, card.cellularNumber) || visible;
265 visible = cvSetNodeWithLabel(data.cvPhPager, zPager, card.pagerNumber) || visible;
266 cvSetVisible(data.cvhPhone, visible);
267 cvSetVisible(data.cvbPhone, visible);
268 // Work section
269 visible = cvSetNode(data.cvJobTitle, card.jobTitle);
270 visible = cvSetNode(data.cvDepartment, card.department) || visible;
271 visible = cvSetNode(data.cvCompany, card.company) || visible;
272
273 var addressVisible = cvSetNode(data.cvWorkAddress, card.workAddress);
274 addressVisible = cvSetNode(data.cvWorkAddress2, card.workAddress2) || addressVisible;
275 addressVisible = cvSetCityStateZip(data.cvWorkCityStZip, card.workCity, card.workState, card.workZipCode) || addressVisible;
276 addressVisible = cvSetNode(data.cvWorkCountry, card.workCountry) || addressVisible;
277
278 if (addressVisible) {
279 var workMapItUrl = CreateMapItURL(card.workAddress, card.workAddress2, card.workCity, card.workState, card.workZipCode, card.workCountry);
280 data.cvWorkMapIt.setAttribute('url', workMapItUrl);
281 if (workMapItUrl) {
282 cvSetVisible(data.cvbWorkMapItBox, true);
283 data.cvWorkMapIt.setAttribute('url', workMapItUrl);
284 }
285 else {
286 cvSetVisible(data.cvbWorkMapItBox, false);
287 }
288 }
289 else {
290 cvSetVisible(data.cvbWorkMapItBox, false);
291 }
292
293 visible = HandleLink(data.cvWorkWebPage, "", card.webPage1, data.cvWorkWebPageBox, card.webPage1) || addressVisible || visible;
294
295 cvSetVisible(data.cvhWork, visible);
296 cvSetVisible(data.cvbWork, visible);
297
298 // make the card view box visible
299 cvSetVisible(top.cvData.CardViewBox, true);
300 }
301
setBuddyIcon
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
302 function setBuddyIcon(card, buddyIcon)
303 {
304 try {
305 var myScreenName = gPrefs.getCharPref("aim.session.screenname");
306 if (myScreenName && card.primaryEmail) {
307 if (!gProfileDirURL) {
308 // lazily create these file urls, and keep them around
309 var dirService = Components.classes["@mozilla.org/file/directory_service;1"]
310 .getService(Components.interfaces.nsIProperties);
311 var profileDir = dirService.get("ProfD", Components.interfaces.nsIFile);
312 gProfileDirURL = gIOService.newFileURI(profileDir);
313 }
314
315 // if we did have a buddy icon on disk for this screenname, this would be the file url spec for it
316 var iconURLStr = gProfileDirURL.spec + "/NIM/" + myScreenName + "/picture/" + card.aimScreenName + ".gif";
317
318 // check if the file exists
319 var file = gFileHandler.getFileFromURLSpec(iconURLStr);
320
321 // check if the file exists
322 // is this a perf hit? (how expensive is stat()?)
323 if (file.exists()) {
324 buddyIcon.setAttribute("src", iconURLStr);
325 return true;
326 }
327 }
328 }
329 catch (ex) {
330 // can get here if no screenname
331 }
332
333 buddyIcon.setAttribute("src", "");
334 return false;
335 }
336
ClearCardViewPane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
337 function ClearCardViewPane()
338 {
339 cvSetVisible(top.cvData.CardViewBox, false);
340 }
341
cvSetNodeWithLabel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
342 function cvSetNodeWithLabel(node, label, text)
343 {
344 if (text) {
345 if (label)
346 return cvSetNode(node, label + ": " + text);
347 else
348 return cvSetNode(node, text);
349 }
350 else
351 return cvSetNode(node, "");
352 }
353
cvSetCityStateZip
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
354 function cvSetCityStateZip(node, city, state, zip)
355 {
356 var text = "";
357
358 if ( city )
359 {
360 text = city;
361 if ( state || zip )
362 text += ", ";
363 }
364 if ( state )
365 text += state + " ";
366 if ( zip )
367 text += zip;
368
369 return cvSetNode(node, text);
370 }
371
cvSetNode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
372 function cvSetNode(node, text)
373 {
374 if ( node )
375 {
376 if ( !node.hasChildNodes() )
377 {
378 var textNode = document.createTextNode(text);
379 node.appendChild(textNode);
380 }
381 else if ( node.childNodes.length == 1 )
382 node.childNodes[0].nodeValue = text;
383
384 var visible;
385
386 if ( text )
387 visible = true;
388 else
389 visible = false;
390
391 cvSetVisible(node, visible);
392 }
393
394 return visible;
395 }
396
cvAddAddressNodes
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
397 function cvAddAddressNodes(node, uri)
398 {
399 var visible = false;
400 if ( node )
401 {
402 var displayName = "";
403 var address = "";
404
405 var editList = GetDirectoryFromURI(uri);
406 var addressList = editList.addressLists;
407
408 if (addressList) {
409 var total = addressList.Count();
410 if (total > 0) {
411 while (node.hasChildNodes()) {
412 node.removeChild(node.lastChild);
413 }
414 for (i = 0; i < total; i++ ) {
415 var descNode = document.createElement("description");
416 address = addressList.GetElementAt(i).QueryInterface(Components.interfaces.nsIAbCard).primaryEmail;
417 displayName = addressList.GetElementAt(i).QueryInterface(Components.interfaces.nsIAbCard).displayName;
418 descNode.setAttribute("class", "CardViewLink");
419 node.appendChild(descNode);
420
421 var linkNode = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
422 linkNode.setAttribute("id", "addr#" + i);
423 linkNode.setAttribute("href", "mailto:" + address);
424 descNode.appendChild(linkNode);
425
426 var textNode = document.createTextNode(displayName + " <" + address + ">");
427 linkNode.appendChild(textNode);
428 }
429 visible = true;
430 }
431 }
432 cvSetVisible(node, visible);
433 }
434 return visible;
435 }
436
cvSetVisible
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
437 function cvSetVisible(node, visible)
438 {
439 if ( visible )
440 node.removeAttribute("collapsed");
441 else
442 node.setAttribute("collapsed", "true");
443 }
444
HandleLink
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
445 function HandleLink(node, label, value, box, link)
446 {
447 var visible = cvSetNodeWithLabel(node, label, value);
448 if (visible)
449 node.setAttribute('href', link);
450 cvSetVisible(box, visible);
451
452 return visible;
453 }
454
MapIt
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
455 function MapIt(id)
456 {
457 var button = document.getElementById(id);
458 try {
459 var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
460 messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
461 messenger.launchExternalURL(button.getAttribute('url'));
462 } catch (ex) {}
463 }
464
CreateMapItURL
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
465 function CreateMapItURL(address1, address2, city, state, zip, country)
466 {
467 if (!gMapItURLFormat)
468 return null;
469
470 var urlFormat = gMapItURLFormat.replace("@A1", encodeURIComponent(address1));
471 urlFormat = urlFormat.replace("@A2", encodeURIComponent(address2));
472 urlFormat = urlFormat.replace("@CO", encodeURIComponent(country));
473 urlFormat = urlFormat.replace("@CI", encodeURIComponent(city));
474 urlFormat = urlFormat.replace("@ST", encodeURIComponent(state));
475 urlFormat = urlFormat.replace("@ZI", encodeURIComponent(zip));
476
477 return urlFormat;
478 }
479
480 // XXX merge with the code in Map It
openLink
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
481 function openLink(id)
482 {
483 try {
484 var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
485 messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
486 messenger.launchExternalURL(document.getElementById(id).getAttribute("href"));
487 } catch (ex) {}
488
489 // return false, so we don't load the href in the addressbook window
490 return false;
491 }