!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/abCommon.js"
2
3 var dirTree = 0;
4 var abList = 0;
5 var gAbResultsTree = null;
6 var gAbView = null;
7 var gAddressBookBundle;
8 var gCurDirectory;
9
10 var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
11 var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
12 var gHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
13
14 const kDefaultSortColumn = "GeneratedName";
15 const kDefaultAscending = "ascending";
16 const kDefaultDescending = "descending";
17 const kPersonalAddressbookURI = "moz-abmdbdirectory://abook.mab";
18 const kCollectedAddressbookURI = "moz-abmdbdirectory://history.mab";
19
20 // List/card selections in the results pane.
21 const kNothingSelected = 0;
22 const kListsAndCards = 1;
23 const kMultipleListsOnly = 2;
24 const kSingleListOnly = 3;
25 const kCardsOnly = 4;
26
27 // Controller object for Results Pane
28 var ResultsPaneController =
29 {
supportsCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
30 supportsCommand: function(command)
31 {
32 switch (command) {
33 case "cmd_selectAll":
34 case "cmd_delete":
35 case "button_delete":
36 case "button_edit":
37 case "cmd_printcard":
38 case "cmd_printcardpreview":
39 case "cmd_newlist":
40 return true;
41 default:
42 return false;
43 }
44 },
45
isCommandEnabled
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
46 isCommandEnabled: function(command)
47 {
48 switch (command) {
49 case "cmd_selectAll":
50 return true;
51
52 case "cmd_delete":
53 case "button_delete":
54 var numSelected;
55 var enabled = false;
56 if (gAbView && gAbView.selection) {
57 if (gAbView.directory)
58 enabled = gAbView.directory.operations & gAbView.directory.opWrite;
59 numSelected = gAbView.selection.count;
60 }
61 else
62 numSelected = 0;
63
64 // fix me, don't update on isCommandEnabled
65 if (command == "cmd_delete") {
66 if (numSelected < 2)
67 goSetMenuValue(command, "valueCard");
68 else
69 goSetMenuValue(command, "valueCards");
70 }
71 return (enabled && (numSelected > 0));
72 case "cmd_printcard":
73 case "cmd_printcardpreview":
74 case "button_edit":
75 return (GetSelectedCardIndex() != -1);
76 case "cmd_newlist":
77 var selectedDir = GetSelectedDirectory();
78 if (selectedDir) {
79 var abDir = GetDirectoryFromURI(selectedDir);
80 if (abDir) {
81 return abDir.supportsMailingLists;
82 }
83 }
84 return false;
85 default:
86 return false;
87 }
88 },
89
doCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
90 doCommand: function(command)
91 {
92 switch (command) {
93 case "cmd_selectAll":
94 if (gAbView)
95 gAbView.selectAll();
96 break;
97 case "cmd_delete":
98 case "button_delete":
99 AbDelete();
100 break;
101 case "button_edit":
102 AbEditSelectedCard();
103 break;
104 case "cmd_printcard":
105 AbPrintCard();
106 break;
107 case "cmd_printcardpreview":
108 AbPrintPreviewCard();
109 break;
110 case "cmd_newlist":
111 AbNewList();
112 break;
113 }
114 },
115
onEvent
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
116 onEvent: function(event)
117 {
118 // on blur events set the menu item texts back to the normal values
119 if (event == "blur")
120 goSetMenuValue("cmd_delete", "valueDefault");
121 }
122 };
123
124
125 // Controller object for Dir Pane
126 var DirPaneController =
127 {
supportsCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
128 supportsCommand: function(command)
129 {
130 switch (command) {
131 case "cmd_selectAll":
132 case "cmd_delete":
133 case "button_delete":
134 case "button_edit":
135 case "cmd_printcard":
136 case "cmd_printcardpreview":
137 case "cmd_newlist":
138 return true;
139 default:
140 return false;
141 }
142 },
143
isCommandEnabled
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
144 isCommandEnabled: function(command)
145 {
146 var selectedDir;
147
148 switch (command) {
149 case "cmd_selectAll":
150 // the dirTree pane
151 // only handles single selection
152 // so we forward select all to the results pane
153 // but if there is no gAbView
154 // don't bother sending to the results pane
155 return (gAbView != null);
156 case "cmd_delete":
157 case "button_delete":
158 if (command == "cmd_delete")
159 goSetMenuValue(command, "valueAddressBook");
160
161 selectedDir = GetSelectedDirectory();
162
163 if (selectedDir == kPersonalAddressbookURI || selectedDir == kCollectedAddressbookURI)
164 return false;
165
166 if (selectedDir) {
167 // If the selected directory is an ldap directory
168 // and if the prefs for this directory are locked
169 // disable the delete button.
170 var ldapUrlPrefix = "moz-abldapdirectory://";
171 if ((selectedDir.indexOf(ldapUrlPrefix, 0)) == 0)
172 {
173 var disable = false;
174 try {
175 var prefName = selectedDir.substr(ldapUrlPrefix.length);
176 disable = gPrefs.getBoolPref(prefName + ".disable_delete");
177 }
178 catch(ex) {
179 // if this preference is not set its ok.
180 }
181 if (disable)
182 return false;
183 }
184 return true;
185 }
186 else
187 return false;
188 case "cmd_printcard":
189 case "cmd_printcardpreview":
190 return (GetSelectedCardIndex() != -1);
191 case "button_edit":
192 return (GetSelectedDirectory() != null);
193 case "cmd_newlist":
194 selectedDir = GetSelectedDirectory();
195 if (selectedDir) {
196 var abDir = GetDirectoryFromURI(selectedDir);
197 if (abDir) {
198 return abDir.supportsMailingLists;
199 }
200 }
201 return false;
202 default:
203 return false;
204 }
205 },
206
doCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
207 doCommand: function(command)
208 {
209 switch (command) {
210 case "cmd_printcard":
211 case "cmd_printcardpreview":
212 case "cmd_selectAll":
213 SendCommandToResultsPane(command);
214 break;
215 case "cmd_delete":
216 case "button_delete":
217 if (dirTree)
218 AbDeleteSelectedDirectory();
219 break;
220 case "button_edit":
221 AbEditSelectedDirectory();
222 break;
223 case "cmd_newlist":
224 AbNewList();
225 break;
226 }
227 },
228
onEvent
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
229 onEvent: function(event)
230 {
231 // on blur events set the menu item texts back to the normal values
232 if (event == "blur")
233 goSetMenuValue("cmd_delete", "valueDefault");
234 }
235 };
236
SendCommandToResultsPane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
237 function SendCommandToResultsPane(command)
238 {
239 ResultsPaneController.doCommand(command);
240
241 // if we are sending the command so the results pane
242 // we should focus the results pane
243 gAbResultsTree.focus();
244 }
245
AbNewLDAPDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
246 function AbNewLDAPDirectory()
247 {
248 window.openDialog("chrome://messenger/content/addressbook/pref-directory-add.xul",
249 "",
250 "chrome,modal=yes,resizable=no,centerscreen",
251 null);
252 }
253
AbNewAddressBook
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
254 function AbNewAddressBook()
255 {
256 window.openDialog(
257 "chrome://messenger/content/addressbook/abAddressBookNameDialog.xul",
258 "", "chrome,modal=yes,resizable=no,centerscreen", null);
259 }
260
AbEditSelectedDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
261 function AbEditSelectedDirectory()
262 {
263 if (dirTree.view.selection.count == 1) {
264 var selecteduri = GetSelectedDirectory();
265 var directory = GetDirectoryFromURI(selecteduri);
266 if (directory.isMailList) {
267 var dirUri = GetParentDirectoryFromMailingListURI(selecteduri);
268 goEditListDialog(null, selecteduri, UpdateCardView);
269 }
270 else {
271 window.openDialog(directory.propertiesChromeURI,
272 "editDirectory", "chrome,modal=yes,resizable=no",
273 {selectedDirectory: directory});
274 }
275 }
276 }
277
AbDeleteSelectedDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
278 function AbDeleteSelectedDirectory()
279 {
280 var selectedABURI = GetSelectedDirectory();
281 if (!selectedABURI)
282 return;
283
284 AbDeleteDirectory(selectedABURI);
285 }
286
AbDeleteDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
287 function AbDeleteDirectory(aURI)
288 {
289 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
290
291 var directory = GetDirectoryFromURI(aURI);
292 var confirmDeleteMessage;
293 var clearPrefsRequired = false;
294
295 if (directory.isMailList)
296 confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingList");
297 else {
298 // Check if this address book is being used for collection
299 if (gPrefs.getCharPref("mail.collect_addressbook") == aURI &&
300 (gPrefs.getBoolPref("mail.collect_email_address_outgoing") ||
301 gPrefs.getBoolPref("mail.collect_email_address_incoming") ||
302 gPrefs.getBoolPref("mail.collect_email_address_newsgroup"))) {
303 var brandShortName = document.getElementById("bundle_brand").getString("brandShortName");
304
305 confirmDeleteMessage = gAddressBookBundle.getFormattedString("confirmDeleteCollectionAddressbook", [brandShortName]);
306 clearPrefsRequired = true;
307 }
308 else {
309 confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteAddressbook");
310 }
311 }
312
313 if (!promptService.confirm(window,
314 gAddressBookBundle.getString(
315 directory.isMailList ?
316 "confirmDeleteMailingListTitle" :
317 "confirmDeleteAddressbookTitle"),
318 confirmDeleteMessage))
319 return;
320
321 // First clear all the prefs if required
322 if (clearPrefsRequired) {
323 gPrefs.setBoolPref("mail.collect_email_address_outgoing", false);
324 gPrefs.setBoolPref("mail.collect_email_address_incoming", false);
325 gPrefs.setBoolPref("mail.collect_email_address_newsgroup", false);
326
327 // Also reset the displayed value so that we don't get a blank item in the
328 // prefs dialog if it gets enabled.
329 gPrefs.setCharPref("mail.collect_addressbook", kPersonalAddressbookURI);
330 }
331
332 Components.classes["@mozilla.org/abmanager;1"]
333 .getService(Components.interfaces.nsIAbManager)
334 .deleteAddressBook(aURI);
335 }
336
GetParentRow
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
337 function GetParentRow(aTree, aRow)
338 {
339 var row = aRow;
340 var level = aTree.view.getLevel(row);
341 var parentLevel = level;
342 while (parentLevel >= level) {
343 row--;
344 if (row == -1)
345 return row;
346 parentLevel = aTree.view.getLevel(row);
347 }
348 return row;
349 }
350
InitCommonJS
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
351 function InitCommonJS()
352 {
353 dirTree = document.getElementById("dirTree");
354 abList = document.getElementById("addressbookList");
355 gAbResultsTree = document.getElementById("abResultsTree");
356 gAddressBookBundle = document.getElementById("bundle_addressBook");
357 }
358
SetupAbCommandUpdateHandlers
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
359 function SetupAbCommandUpdateHandlers()
360 {
361 // dir pane
362 if (dirTree)
363 dirTree.controllers.appendController(DirPaneController);
364
365 // results pane
366 if (gAbResultsTree)
367 gAbResultsTree.controllers.appendController(ResultsPaneController);
368 }
369
GetSelectedCardTypes
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
370 function GetSelectedCardTypes()
371 {
372 var cards = GetSelectedAbCards();
373 if (!cards)
374 return kNothingSelected; // no view
375
376 var count = cards.length;
377 if (count == 0)
378 return kNothingSelected; // nothing selected
379
380 var mailingListCnt = 0;
381 var cardCnt = 0;
382 for (var i = 0; i < count; i++) {
383 if (cards[i].isMailList)
384 mailingListCnt++;
385 else
386 cardCnt++;
387 }
388 if (mailingListCnt && cardCnt)
389 return kListsAndCards; // lists and cards selected
390 else if (mailingListCnt && !cardCnt) {
391 if (mailingListCnt > 1)
392 return kMultipleListsOnly; // only multiple mailing lists selected
393 else
394 return kSingleListOnly; // only single mailing list
395 }
396 else if (!mailingListCnt && cardCnt)
397 return kCardsOnly; // only card(s) selected
398
399 // Fallback just in case.
400 return kNothingSelected;
401 }
402
AbDelete
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
403 function AbDelete()
404 {
405 var types = GetSelectedCardTypes();
406 if (types == kNothingSelected)
407 return;
408
409 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
410 // If at least one mailing list is selected then prompt users for deletion.
411 if (types != kCardsOnly)
412 {
413 var confirmDeleteMessage;
414 if (types == kListsAndCards)
415 confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteListsAndCards");
416 else if (types == kMultipleListsOnly)
417 confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingLists");
418 else
419 confirmDeleteMessage = gAddressBookBundle.getString("confirmDeleteMailingList");
420 if (!promptService.confirm(window, null, confirmDeleteMessage))
421 return;
422 }
423
424 gAbView.deleteSelectedCards();
425 }
426
AbNewCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
427 function AbNewCard()
428 {
429 goNewCardDialog(GetSelectedDirectory());
430 }
431
432 // NOTE, will return -1 if more than one card selected, or no cards selected.
GetSelectedCardIndex
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
433 function GetSelectedCardIndex()
434 {
435 if (!gAbView)
436 return -1;
437
438 var treeSelection = gAbView.selection;
439 if (treeSelection.getRangeCount() == 1) {
440 var start = new Object;
441 var end = new Object;
442 treeSelection.getRangeAt(0,start,end);
443 if (start.value == end.value)
444 return start.value;
445 }
446
447 return -1;
448 }
449
450 // NOTE, returns the card if exactly one card is selected, null otherwise
GetSelectedCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
451 function GetSelectedCard()
452 {
453 var index = GetSelectedCardIndex();
454 return (index == -1) ? null : gAbView.getCardFromRow(index);
455 }
456
AbEditSelectedCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
457 function AbEditSelectedCard()
458 {
459 AbEditCard(GetSelectedCard());
460 }
461
AbEditCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
462 function AbEditCard(card)
463 {
464 // Need a card,
465 // but not allowing AOL special groups to be edited.
466 if (!card)
467 return;
468
469 if (card.isMailList) {
470 goEditListDialog(card, card.mailListURI, UpdateCardView);
471 }
472 else {
473 goEditCardDialog(GetSelectedDirectory(), card, UpdateCardView);
474 }
475 }
476
AbNewMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
477 function AbNewMessage()
478 {
479 var msgComposeType = Components.interfaces.nsIMsgCompType;
480 var msgComposFormat = Components.interfaces.nsIMsgCompFormat;
481 var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService();
482 msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
483
484 var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
485 if (params)
486 {
487 params.type = msgComposeType.New;
488 params.format = msgComposFormat.Default;
489 var composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
490 if (composeFields)
491 {
492 if (DirPaneHasFocus())
493 composeFields.to = GetSelectedAddressesFromDirTree();
494 else
495 composeFields.to = GetSelectedAddresses();
496 params.composeFields = composeFields;
497 msgComposeService.OpenComposeWindowWithParams(null, params);
498 }
499 }
500 }
501
GetOneOrMoreCardsSelected
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
502 function GetOneOrMoreCardsSelected()
503 {
504 if (!gAbView)
505 return false;
506
507 return (gAbView.selection.getRangeCount() > 0);
508 }
509
510 // XXX todo
511 // could this be moved into utilityOverlay.js?
goToggleSplitter
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
512 function goToggleSplitter( id, elementID )
513 {
514 var splitter = document.getElementById( id );
515 var element = document.getElementById( elementID );
516 if ( splitter )
517 {
518 var attribValue = splitter.getAttribute("state") ;
519 if ( attribValue == "collapsed" )
520 {
521 splitter.setAttribute("state", "open" );
522 if ( element )
523 element.setAttribute("checked","true")
524 }
525 else
526 {
527 splitter.setAttribute("state", "collapsed");
528 if ( element )
529 element.setAttribute("checked","false")
530 }
531 document.persist(id, 'state');
532 document.persist(elementID, 'checked');
533 }
534 }
535
536 // Generate a list of cards from the selected mailing list
537 // and get a comma separated list of card addresses. If the
538 // item selected in the directory pane is not a mailing list,
539 // an empty string is returned.
GetSelectedAddressesFromDirTree
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
540 function GetSelectedAddressesFromDirTree()
541 {
542 var addresses = "";
543
544 if (dirTree.currentIndex >= 0) {
545 var selectedResource = dirTree.builderView.getResourceAtIndex(dirTree.currentIndex);
546 var directory = GetDirectoryFromURI(selectedResource.Value);
547 if (directory.isMailList) {
548 var listCardsCount = directory.addressLists.Count();
549 var cards = new Array(listCardsCount);
550 for (var i = 0; i < listCardsCount; ++i)
551 cards[i] = directory.addressLists.QueryElementAt(
552 i, Components.interfaces.nsIAbCard);
553 addresses = GetAddressesForCards(cards);
554 }
555 }
556 return addresses;
557 }
558
GetSelectedAddresses
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
559 function GetSelectedAddresses()
560 {
561 return GetAddressesForCards(GetSelectedAbCards());
562 }
563
564 // Generate a comma separated list of addresses from a given
565 // set of cards.
GetAddressesForCards
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
566 function GetAddressesForCards(cards)
567 {
568 var addresses = "";
569
570 if (!cards)
571 return addresses;
572
573 var count = cards.length;
574 if (count > 0)
575 addresses += GenerateAddressFromCard(cards[0]);
576
577 for (var i = 1; i < count; i++) {
578 var generatedAddress = GenerateAddressFromCard(cards[i]);
579
580 if (generatedAddress)
581 addresses += "," + generatedAddress;
582 }
583 return addresses;
584 }
585
GetNumSelectedCards
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
586 function GetNumSelectedCards()
587 {
588 try {
589 return gAbView.selection.count;
590 }
591 catch (ex) {
592 }
593
594 // if something went wrong, return 0 for the count.
595 return 0;
596 }
597
598 // XXX todo
599 // an optimization might be to make this return
600 // the selected ranges, which would be faster
601 // when the user does large selections, but for now, let's keep it simple.
GetSelectedRows
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
602 function GetSelectedRows()
603 {
604 var selectedRows = "";
605
606 if (!gAbView)
607 return selectedRows;
608
609 var i,j;
610 var rangeCount = gAbView.selection.getRangeCount();
611 var current = 0;
612
613 for (i=0; i < rangeCount; i++) {
614 var start = new Object;
615 var end = new Object;
616 gAbView.selection.getRangeAt(i,start,end);
617 for (j=start.value;j<=end.value;j++) {
618 if (selectedRows)
619 selectedRows += ",";
620 selectedRows += j;
621 }
622 }
623 return selectedRows;
624 }
625
GetSelectedAbCards
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
626 function GetSelectedAbCards()
627 {
628 var abView = gAbView;
629
630 if (!abView)
631 return null;
632
633 var cards = new Array(abView.selection.count);
634 var i,j;
635 var count = abView.selection.getRangeCount();
636
637 var current = 0;
638
639 for (i=0; i < count; i++) {
640 var start = new Object;
641 var end = new Object;
642 abView.selection.getRangeAt(i,start,end);
643 for (j = start.value; j <= end.value; ++j)
644 cards[current++] = abView.getCardFromRow(j);
645 }
646 return cards;
647 }
648
SelectFirstAddressBook
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
649 function SelectFirstAddressBook()
650 {
651 dirTree.view.selection.select(0);
652
653 ChangeDirectoryByURI(GetSelectedDirectory());
654 gAbResultsTree.focus();
655 }
656
SelectFirstCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
657 function SelectFirstCard()
658 {
659 if (gAbView && gAbView.selection) {
660 gAbView.selection.select(0);
661 }
662 }
663
DirPaneClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
664 function DirPaneClick(event)
665 {
666 // we only care about left button events
667 if (event.button != 0)
668 return;
669
670 // if the user clicks on the header / trecol, do nothing
671 if (event.originalTarget.localName == "treecol") {
672 event.stopPropagation();
673 return;
674 }
675 }
676
DirPaneDoubleClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
677 function DirPaneDoubleClick(event)
678 {
679 // we only care about left button events
680 if (event.button != 0)
681 return;
682
683 var row = dirTree.treeBoxObject.getRowAt(event.clientX, event.clientY);
684 if (row == -1 || row > dirTree.view.rowCount-1) {
685 // double clicking on a non valid row should not open the dir properties dialog
686 return;
687 }
688
689 if (dirTree && dirTree.view.selection && dirTree.view.selection.count == 1)
690 AbEditSelectedDirectory();
691 }
692
DirPaneSelectionChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
693 function DirPaneSelectionChange()
694 {
695 // clear out the search box when changing folders...
696 onClearSearch();
697 if (dirTree && dirTree.view.selection && dirTree.view.selection.count == 1) {
698 gPreviousDirTreeIndex = dirTree.currentIndex;
699 ChangeDirectoryByURI(GetSelectedDirectory());
700 }
701 goUpdateCommand('cmd_newlist');
702 }
703
GetAbResultsBoxObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
704 function GetAbResultsBoxObject()
705 {
706 if (!gAbResultsTree)
707 gAbResultsTree = document.getElementById('abResultsTree');
708
709 return gAbResultsTree.treeBoxObject;
710 }
711
CloseAbView
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
712 function CloseAbView()
713 {
714 var boxObject = GetAbResultsBoxObject();
715 boxObject.view = null;
716
717 if (gAbView) {
718 gAbView.close();
719 gAbView = null;
720 }
721 }
722
SetAbView
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
723 function SetAbView(uri, searchView, sortColumn, sortDirection)
724 {
725 var actualSortColumn;
726
727 // make sure sortColumn and sortDirection have non null values before calling gAbView.init
728 if (!sortColumn)
729 sortColumn = kDefaultSortColumn;
730
731 if (!sortDirection)
732 sortDirection = kDefaultAscending;
733
734 if (gAbView && gCurDirectory == GetSelectedDirectory())
735 {
736 // re-init the view
737 actualSortColumn = gAbView.init(uri, searchView, GetAbViewListener(), sortColumn, sortDirection);
738 }
739 else
740 {
741 CloseAbView();
742
743 gCurDirectory = GetSelectedDirectory();
744 gAbView = Components.classes["@mozilla.org/addressbook/abview;1"].createInstance(Components.interfaces.nsIAbView);
745
746 actualSortColumn = gAbView.init(uri, searchView, GetAbViewListener(), sortColumn, sortDirection);
747 }
748
749 var boxObject = GetAbResultsBoxObject();
750 boxObject.view = gAbView.QueryInterface(Components.interfaces.nsITreeView);
751
752 UpdateSortIndicators(sortColumn, sortDirection);
753
754 return actualSortColumn;
755 }
756
GetAbView
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
757 function GetAbView()
758 {
759 return gAbView;
760 }
761
ChangeDirectoryByURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
762 function ChangeDirectoryByURI(uri)
763 {
764 if (!uri)
765 uri = kPersonalAddressbookURI;
766
767 if (gAbView && gAbView.URI == uri)
768 return;
769
770 var sortColumn = gAbResultsTree.getAttribute("sortCol");
771 var sortDirection = document.getElementById(sortColumn).getAttribute("sortDirection");
772
773 var actualSortColumn = SetAbView(uri, false, sortColumn, sortDirection);
774
775 UpdateSortIndicators(actualSortColumn, sortDirection);
776
777 // only select the first card if there is a first card
778 if (gAbView && gAbView.getCardFromRow(0)) {
779 SelectFirstCard();
780 }
781 else {
782 // the selection changes if we were switching directories.
783 ResultsPaneSelectionChanged()
784 }
785 return;
786 }
787
AbSortAscending
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
788 function AbSortAscending()
789 {
790 var sortColumn = gAbResultsTree.getAttribute("sortCol");
791 SortAndUpdateIndicators(sortColumn, kDefaultAscending);
792 }
793
AbSortDescending
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
794 function AbSortDescending()
795 {
796 var sortColumn = gAbResultsTree.getAttribute("sortCol");
797 SortAndUpdateIndicators(sortColumn, kDefaultDescending);
798 }
799
SortResultPane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
800 function SortResultPane(sortColumn)
801 {
802 var sortDirection = kDefaultAscending;
803
804 if (gAbView) {
805 sortDirection = gAbView.sortDirection;
806 }
807
808 SortAndUpdateIndicators(sortColumn, sortDirection);
809 }
810
SortAndUpdateIndicators
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
811 function SortAndUpdateIndicators(sortColumn, sortDirection)
812 {
813 // XXX todo remove once #116341 is fixed
814 if (!sortColumn)
815 return;
816
817 UpdateSortIndicators(sortColumn, sortDirection);
818
819 if (gAbView)
820 gAbView.sortBy(sortColumn, sortDirection);
821 }
822
UpdateSortIndicators
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
823 function UpdateSortIndicators(colID, sortDirection)
824 {
825 var sortedColumn;
826 // set the sort indicator on the column we are sorted by
827 if (colID) {
828 sortedColumn = document.getElementById(colID);
829 if (sortedColumn) {
830 sortedColumn.setAttribute("sortDirection",sortDirection);
831 gAbResultsTree.setAttribute("sortCol", colID);
832 }
833 }
834
835 // remove the sort indicator from all the columns
836 // except the one we are sorted by
837 var currCol = gAbResultsTree.firstChild.firstChild;
838 while (currCol) {
839 if (currCol != sortedColumn && currCol.localName == "treecol")
840 currCol.removeAttribute("sortDirection");
841 currCol = currCol.nextSibling;
842 }
843 }
844
InvalidateResultsPane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
845 function InvalidateResultsPane()
846 {
847 if (gAbResultsTree)
848 gAbResultsTree.treeBoxObject.invalidate();
849 }
850
AbNewList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
851 function AbNewList()
852 {
853 goNewListDialog(GetSelectedDirectory());
854 }
855
goNewListDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
856 function goNewListDialog(selectedAB)
857 {
858 window.openDialog("chrome://messenger/content/addressbook/abMailListDialog.xul",
859 "",
860 "chrome,resizable=no,titlebar,modal,centerscreen",
861 {selectedAB:selectedAB});
862 }
863
goEditListDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
864 function goEditListDialog(abCard, listURI, okCallback)
865 {
866 window.openDialog("chrome://messenger/content/addressbook/abEditListDialog.xul",
867 "",
868 "chrome,resizable=no,titlebar,modal,centerscreen",
869 {abCard:abCard, listURI:listURI, okCallback:okCallback});
870 }
871
goNewCardDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
872 function goNewCardDialog(selectedAB)
873 {
874 window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
875 "",
876 "chrome,resizable=no,titlebar,modal,centerscreen",
877 {selectedAB:selectedAB});
878 }
879
goEditCardDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
880 function goEditCardDialog(abURI, card, okCallback)
881 {
882 window.openDialog("chrome://messenger/content/addressbook/abEditCardDialog.xul",
883 "",
884 "chrome,resizable=no,modal,titlebar,centerscreen",
885 {abURI:abURI, card:card, okCallback:okCallback});
886 }
887
888
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
889 function setSortByMenuItemCheckState(id, value)
890 {
891 var menuitem = document.getElementById(id);
892 if (menuitem) {
893 menuitem.setAttribute("checked", value);
894 }
895 }
896
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
897 function InitViewSortByMenu()
898 {
899 var sortColumn = kDefaultSortColumn;
900 var sortDirection = kDefaultAscending;
901
902 if (gAbView) {
903 sortColumn = gAbView.sortColumn;
904 sortDirection = gAbView.sortDirection;
905 }
906
907 // this approach is necessary to support generic columns that get overlayed.
908 var elements = document.getElementsByAttribute("name","sortas");
909 for (var i=0; i<elements.length; i++) {
910 var cmd = elements[i].getAttribute("id");
911 var columnForCmd = cmd.split("cmd_SortBy")[1];
912 setSortByMenuItemCheckState(cmd, (sortColumn == columnForCmd));
913 }
914
915 setSortByMenuItemCheckState("sortAscending", (sortDirection == kDefaultAscending));
916 setSortByMenuItemCheckState("sortDescending", (sortDirection == kDefaultDescending));
917 }
918
GenerateAddressFromCard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
919 function GenerateAddressFromCard(card)
920 {
921 if (!card)
922 return "";
923
924 var email;
925
926 if (card.isMailList)
927 {
928 var directory = GetDirectoryFromURI(card.mailListURI);
929 email = directory.description || card.displayName;
930 }
931 else
932 email = card.primaryEmail;
933
934 return gHeaderParser.makeFullAddressWString(card.displayName, email);
935 }
936
GetDirectoryFromURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
937 function GetDirectoryFromURI(uri)
938 {
939 return rdf.GetResource(uri).QueryInterface(Components.interfaces.nsIAbDirectory);
940 }
941
942 // returns null if abURI is not a mailing list URI
GetParentDirectoryFromMailingListURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
943 function GetParentDirectoryFromMailingListURI(abURI)
944 {
945 var abURIArr = abURI.split("/");
946 /*
947 turn turn "moz-abmdbdirectory://abook.mab/MailList6"
948 into ["moz-abmdbdirectory:","","abook.mab","MailList6"]
949 then, turn ["moz-abmdbdirectory:","","abook.mab","MailList6"]
950 into "moz-abmdbdirectory://abook.mab"
951 */
952 if (abURIArr.length == 4 && abURIArr[0] == "moz-abmdbdirectory:" && abURIArr[3] != "") {
953 return abURIArr[0] + "/" + abURIArr[1] + "/" + abURIArr[2];
954 }
955
956 return null;
957 }
958
DirPaneHasFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
959 function DirPaneHasFocus()
960 {
961 // returns true if diectory pane has the focus. Returns false, otherwise.
962 return (top.document.commandDispatcher.focusedElement == dirTree)
963 }
964
GetSelectedDirectory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
965 function GetSelectedDirectory()
966 {
967 if (abList)
968 return abList.selectedItem.id;
969 else {
970 if (dirTree.currentIndex < 0)
971 return null;
972 var selected = dirTree.builderView.getResourceAtIndex(dirTree.currentIndex)
973 return selected.Value;
974 }
975 }
976
onAbSearchKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
977 function onAbSearchKeyPress(event)
978 {
979 // 13 == return
980 if (event && event.keyCode == 13)
981 onAbSearchInput(true);
982 }
983
onAbSearchInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
984 function onAbSearchInput(returnKeyHit)
985 {
986 if (gSearchInput.showingSearchCriteria && !(returnKeyHit && gSearchInput.value == ""))
987 return;
988
989 SearchInputChanged();
990
991 if (gSearchTimer) {
992 clearTimeout(gSearchTimer);
993 gSearchTimer = null;
994 }
995
996 if (returnKeyHit) {
997 gSearchInput.select();
998 onEnterInSearchBar();
999 }
1000 else {
1001 gSearchTimer = setTimeout(onEnterInSearchBar, 800);
1002 }
1003 }
1004
SearchInputChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1005 function SearchInputChanged()
1006 {
1007 var clearButton = document.getElementById("clear");
1008 if (clearButton) {
1009 if (gSearchInput.value && (gSearchInput.value != ""))
1010 clearButton.removeAttribute("disabled");
1011 else
1012 clearButton.setAttribute("disabled", "true");
1013 }
1014 }
1015
onAbClearSearch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1016 function onAbClearSearch()
1017 {
1018 if (gSearchInput)
1019 gSearchInput.value =""; //on input does not get fired for some reason
1020 onAbSearchInput(true);
1021 }
1022
AbSwapFirstNameLastName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1023 function AbSwapFirstNameLastName()
1024 {
1025 if (gAbView)
1026 gAbView.swapFirstNameLastName();
1027 }
1028
1029
onSearchInputFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1030 function onSearchInputFocus(event)
1031 {
1032 // search bar has focus, ...clear the showing search criteria flag
1033 if (gSearchInput.showingSearchCriteria)
1034 {
1035 gSearchInput.value = "";
1036 gSearchInput.showingSearchCriteria = false;
1037 }
1038
1039 gSearchInput.select();
1040 }
1041
1042 // sets focus into the quick search box
QuickSearchFocus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1043 function QuickSearchFocus()
1044 {
1045 gSearchInput.focus();
1046 }
1047
onSearchInputBlur
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1048 function onSearchInputBlur(event)
1049 {
1050 // if (gQuickSearchFocusEl && gQuickSearchFocusEl.id == 'searchInput') // ignore the blur if we are in the middle of processing the clear button
1051 // return;
1052
1053 if (!gSearchInput.value)
1054 gSearchInput.showingSearchCriteria = true;
1055
1056 if (gSearchInput.showingSearchCriteria)
1057 gSearchInput.setSearchCriteriaText();
1058 }
1059
1060 var gQuickSearchFocusEl = null;
1061
onClearSearch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1062 function onClearSearch()
1063 {
1064 if (gSearchInput && !gSearchInput.showingSearchCriteria) // ignore the text box value if it's just showing the search criteria string
1065 {
1066 onAbClearSearch();
1067 // this needs to be on a timer otherwise we end up messing up the focus while the Search("") is still happening
1068 setTimeout(restoreSearchFocusAfterClear, 0);
1069 }
1070 }
1071
restoreSearchFocusAfterClear
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1072 function restoreSearchFocusAfterClear()
1073 {
1074 // gQuickSearchFocusEl.focus();
1075 gSearchInput.clearButtonHidden = 'true';
1076 gQuickSearchFocusEl = null;
1077 }
1078
1079 var gIsOffline;
1080 var gSessionAdded;
1081 var gCurrentAutocompleteDirectory;
1082 var gAutocompleteSession;
1083 var gSetupLdapAutocomplete;
1084 var gLDAPSession;
1085
setupLdapAutocompleteSession
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1086 function setupLdapAutocompleteSession()
1087 {
1088 var autocompleteLdap = false;
1089 var autocompleteDirectory = null;
1090 var prevAutocompleteDirectory = gCurrentAutocompleteDirectory;
1091 var i;
1092
1093 autocompleteLdap = gPrefs.getBoolPref("ldap_2.autoComplete.useDirectory");
1094 if (autocompleteLdap)
1095 autocompleteDirectory = gPrefs.getCharPref(
1096 "ldap_2.autoComplete.directoryServer");
1097
1098
1099 // use a temporary to do the setup so that we don't overwrite the
1100 // global, then have some problem and throw an exception, and leave the
1101 // global with a partially setup session. we'll assign the temp
1102 // into the global after we're done setting up the session
1103 //
1104 var LDAPSession;
1105 if (gLDAPSession) {
1106 LDAPSession = gLDAPSession;
1107 } else {
1108 LDAPSession = Components.classes[
1109 "@mozilla.org/autocompleteSession;1?type=ldap"].createInstance()
1110 .QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
1111 }
1112
1113 if (autocompleteDirectory && !gIsOffline) {
1114 // the compose window code adds an observer on the directory server
1115 // prefs, but I don't think we need this here.
1116 gCurrentAutocompleteDirectory = autocompleteDirectory;
1117
1118 // fill in the session params if there is a session
1119 //
1120 if (LDAPSession) {
1121 var serverURL = Components.classes[
1122 "@mozilla.org/network/ldap-url;1"].
1123 createInstance().QueryInterface(
1124 Components.interfaces.nsILDAPURL);
1125
1126 try {
1127 serverURL.spec = gPrefs.getComplexValue(autocompleteDirectory +".uri",
1128 Components.interfaces.nsISupportsString).data;
1129 } catch (ex) {
1130 dump("ERROR: " + ex + "\n");
1131 }
1132 LDAPSession.serverURL = serverURL;
1133
1134 // get the login to authenticate as, if there is one
1135 //
1136 try {
1137 LDAPSession.login =gPrefs.getComplexValue(
1138 autocompleteDirectory + ".auth.dn",
1139 Components.interfaces.nsISupportsString).data;
1140 } catch (ex) {
1141 // if we don't have this pref, no big deal
1142 }
1143
1144 // don't search on non-CJK strings shorter than this
1145 //
1146 try {
1147 LDAPSession.minStringLength = gPrefs.getIntPref(
1148 autocompleteDirectory + ".autoComplete.minStringLength");
1149 } catch (ex) {
1150 // if this pref isn't there, no big deal. just let
1151 // nsLDAPAutoCompleteSession use its default.
1152 }
1153
1154 // don't search on CJK strings shorter than this
1155 //
1156 try {
1157 LDAPSession.cjkMinStringLength = gPrefs.getIntPref(
1158 autocompleteDirectory + ".autoComplete.cjkMinStringLength");
1159 } catch (ex) {
1160 // if this pref isn't there, no big deal. just let
1161 // nsLDAPAutoCompleteSession use its default.
1162 }
1163
1164 // we don't try/catch here, because if this fails, we're outta luck
1165 //
1166 var ldapFormatter = Components.classes[
1167 "@mozilla.org/ldap-autocomplete-formatter;1?type=addrbook"]
1168 .createInstance().QueryInterface(
1169 Components.interfaces.nsIAbLDAPAutoCompFormatter);
1170
1171 // override autocomplete name format?
1172 //
1173 try {
1174 ldapFormatter.nameFormat =
1175 gPrefs.getComplexValue(autocompleteDirectory +
1176 ".autoComplete.nameFormat",
1177 Components.interfaces.nsISupportsString).data;
1178 } catch (ex) {
1179 // if this pref isn't there, no big deal. just let
1180 // nsAbLDAPAutoCompFormatter use its default.
1181 }
1182
1183 // override autocomplete mail address format?
1184 //
1185 try {
1186 ldapFormatter.addressFormat =
1187 gPrefs.getComplexValue(autocompleteDirectory +
1188 ".autoComplete.addressFormat",
1189 Components.interfaces.nsISupportsString).data;
1190 } catch (ex) {
1191 // if this pref isn't there, no big deal. just let
1192 // nsAbLDAPAutoCompFormatter use its default.
1193 }
1194
1195 try {
1196 // figure out what goes in the comment column, if anything
1197 //
1198 // 0 = none
1199 // 1 = name of addressbook this card came from
1200 // 2 = other per-addressbook format
1201 //
1202 var showComments = 0;
1203 showComments = gPrefs.getIntPref(
1204 "mail.autoComplete.commentColumn");
1205
1206 switch (showComments) {
1207
1208 case 1:
1209 // use the name of this directory
1210 //
1211 ldapFormatter.commentFormat = gPrefs.getComplexValue(
1212 autocompleteDirectory + ".description",
1213 Components.interfaces.nsISupportsString).data;
1214 break;
1215
1216 case 2:
1217 // override ldap-specific autocomplete entry?
1218 //
1219 try {
1220 ldapFormatter.commentFormat =
1221 gPrefs.getComplexValue(autocompleteDirectory +
1222 ".autoComplete.commentFormat",
1223 Components.interfaces.nsISupportsString).data;
1224 } catch (innerException) {
1225 // if nothing has been specified, use the ldap
1226 // organization field
1227 ldapFormatter.commentFormat = "[o]";
1228 }
1229 break;
1230
1231 case 0:
1232 default:
1233 // do nothing
1234 }
1235 } catch (ex) {
1236 // if something went wrong while setting up comments, try and
1237 // proceed anyway
1238 }
1239
1240 // set the session's formatter, which also happens to
1241 // force a call to the formatter's getAttributes() method
1242 // -- which is why this needs to happen after we've set the
1243 // various formats
1244 //
1245 LDAPSession.formatter = ldapFormatter;
1246
1247 // override autocomplete entry formatting?
1248 //
1249 try {
1250 LDAPSession.outputFormat =
1251 gPrefs.getComplexValue(autocompleteDirectory +
1252 ".autoComplete.outputFormat",
1253 Components.interfaces.nsISupportsString).data;
1254
1255 } catch (ex) {
1256 // if this pref isn't there, no big deal. just let
1257 // nsLDAPAutoCompleteSession use its default.
1258 }
1259
1260 // override default search filter template?
1261 //
1262 try {
1263 LDAPSession.filterTemplate = gPrefs.getComplexValue(
1264 autocompleteDirectory + ".autoComplete.filterTemplate",
1265 Components.interfaces.nsISupportsString).data;
1266
1267 } catch (ex) {
1268 // if this pref isn't there, no big deal. just let
1269 // nsLDAPAutoCompleteSession use its default
1270 }
1271
1272 // override default maxHits (currently 100)
1273 //
1274 try {
1275 // XXXdmose should really use .autocomplete.maxHits,
1276 // but there's no UI for that yet
1277 //
1278 LDAPSession.maxHits =
1279 gPrefs.getIntPref(autocompleteDirectory + ".maxHits");
1280 } catch (ex) {
1281 // if this pref isn't there, or is out of range, no big deal.
1282 // just let nsLDAPAutoCompleteSession use its default.
1283 }
1284
1285 if (!gSessionAdded) {
1286 // if we make it here, we know that session initialization has
1287 // succeeded; add the session for all recipients, and
1288 // remember that we've done so
1289 var autoCompleteWidget;
1290 for (i=1; i <= awGetMaxRecipients(); i++)
1291 {
1292 autoCompleteWidget = document.getElementById("addressCol1#" + i);
1293 if (autoCompleteWidget)
1294 {
1295 autoCompleteWidget.addSession(LDAPSession);
1296 // ldap searches don't insert a default entry with the default domain appended to it
1297 // so reduce the minimum results for a popup to 2 in this case.
1298 autoCompleteWidget.minResultsForPopup = 2;
1299
1300 }
1301 }
1302 gSessionAdded = true;
1303 }
1304 }
1305 } else {
1306 if (gCurrentAutocompleteDirectory) {
1307 gCurrentAutocompleteDirectory = null;
1308 }
1309 if (gLDAPSession && gSessionAdded) {
1310 for (i=1; i <= awGetMaxRecipients(); i++)
1311 document.getElementById("addressCol1#" + i).
1312 removeSession(gLDAPSession);
1313 gSessionAdded = false;
1314 }
1315 }
1316
1317 gLDAPSession = LDAPSession;
1318 gSetupLdapAutocomplete = true;
1319 }