home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / aw-server.js < prev    next >
Text File  |  2001-10-02  |  5KB  |  146 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  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.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications 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.  * Seth Spitzer <sspitzer@netscape.com>
  23.  */
  24.  
  25. var gPrefsBundle;
  26.  
  27. function hostnameIsIllegal(hostname)
  28. {
  29.   // XXX TODO do a complete check.
  30.   // this only checks for illegal characters in the hostname
  31.   // but hostnames like "...." and "_" and ".111" will get by
  32.   // my test.  
  33.   var validChars = hostname.match(/[A-Za-z0-9.-]/g);
  34.   if (!validChars || (validChars.length != hostname.length)) {
  35.     return true;
  36.   }
  37.  
  38.   return false;
  39. }
  40.  
  41. function validate() 
  42. {
  43.   var servername = document.getElementById("hostname");
  44.   var smtpserver = document.getElementById("smtphostname");
  45.  
  46.   if ((servername && hostnameIsIllegal(servername.value)) ||
  47.       (smtpserver && hostnameIsIllegal(smtpserver.value))) {
  48.     var alertText = gPrefsBundle.getString("enterValidHostname");
  49.     window.alert(alertText);
  50.     return false;
  51.   }
  52.  
  53.   /* if this is for a server that doesn't require a username, 
  54.    * check if the account exists. 
  55.    * for other types, we check after the user provides the username (see aw-login.js)
  56.    */
  57.   var pageData = parent.GetPageData();
  58.   var serverType = parent.getCurrentServerType(pageData);
  59.   var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + serverType].getService(Components.interfaces.nsIMsgProtocolInfo);
  60.   if (!protocolinfo.requiresUsername) {
  61.     var userName = parent.getCurrentUserName(pageData);
  62.     var hostName = servername.value;
  63.  
  64.     if (parent.AccountExists(userName,hostName,serverType)) {
  65.       alertText = gPrefsBundle.getString("accountExists");
  66.       window.alert(alertText);
  67.       return false;
  68.     }
  69.   }
  70.  
  71.   return true;
  72. }
  73.  
  74. function onInit() {
  75.   // Server type selection (pop3 or imap) is for mail accounts only
  76.   var isMailAccount = parent.GetPageData().accounttype.mailaccount;
  77.   if (isMailAccount && isMailAccount.value) {
  78.     var serverTypeRadioGroup = document.getElementById("servertype");
  79.     /* 
  80.      * Check to see if the radiogroup has any value. If there is no
  81.      * value, this must be the first time user visting this page in the
  82.      * account setup process. So, the default is set to pop3. If there 
  83.      * is a value (it's used automatically), user has already visited 
  84.      * page and server type selection is done. Once user visits the page, 
  85.      * the server type value from then on will persist (whether the selection 
  86.      * came from the default or the user action).
  87.      */
  88.     if (!serverTypeRadioGroup.value) {
  89.       // Set pop3 server type as default selection
  90.       var pop3RadioItem = document.getElementById("pop3");
  91.       serverTypeRadioGroup.selectedItem = pop3RadioItem;
  92.     }
  93.   }
  94.  
  95.   gPrefsBundle = document.getElementById("bundle_prefs");
  96.   var smtpServer = parent.smtpService.defaultServer;
  97.  
  98.   // modify the value in the smtp display if we already have a 
  99.   // smtp server so that the single string displays the 
  100.   // name of the smtp server.
  101.   var smtpStatic = document.getElementById("smtpStaticText");
  102.   if (smtpServer && smtpServer.hostname && smtpStatic &&
  103.       smtpStatic.hasChildNodes()) {
  104.     var staticText = smtpStatic.firstChild.nodeValue;
  105.     staticText = staticText.replace(/@server_name@/, smtpServer.hostname);
  106.     while (smtpStatic.hasChildNodes())
  107.       smtpStatic.removeChild(smtpStatic.firstChild);
  108.     var staticTextNode = document.createTextNode(staticText);
  109.     smtpStatic.appendChild(staticTextNode);
  110.   }
  111.   
  112.   hideShowSmtpSettings(smtpServer);
  113. }
  114.  
  115. function hideShowSmtpSettings(smtpServer) {
  116.  
  117.   var noSmtpBox = document.getElementById("noSmtp");
  118.   var haveSmtpBox = document.getElementById("haveSmtp");
  119.  
  120.   var boxToHide;
  121.   var boxToShow;
  122.   
  123.   if (smtpServer && smtpServer.hostname && smtpServer.redirectorType == null 
  124.       && smtpServer.hostname != "") {
  125.     // we have a hostname, so show the static text and 
  126.     // store the value of the default smtp server in the textbox.
  127.     var smtpTextBox = document.getElementById("smtphostname");
  128.     if (smtpTextBox && smtpTextBox.value == "" && smtpServer.hostname)
  129.       smtpTextBox.value = smtpServer.hostname;
  130.     boxToShow = haveSmtpBox;
  131.     boxToHide = noSmtpBox;
  132.   } else {
  133.     // no default hostname yet
  134.     boxToShow = noSmtpBox;
  135.     boxToHide = haveSmtpBox;
  136.   }
  137.  
  138.   if (boxToHide)
  139.     boxToHide.setAttribute("hidden", "true");
  140.  
  141.   if (boxToShow)
  142.     boxToShow.removeAttribute("hidden");
  143.  
  144.  
  145. }
  146.