Bug 532505 - Cannot select address book if quick search widget is removed from toolbar - Error: gSearchInput is null ... abCommon.js Line: 588; r=standard8
authorJim Porter <squibblyflabbetydoo@gmail.com>
Mon, 08 Aug 2011 17:56:33 -0500
changeset 8265 0c5f5d10b4bc41c934b7c502ae632e9b41e6da4f
parent 8264 e15d27718d811d77d67e8915fa492ad9d98a0ef3
child 8266 ef977dca2337aebabfd77af8d02a9d8a394d849b
push id6357
push usersquibblyflabbetydoo@gmail.com
push dateMon, 08 Aug 2011 23:25:42 +0000
treeherdercomm-central@0c5f5d10b4bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs532505
Bug 532505 - Cannot select address book if quick search widget is removed from toolbar - Error: gSearchInput is null ... abCommon.js Line: 588; r=standard8
mail/components/addrbook/content/abCommon.js
mail/components/addrbook/content/abContactsPanel.js
mail/components/addrbook/content/addressbook.js
mailnews/addrbook/content/abResultsPane.js
--- a/mail/components/addrbook/content/abCommon.js
+++ b/mail/components/addrbook/content/abCommon.js
@@ -633,25 +633,30 @@ function GetSelectedDirectory()
     if (gDirTree.currentIndex < 0)
       return null;
     return gDirectoryTreeView.getDirectoryAtIndex(gDirTree.currentIndex).URI;
   }
 }
 
 function onAbClearSearch()
 {
-  gSearchInput.value = "";
+  var searchInput = document.getElementById("peopleSearchInput");
+  if (searchInput)
+    searchInput.value = "";
   onEnterInSearchBar();
 }
 
 // sets focus into the quick search box
 function QuickSearchFocus()
 {
-  gSearchInput.focus();
-  gSearchInput.select();
+  var searchInput = document.getElementById("peopleSearchInput");
+  if (searchInput) {
+    searchInput.focus();
+    searchInput.select();
+  }
 }
 
 var gQuickSearchFocusEl = null;
 var gIsOffline;
 var gSessionAdded;
 var gCurrentAutocompleteDirectory;
 var gAutocompleteSession;
 var gSetupLdapAutocomplete;
