Bug 490111 - Setting kDebug to false broke "function getElementById()" which had apparently never been tested, and is even less pretty when it's made to work, so just use document.getElementById() instead, r=philringnalda
authorBlake Winton <bwinton@latte.ca>
Tue, 01 Sep 2009 16:42:23 +0100
changeset 3473 12460d9e985bc2862d146513a2dee99813d137fc
parent 3472 2c185d4050c25030e358d0f39a479fc81a6c18ac
child 3474 e2d7771ba879fcf38159df92c473223ba242bb2a
push idunknown
push userunknown
push dateunknown
reviewersphilringnalda
bugs490111
Bug 490111 - Setting kDebug to false broke "function getElementById()" which had apparently never been tested, and is even less pretty when it's made to work, so just use document.getElementById() instead, r=philringnalda
mailnews/base/prefs/content/accountcreation/emailWizard.js
--- a/mailnews/base/prefs/content/accountcreation/emailWizard.js
+++ b/mailnews/base/prefs/content/accountcreation/emailWizard.js
@@ -70,38 +70,23 @@ Cu.import("resource://app/modules/gloda/
 let gSmtpManager = Cc["@mozilla.org/messengercompose/smtp;1"]
                    .getService(Ci.nsISmtpService);
 let gAccountMgr = Cc["@mozilla.org/messenger/account-manager;1"]
                   .getService(Ci.nsIMsgAccountManager);
 let gEmailWizardLogger = Log4Moz.getConfiguredLogger("emailwizard");
 let gStringsBundle;
 let gBrandBundle;
 
-// debugging aid
-if (kDebug) {
-  function getElementById(id)
-  {
-    let elt = document.getElementById(id);
-    if (!elt)
-    {
-      gEmailWizardLogger.error("Can't find element ID: " + id);
-      return null;
-    }
-    return elt;
-  }
-} else // production
-  getElementById = document.getElementById;
-
 function _hide(id)
 {
-  getElementById(id).hidden = true;
+  document.getElementById(id).hidden = true;
 }
 function _show(id)
 {
-  getElementById(id).hidden = false;
+  document.getElementById(id).hidden = false;
 }
 function EmailConfigWizard()
 {
   this._init();
 }
 EmailConfigWizard.prototype =
 {
   _init : function EmailConfigWizard__init()
@@ -126,56 +111,56 @@ EmailConfigWizard.prototype =
     this._incomingWarning = 'cleartext';
     this._outgoingWarning = 'cleartext';
     this._userPickedOutgoingServer = false;
 
     if (window.arguments && window.arguments[0] &&
         window.arguments[0].msgWindow)
       this._parentMsgWindow = window.arguments[0].msgWindow;
 
-    gStringsBundle = getElementById("strings");
+    gStringsBundle = document.getElementById("strings");
     gBrandBundle = document.getElementById("bundle_brand");
 
     // Populate SMTP server dropdown with already configured SMTP servers from
     // other accounts.
     let gSmtpManager = Cc["@mozilla.org/messengercompose/smtp;1"]
                        .getService(Ci.nsISmtpService);
     this._smtpServers = gSmtpManager.smtpServers;
-    var menupopup = getElementById("smtp_menupopup");
+    var menupopup = document.getElementById("smtp_menupopup");
     this._smtpServerCount = 0;
     while (this._smtpServers.hasMoreElements())
     {
       var server = this._smtpServers.getNext().QueryInterface(Ci.nsISmtpServer);
       this._smtpServerCount++;
       var menuitem = document.createElement("menuitem");
       var label = server.displayname;
       if (server.key == gSmtpManager.defaultServer.key)
         label += " " + gStringsBundle.getString("default_server_tag");
 
       menuitem.setAttribute("label", label);
       menuitem.setAttribute("value", server.key);
       menuitem.hostname = server.hostname;
       menupopup.appendChild(menuitem);
     }
-    var menulist = getElementById("outgoing_server");
+    var menulist = document.getElementById("outgoing_server");
     menulist.addEventListener("command",
       function(event) { gEmailConfigWizard.userChangedOutgoing(event); }, true);
   },
 
   /* When the next button is clicked we've moved from the initial account
    * information stage to using that information to configure account details.
    */
   onNext : function()
   {
     // change the inputs to a flat look
     this._accountInfoInputs(true);
 
-    this._email = getElementById("email").value;
-    this._realname = getElementById("realname").value;
-    this._password = getElementById("password").value;
+    this._email = document.getElementById("email").value;
+    this._realname = document.getElementById("realname").value;
+    this._password = document.getElementById("password").value;
 
     this.showConfigDetails();
 
     let domain = this._email.split("@")[1];
     this.findConfig(domain, this._email);
 
     // swap out buttons
     _hide("next_button");
@@ -210,42 +195,44 @@ EmailConfigWizard.prototype =
    *
    * NOTE: The remember password input was skipped purposefully, people should
    *        continue to be able to change that setting even as account details
    *        are determined.
    */
   _accountInfoInputs : function(disabled)
   {
     let ids = ["realname","email","password"];
-    if (disabled && getElementById("password").getAttribute("empty")) {
-      getElementById("password").value = " ";
-      getElementById("password").setAttribute("empty", true);
-      getElementById("remember_password").checked = false;
+    if (disabled && document.getElementById("password").getAttribute("empty")) {
+      document.getElementById("password").value = " ";
+      document.getElementById("password").setAttribute("empty", true);
+      document.getElementById("remember_password").checked = false;
     }
 
     for ( let i = 0; i < ids.length; i++ )
-      getElementById(ids[i]).disabled = disabled;
+      document.getElementById(ids[i]).disabled = disabled;
 
-    if (!disabled && getElementById("password").getAttribute("empty")) {
-      getElementById("password").value = "";
-      getElementById("password").setAttribute("empty", true);
-      getElementById("remember_password").checked = false;
+    if (!disabled &&
+        document.getElementById("password").getAttribute("empty")) {
+      document.getElementById("password").value = "";
+      document.getElementById("password").setAttribute("empty", true);
+      document.getElementById("remember_password").checked = false;
     }
   },
 
   userChangedOutgoing : function(event)
   {
-    let menulist = getElementById("outgoing_server");
+    let menulist = document.getElementById("outgoing_server");
 
     let selectedIndex = menulist.getIndexOfItem(event.target);
 
     if (selectedIndex != -1) {
-      getElementById("outgoing_port").value = this._currentConfig.outgoing.port;
-      getElementById("outgoing_security").value = this._currentConfig
-                                                      .outgoing.socketType;
+      document.getElementById("outgoing_port").value =
+        this._currentConfig.outgoing.port;
+      document.getElementById("outgoing_security").value =
+        this._currentConfig.outgoing.socketType;
     }
 
     if (selectedIndex == -1 || selectedIndex == 0) {
       this._outgoingState = '';
       this._userPickedOutgoingServer = false;
       _show('outgoing_protocol');
       _show('outgoing_port');
       _show('outgoing_security');
@@ -270,66 +257,66 @@ EmailConfigWizard.prototype =
   },
 
   /* This does very little other than to check that a name was entered at all
    * Since this is such an insignificant test we should be using a very light
    * or even jovial warning.
    */
   validateRealname : function()
   {
-    if (getElementById('realname').value.length > 0)
+    if (document.getElementById('realname').value.length > 0)
       this.clearError('nameerror');
     else
       this.setError("nameerror", "name.error");
   },
 
   /*
    * This checks if the email address is at least possibly valid, meaning it
    * has an '@' before the last char.
    */
   emailAddrValidish : function()
   {
-    let emailAddr = getElementById('email').value;
+    let emailAddr = document.getElementById('email').value;
     let atPos = emailAddr.lastIndexOf("@");
     return  atPos > 0 && atPos + 1 < emailAddr.length;
   },
 
   /*
    * onEmailInput and onRealnameInput are called onInput, and just handle
    * hiding/showing the next button based on whether there's a semi-reasonable
    * e-mail address and nonblank realname to start with.
    */
   onEmailInput : function()
   {
-    if (getElementById('realname').value.length > 0 &&
+    if (document.getElementById('realname').value.length > 0 &&
         this.emailAddrValidish())
       _show("next_button");
     else
       _hide("next_button");
    },
 
   onRealnameInput : function()
   {
-    if (getElementById('realname').value.length > 0 &&
+    if (document.getElementById('realname').value.length > 0 &&
         this.emailAddrValidish())
       _show("next_button");
     else
       _hide("next_button");
    },
 
   /* This check is done on blur and is only done as an informative warning
    * we don't want to block the person if they've entered and email that
    * doesn't conform to our regex
    */
   validateEmail : function()
   {
-    if (getElementById('email').value.length <= 0)
+    if (document.getElementById('email').value.length <= 0)
       return;
 
-    if (emailRE.test(getElementById('email').value))
+    if (emailRE.test(document.getElementById('email').value))
       this.clearError('emailerror');
     else
       this.setError("emailerror", "email.error");
   },
 
   // We use this to  prevent probing from forgetting the user's choice.
   setSecurity : function(eltId)
   {
@@ -362,33 +349,33 @@ EmailConfigWizard.prototype =
         this._userChangedOutgoingPort = true;
         this._outgoingState = "";
         break;
     }
   },
   
   oninputPassword : function()
   {
-    let passwordElt = getElementById("password");
-    let rememberPasswordElt = getElementById("remember_password");
+    let passwordElt = document.getElementById("password");
+    let rememberPasswordElt = document.getElementById("remember_password");
     if (passwordElt.value.length < 1) {
-      getElementById("remember_password").checked = false;
+      document.getElementById("remember_password").checked = false;
       this._userChangedPassword = false;
     }
     else if (!this._userChangedPassword)
-      getElementById("remember_password").checked = true;
+      document.getElementById("remember_password").checked = true;
   },
 
   /* If the user just tabbed through the password input without entering
    * anything, set the type back to text so we don't wind up showing the
    * emptytext as bullet characters.
    */
   onblurPassword : function()
   {
-    let passwordElt = getElementById("password");
+    let passwordElt = document.getElementById("password");
     if (passwordElt.value.length < 1)
       passwordElt.type = "text";
   },
 
   findConfig : function(domain, email)
   {
     gEmailWizardLogger.info("findConfig()");
     this.startSpinner("searching_for_configs");
@@ -543,18 +530,18 @@ EmailConfigWizard.prototype =
   {
     this._currentConfigFilledIn = config.copy();
     _show("advanced_settings");
     replaceVariables(this._currentConfigFilledIn, this._realname, this._email,
                      this._password);
 
     this.updateConfig(this._currentConfigFilledIn);
 
-    getElementById('create_button').disabled = false;
-    getElementById('create_button').hidden = false;
+    document.getElementById('create_button').disabled = false;
+    document.getElementById('create_button').hidden = false;
 
   },
 
   /*
    * Returns either the nsISmtpServer.key for an existing account that matches
    * our discovered hostname + port + username, or false if no match is found.
    */
   keyForExistingOutgoingAccount : function()
@@ -604,17 +591,17 @@ EmailConfigWizard.prototype =
       details.setAttribute("collapsed", true);
       tech.removeAttribute("expanded");
     }
   },
 
   toggleAcknowledgeWarning : function()
   {
     this._warningAcknowledged =
-      getElementById('acknowledge_warning').checked;
+      document.getElementById('acknowledge_warning').checked;
     this.checkEnableIKnow();
   },
 
   checkEnableIKnow: function()
   {
     if ((!this._incomingWarning && !this._outgoingWarning) ||
         this._warningAcknowledged)
       document.getElementById('iknow').disabled = false;
@@ -699,17 +686,17 @@ EmailConfigWizard.prototype =
       }
 
     } catch (ex) { alertPrompt(gStringsBundle.getString("error_creating_account"), ex); }
   },
 
   getMeOutOfHere : function()
   {
     // If we're going backwards, we should reset the acknowledge_warning.
-    getElementById('acknowledge_warning').checked = false;
+    document.getElementById('acknowledge_warning').checked = false;
     this.toggleAcknowledgeWarning();
     _hide('warningbox');
     _show('mastervbox');
   },
 
   validateAndFinish : function()
   {
     // if we're coming from the cert warning dialog
@@ -728,26 +715,26 @@ EmailConfigWizard.prototype =
       let existingKey = this.keyForExistingOutgoingAccount();
       if (existingKey)
       {
         this._currentConfigFilledIn.outgoing.addThisServer = false;
         this._currentConfigFilledIn.outgoing.existingServerKey = existingKey;
       }
     }
 
-    getElementById('create_button').disabled = true;
+    document.getElementById('create_button').disabled = true;
     var me = this;
     if (!this._verifiedConfig)
       this.verifyConfig(function() // success
                         {
                           me.finish();
                         },
                         function(e) // failure
                         {
-                          getElementById('create_button').disabled = false;
+                          document.getElementById('create_button').disabled = false;
                         });
     else
       this.finish();
   },
 
   verifyConfig : function(successCallback, errorCallback)
   {
     var me = this;
@@ -775,32 +762,32 @@ EmailConfigWizard.prototype =
           errorCallback(e);
       });
   },
 
   finish : function()
   {
     gEmailWizardLogger.info("creating account in backend");
     this._currentConfigFilledIn.rememberPassword =
-      getElementById("remember_password").checked;
+      document.getElementById("remember_password").checked;
     createAccountInBackend(this._currentConfigFilledIn);
     window.close();
   },
 
   advancedSettings : function()
   {
     let config = this._currentConfigFilledIn ? this._currentConfigFilledIn.copy()
                                              : this.getUserConfig();
     // call this to set the password
     replaceVariables(config, this._realname, this._email,
                      this._password);
 
     gEmailWizardLogger.info("creating account in backend");
     config.rememberPassword =
-      getElementById("remember_password").checked;
+      document.getElementById("remember_password").checked;
     var newAccount = createAccountInBackend(config);
     var windowManager =
       Components.classes['@mozilla.org/appshell/window-mediator;1']
                 .getService(Components.interfaces.nsIWindowMediator);
 
     var existingAccountManager =
       windowManager.getMostRecentWindow("mailnews:accountmanager");
 
@@ -825,39 +812,42 @@ EmailConfigWizard.prototype =
     config.source = AccountConfig.kSourceGuess;
 
     // Did the user select one of the already configured SMTP servers from the
     // drop-down list? If so, use it.
     if (this._userPickedOutgoingServer)
     {
       config.outgoing.addThisServer = false;
       config.outgoing.existingServerKey =
-        getElementById("outgoing_server").selectedItem.value;
+        document.getElementById("outgoing_server").selectedItem.value;
       config.outgoing.existingServerLabel =
-        getElementById("outgoing_server").selectedItem.label;
+        document.getElementById("outgoing_server").selectedItem.label;
     }
     else
     {
-      config.outgoing.username = getElementById("username").value;
-      config.outgoing.hostname = getElementById("outgoing_server").value;
+      config.outgoing.username = document.getElementById("username").value;
+      config.outgoing.hostname =
+        document.getElementById("outgoing_server").value;
       config.outgoing.port =
-        sanitize.integerRange(getElementById("outgoing_port").value, 1,
+        sanitize.integerRange(document.getElementById("outgoing_port").value, 1,
                               kHighestPort);
-      config.outgoing.socketType = parseInt(getElementById("outgoing_security").value);
+      config.outgoing.socketType =
+        parseInt(document.getElementById("outgoing_security").value);
     }
-    config.incoming.username = getElementById("username").value;
-    config.incoming.hostname = getElementById("incoming_server").value;
+    config.incoming.username = document.getElementById("username").value;
+    config.incoming.hostname = document.getElementById("incoming_server").value;
     config.incoming.port =
-      sanitize.integerRange(getElementById("incoming_port").value, 1,
+      sanitize.integerRange(document.getElementById("incoming_port").value, 1,
                             kHighestPort);
     config.incoming.type =
-      getElementById("incoming_protocol").value == 1 ? "imap" : "pop3";
+      document.getElementById("incoming_protocol").value == 1 ? "imap" : "pop3";
     // type is a string, "imap" or "pop3", protocol is a protocol type.
     config.incoming.protocol = sanitize.translate(config.incoming.type, { "imap" : 0, "pop3" : 1});
-    config.incoming.socketType = parseInt(getElementById("incoming_security").value);
+    config.incoming.socketType =
+      parseInt(document.getElementById("incoming_security").value);
 
     return config;
   },
 
   _setIncomingStatus : function(state, details)
   {
     if (!details)
       details = "";
@@ -909,17 +899,17 @@ EmailConfigWizard.prototype =
     if (state == 'weak')
       this._outgoingState = 'done';
 
     this._setIconAndTooltip('outgoing_status', state, details);
   },
 
   _setIconAndTooltip : function(id, state, details)
   {
-    let icon = getElementById(id);
+    let icon = document.getElementById(id);
     icon.setAttribute("state", state);
     switch (state)
     {
       case "weak":
         icon.setAttribute("tooltip", "insecureserver-" + details);
         icon.setAttribute("popup", "insecureserver-" + details + "-panel");
         break;
       case "hidden":
@@ -950,42 +940,42 @@ EmailConfigWizard.prototype =
   /* Clears out the config details information, this is really only meant to be
    * called from the (Back) button.
    * XXX This can destroy user input where it might not be necessary
    */
   clearConfigDetails : function()
   {
     for (let i = 0; i < this._configDetailTextInputs.length; i++ )
     {
-      getElementById(this._configDetailTextInputs[i]).value = "";
+      document.getElementById(this._configDetailTextInputs[i]).value = "";
     }
 
     this._setIncomingStatus('hidden');
     this._setOutgoingStatus('hidden');
   },
 
   /* Setting the config details form so it can be edited.  We also disable
    * (and hide) the create button during this time because we don't know what
    * might have changed.  The function called from the button that restarts
    * the config check should be enabling the config button as needed.
    */
   editConfigDetails : function()
   {
     // Add the custom entry to the menulist, if it's not already there.
-    let menulist = getElementById("outgoing_server");
+    let menulist = document.getElementById("outgoing_server");
     if (this._smtpServerCount == menulist.itemCount) {
-      var hostname = getElementById("outgoing_server").value;
+      var hostname = document.getElementById("outgoing_server").value;
       let menuitem = menulist.insertItemAt(0, hostname, hostname);
       menuitem.hostname = hostname;
     }
 
     this._disableConfigDetails(false);
     this._setIncomingStatus('hidden');
     this._setOutgoingStatus('hidden');
-    getElementById('create_button').disabled = true;
+    document.getElementById('create_button').disabled = true;
     _hide("create_button");
     _hide("stop_button");
     _hide("edit_button");
     _show("go_button");
   },
 
   /* This _doesn't_ set create back to enabled, that needs to be done in a
    * config check.  Only showing the button.
@@ -1012,51 +1002,53 @@ EmailConfigWizard.prototype =
    * enable or disable each
    */
   _disableConfigDetails : function(disabled)
   {
     let formElements =
       this._configDetailTextInputs.concat(this._configDetailMenulists);
     for (let i = 0; i < formElements.length; i++)
     {
-      getElementById(formElements[i]).disabled = disabled;
+      document.getElementById(formElements[i]).disabled = disabled;
     }
   },
 
   /**
    * Updates a (probed) config to the user,
    * in the config details area
    *
    * @param config {AccountConfig} The config to present to user
    */
   updateConfig : function(config)
   {
     _show("advanced_settings");
     this._currentConfig = config;
     // if we have a username, set it.
     if (config.incoming.username)
     {
-      getElementById("username").value = config.incoming.username;
+      document.getElementById("username").value = config.incoming.username;
     }
     else
     {
       // XXX needs more thought
     }
 
     // incoming server
     if (config.incoming.hostname && config.incoming.hostname != -1)
     {
       /* -1 failure needs to be handled in the context of the failure
         * at this point all we know is there is no hostname, but not why
         * the error handling behaviour needs to be done above
         */
-      getElementById("incoming_server").value = config.incoming.hostname;
-      getElementById("incoming_port").value = config.incoming.port;
-      getElementById("incoming_security").value = config.incoming.socketType;
-      getElementById("incoming_protocol").value =
+      document.getElementById("incoming_server").value =
+        config.incoming.hostname;
+      document.getElementById("incoming_port").value = config.incoming.port;
+      document.getElementById("incoming_security").value =
+        config.incoming.socketType;
+      document.getElementById("incoming_protocol").value =
         sanitize.translate(config.incoming.type, { "imap" : 1, "pop3" : 2});
 
       if (config.incoming._inprogress)
       {
         this._setIncomingStatus('probing');
       }
       else
       {
@@ -1092,19 +1084,21 @@ EmailConfigWizard.prototype =
     if (config.outgoing.hostname && config.outgoing.hostname != -1)
     {
       /* -1 failure needs to be handled in the context of the failure
        * at this point all we know is there is no hostname, but not why.
        * The error handling behaviour needs to be done elsewhere
        */
       if (!gEmailConfigWizard._userPickedOutgoingServer)
       {
-        getElementById("outgoing_server").value = config.outgoing.hostname;
-        getElementById("outgoing_port").value = config.outgoing.port;
-        getElementById("outgoing_security").value = config.outgoing.socketType;
+        document.getElementById("outgoing_server").value =
+          config.outgoing.hostname;
+        document.getElementById("outgoing_port").value = config.outgoing.port;
+        document.getElementById("outgoing_security").value =
+          config.outgoing.socketType;
         _show("outgoing_port");
         _show("outgoing_security");
         if (config.outgoing._inprogress) {
           this._setOutgoingStatus('probing');
         }
         else
         {
           switch (config.outgoing.socketType)
@@ -1211,46 +1205,46 @@ EmailConfigWizard.prototype =
   {
     this._showStatusTitle(true, actionStrName);
     gEmailWizardLogger.warn("spinner stop\n");
   },
 
   // thought this would be needed other places, not likely though
   _hideSpinner : function(hidden)
   {
-    getElementById("config_spinner").hidden = hidden;
+    document.getElementById("config_spinner").hidden = hidden;
   },
 
   _showStatusTitle: function(success, msgName)
   {
     let msg;
     try {
       msg = msgName ? gStringsBundle.getString(msgName) : "";
     } catch(ex) {
       gEmailWizardLogger.error("missing string for " + msgName);
     }
 
     this._hideSpinner(success);
-    let title = getElementById("config_status_title");
+    let title = document.getElementById("config_status_title");
     title.hidden = false;
     title.textContent = msg;
     gEmailWizardLogger.info("show status title " + (success ? "success" : "failure") +
                             ", msg: " + msg);
   },
 
   _showStatus: function(msgName)
   {
     let msg;
     try {
       msg = msgName ? gStringsBundle.getString(msgName) : "";
     } catch(ex) {
       gEmailWizardLogger.error("missing string for " + msgName);
     }
 
-    let subtitle = getElementById("config_status_subtitle");
+    let subtitle = document.getElementById("config_status_subtitle");
     subtitle.hidden = false;
     subtitle.textContent = msg;
     gEmailWizardLogger.info("show status subtitle: " + msg);
   },
 
   _prefillConfig: function(initialConfig)
   {
     var emailsplit = this._email.split("@");
@@ -1318,41 +1312,42 @@ EmailConfigWizard.prototype =
     else
     {
       this._guessConfig(config.outgoing.hostname, config, "outgoing");
     }
   },
 
   clearError: function(which) {
     _hide(which);
-    getElementById(which).textContent = "";
+    document.getElementById(which).textContent = "";
   },
 
   setError: function(which, msg_name) {
     try {
       _show(which);
-      getElementById(which).textContent = gStringsBundle.getString(msg_name);
+      document.getElementById(which).textContent =
+        gStringsBundle.getString(msg_name);
     }
     catch(ex) {
       alertPrompt("missing error string", msg_name);
     }
   },
 
   onKeyDown : function(event)
   {
     let key = event.keyCode;
     if (key == 27) {
       this.onCancel();
       return true;
     }
-    if (key == 13 && !getElementById('create_button').hidden) {
+    if (key == 13 && !document.getElementById('create_button').hidden) {
       this.onOK();
       return true;
     }
-    if (key == 13 && !getElementById('next_button').hidden) {
+    if (key == 13 && !document.getElementById('next_button').hidden) {
       this.onNext();
       return true;
     }
     return false;
   },
 
   onWizardShutdown: function EmailConfigWizard_onWizardshutdown() {
     if (this._probeAbortable)