home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / smtpEditOverlay.js < prev    next >
Text File  |  2001-05-17  |  4KB  |  115 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape Communications
  16.  * Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Alec Flett <alecf@netscape.com>
  22.  *   Henrik Gemal <gemal@gemal.dk>
  23.  */
  24.  
  25. // be real hacky with document.getElementById until document.controls works
  26. // with the new XUL widgets
  27.  
  28. var gSmtpUsername;
  29. var gSmtpUsernameLabel;
  30. var gSmtpHostname;
  31. var gSmtpUseUsername;
  32. var gSmtpAuthMethod;
  33. var gSmtpTrySSL;
  34.  
  35. var gSavedUsername="";
  36.  
  37. function initSmtpSettings(server) {
  38.  
  39.     gSmtpUsername = document.getElementById("smtp.username");
  40.     gSmtpUsernameLabel = document.getElementById("smtpusernamelabel");
  41.     gSmtpHostname = document.getElementById("smtp.hostname");
  42.     gSmtpUseUsername = document.getElementById("smtp.useUsername");
  43.     gSmtpAuthMethod = document.getElementById("smtp.authMethod");
  44.     gSmtpTrySSL = document.getElementById("smtp.trySSL");
  45.  
  46.     if (server) {
  47.         gSmtpHostname.value = server.hostname;
  48.         gSmtpUsername.value = server.username;
  49.         gSmtpAuthMethod.setAttribute("value", server.authMethod);
  50.  
  51.         var elements = gSmtpTrySSL.getElementsByAttribute("value", server.trySSL);
  52.         if (elements.length == 0)
  53.             elements = gSmtpTrySSL.getElementsByAttribute("value", "1");
  54.         gSmtpTrySSL.selectedItem = elements[0];
  55.     } else {
  56.         gSmtpAuthMethod.setAttribute("value", "1");
  57.         gSmtpTrySSL.selectedItem =
  58.             gSmtpTrySSL.getElementsByAttribute("value", "1")[0];
  59.     }
  60.  
  61.     if (gSmtpAuthMethod.getAttribute("value") == "1")
  62.         gSmtpUseUsername.checked = true;
  63.  
  64.     //dump("gSmtpAuthMethod = <" + gSmtpAuthMethod.localName + ">\n");
  65.     //dump("gSmtpAuthMethod.value = " + gSmtpAuthMethod.getAttribute("value") + "\n");
  66.  
  67.     onUseUsername(gSmtpUseUsername, false);
  68.     updateControls();
  69. }
  70.  
  71. function saveSmtpSettings(server)
  72. {
  73.  
  74.     if (gSmtpUseUsername.checked)
  75.         gSmtpAuthMethod.setAttribute("value", "1");
  76.     else
  77.         gSmtpAuthMethod.setAttribute("value", "0");
  78.  
  79.     //dump("Saving to " + server + "\n");
  80.     if (server) {
  81.         server.hostname = gSmtpHostname.value;
  82.         server.authMethod = (gSmtpUseUsername.checked ? 1 : 0);
  83.         //dump("Saved authmethod = " + server.authMethod +
  84.         //     " but checked = " + gSmtpUseUsername.checked + "\n");
  85.         server.username = gSmtpUsername.value;
  86.         server.trySSL = gSmtpTrySSL.selectedItem.value;
  87.     }
  88. }
  89.  
  90. function onUseUsername(checkbox, dofocus)
  91. {
  92.     if (checkbox.checked) {
  93.         // not only do we enable the elements when the check box is checked,
  94.         // but we also make sure that it's not disabled (ie locked) as well.
  95.         if (!checkbox.disabled) {
  96.             gSmtpUsername.removeAttribute("disabled");
  97.             gSmtpUsernameLabel.removeAttribute("disabled");
  98.         }
  99.         if (dofocus)
  100.             gSmtpUsername.focus();
  101.         if (gSavedUsername && gSavedUsername != "")
  102.             gSmtpUsername.value = gSavedUsername;
  103.     } else {
  104.         gSavedUsername = gSmtpUsername.value;
  105.         gSmtpUsername.value = "";
  106.         gSmtpUsername.setAttribute("disabled", "true");
  107.         gSmtpUsernameLabel.setAttribute("disabled", "true");
  108.     }
  109. }
  110.  
  111. function updateControls() {
  112.     if (gSmtpTrySSL.disabled)  // see bug 70033 on why this is necessary for radiobuttons
  113.         gSmtpTrySSL.disabled = gSmtpTrySSL.disabled;
  114. }
  115.