--- a/mail/components/addrbook/content/abContactsPanel.js
+++ b/mail/components/addrbook/content/abContactsPanel.js
@@ -77,17 +77,18 @@ function addSelectedAddresses(recipientT
     var address = GenerateAddressFromCard(cards[i]);
     if (address != "")
       parent.AddRecipient(recipientType, address);     
   }
 }
 
 function AddressBookMenuListChange()
 {
-  if (gSearchInput.value && !gSearchInput.showingSearchCriteria) 
+  var searchInput = document.getElementById("peopleSearchInput");
+  if (searchInput.value && !searchInput.showingSearchCriteria)
     onEnterInSearchBar();
   else 
     ChangeDirectoryByURI(document.getElementById('addressbookList').value);
 }
 
 function AbPanelOnComposerClose()
 {
   CloseAbView();
@@ -114,17 +115,16 @@ function AbPanelLoad()
   abPopup.value = temp;
   if (!abPopup.selectedItem)
     abPopup.selectedIndex = 0;
 
   ChangeDirectoryByURI(abPopup.value);
 
   parent.addEventListener("compose-window-close", AbPanelOnComposerClose, true);
   parent.addEventListener("compose-window-reopen", AbPanelOnComposerReOpen, true);
-  gSearchInput = document.getElementById("peopleSearchInput");
 }
 
 function AbPanelUnload()
 {
   parent.removeEventListener("compose-window-close", AbPanelOnComposerClose, true);
   parent.removeEventListener("compose-window-reopen", AbPanelOnComposerReOpen, true);
 
   CloseAbView();
@@ -163,14 +163,15 @@ function UpdateCardView()
 
 function onEnterInSearchBar()
 {
   if (!gQueryURIFormat) 
     gQueryURIFormat = gPrefs.getComplexValue("mail.addr_book.quicksearchquery.format", 
                                               Components.interfaces.nsIPrefLocalizedString).data;
  
   var searchURI = GetSelectedDirectory();
+  var searchInput = document.getElementById("peopleSearchInput");
 
-  if (gSearchInput.value != "")
-    searchURI += gQueryURIFormat.replace(/@V/g, encodeURIComponent(gSearchInput.value));
+  if (searchInput.value != "")
+    searchURI += gQueryURIFormat.replace(/@V/g, encodeURIComponent(searchInput.value));
 
   SetAbView(searchURI);
 }
--- a/mail/components/addrbook/content/addressbook.js
+++ b/mail/components/addrbook/content/addressbook.js
@@ -48,17 +48,16 @@ Components.utils.import("resource:///mod
 const nsIAbListener = Components.interfaces.nsIAbListener;
 const kPrefMailAddrBookLastNameFirst = "mail.addr_book.lastnamefirst";
 const kPersistCollapseMapStorage = "directoryTree.json";
 
 var cvPrefs = 0;
 var gSearchTimer = null;
 var gStatusText = null;
 var gQueryURIFormat = null;
-var gSearchInput;
 var gCardViewBox;
 var gCardViewBoxEmail1;
 var gPreviousDirTreeIndex = -1;
 
 var msgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"]
                           .createInstance(Components.interfaces.nsIMsgWindow);
 
 // Constants that correspond to choices
@@ -177,18 +176,16 @@ function OnLoadAddressBook()
     document.documentElement.setAttribute("screenX", screen.availLeft);
     document.documentElement.setAttribute("screenY", screen.availTop);
   }
   setTimeout(delayedOnLoadAddressBook, 0); // when debugging, set this to 5000, so you can see what happens after the window comes up.
 }
 
 function delayedOnLoadAddressBook()
 {
-  gSearchInput = document.getElementById("peopleSearchInput");
-
   verifyAccounts(null, false);   // this will do migration, if we need to.
 
   InitCommonJS();
 
   GetCurrentPrefs();
 
   // FIX ME - later we will be able to use onload from the overlay
   OnLoadCardView();
@@ -464,17 +461,18 @@ function AbExport()
 function SetStatusText(total)
 {
   if (!gStatusText)
     gStatusText = document.getElementById('statusText');
 
   try {
     var statusText;
 
-    if (gSearchInput && gSearchInput.value) {
+    var searchInput = document.getElementById("peopleSearchInput");
+    if (searchInput && searchInput.value) {
       if (total == 0)
         statusText = gAddressBookBundle.getString("noMatchFound");
       else
       {
         if (total == 1)
           statusText = gAddressBookBundle.getString("matchFound");
         else
           statusText = gAddressBookBundle.getFormattedString("matchesFound", [total]);
@@ -528,20 +526,21 @@ function onEnterInSearchBar()
   var searchURI = GetSelectedDirectory();
   if (!searchURI) return;
 
   /*
    XXX todo, handle the case where the LDAP url
    already has a query, like
    moz-abldapdirectory://nsdirectory.netscape.com:389/ou=People,dc=netscape,dc=com?(or(Department,=,Applications))
   */
-  if (gSearchInput.value != "") {
+  var searchInput = document.getElementById("peopleSearchInput");
+  if (searchInput && searchInput.value != "") {
     // replace all instances of @V with the escaped version
     // of what the user typed in the quick search text input
-    searchURI += gQueryURIFormat.replace(/@V/g, encodeURIComponent(gSearchInput.value));
+    searchURI += gQueryURIFormat.replace(/@V/g, encodeURIComponent(searchInput.value));
   }
 
   SetAbView(searchURI);
 
   // XXX todo
   // this works for synchronous searches of local addressbooks,
   // but not for LDAP searches
   SelectFirstCard();
@@ -549,16 +548,17 @@ function onEnterInSearchBar()
 
 function SwitchPaneFocus(event)
 {
   var focusedElement    = WhichPaneHasFocus();
   var cardViewBox       = GetCardViewBox();
   var cardViewBoxEmail1 = GetCardViewBoxEmail1();
   var searchBox         = document.getElementById('search-container');
   var dirTree           = GetDirTree();
+  var searchInput       = document.getElementById('peopleSearchInput');
 
   if (event && event.shiftKey)
   {
     if (focusedElement == gAbResultsTree && searchBox)
       searchInput.focus();
     else if ((focusedElement == gAbResultsTree || focusedElement == searchBox) && !IsDirPaneCollapsed())
       dirTree.focus();
     else if (focusedElement != cardViewBox && !IsCardViewAndAbResultsPaneSplitterCollapsed())
@@ -579,18 +579,18 @@ function SwitchPaneFocus(event)
     {
       if(cardViewBoxEmail1)
         cardViewBoxEmail1.focus();
       else
         cardViewBox.focus();
     }
     else if (focusedElement != dirTree && !IsDirPaneCollapsed())
       dirTree.focus();
-    else if (searchBox)
-      gSearchInput.focus();
+    else if (searchBox && searchInput)
+      searchInput.focus();
     else
       gAbResultsTree.focus();
   }
 }
 
 function WhichPaneHasFocus()
 {
   var cardViewBox       = GetCardViewBox();
--- a/mailnews/addrbook/content/abResultsPane.js
+++ b/mailnews/addrbook/content/abResultsPane.js
@@ -32,18 +32,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /**
  * Use of items in this file require:
  *
- * gSearchInput
- *   global variable to be set up pointing to the search input box
  * GetSelectedDirectory()
  *   returns the URI of the selected directory
  * AbResultsPaneDoubleClick(card)
  *   Is called when the results pane is double-clicked, with the clicked card.
  * AbEditCard(card)
  *   Is called when a card is to be edited, with the card as the parameter.
  *
  * The following function is only required if ResultsPaneController is used: