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

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-2001 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * 
  20.  * Contributors:
  21.  *   alecf@netscape.com
  22.  *   sspitzer@netscape.com
  23.  *   racham@netscape.com
  24.  *   hwaara@chello.se
  25.  */
  26.  
  27. function onInit() 
  28. {
  29.     initServerType();
  30.  
  31.     setupBiffUI();
  32.     setupMailOnServerUI();
  33.  
  34.     // disable for bug #14295.  Also see bug 104253 and 103181 for why the elements
  35.     // are being disabled here.
  36.     var disabledElem = document.getElementById("server.username");
  37.     disabledElem.setAttribute("disabled","true");
  38.     disabledElem = document.getElementById("server.hostName");
  39.     disabledElem.setAttribute("disabled","true");
  40. }
  41.  
  42. function onPreInit(account, accountValues)
  43. {
  44.     var type = parent.getAccountValue(account, accountValues, "server", "type");
  45.     
  46.     hideShowControls(type);
  47. }
  48.  
  49.  
  50. function initServerType() {
  51.   var serverType = document.getElementById("server.type").getAttribute("value");
  52.   
  53.   var propertyName = "serverType-" + serverType;
  54.  
  55.   var messengerBundle = document.getElementById("bundle_messenger");
  56.   var verboseName = messengerBundle.getString(propertyName);
  57.  
  58.   setDivText("servertype.verbose", verboseName);
  59. }
  60.  
  61. function hideShowControls(serverType)
  62. {
  63.     var controls = document.getElementsByAttribute("hidable", "true");
  64.     var len = controls.length;
  65.     for (var i=0; i<len; i++) {
  66.         var control = controls[i];
  67.  
  68.         var hideFor = control.getAttribute("hidefor");
  69.         if (!hideFor)
  70.             throw "this should not happen, things that are hidable should have hidefor set";
  71.  
  72.         var box = getEnclosingContainer(control);
  73.  
  74.         if (!box)
  75.             throw "this should not happen, things that are hidable should be in a box";
  76.  
  77.         // hide unsupported server type
  78.         // adding support for hiding multiple server types using hideFor="server1,server2"
  79.         var hideForBool = false;
  80.         var hideForTokens = hideFor.split(",");
  81.         for (var j = 0; j < hideForTokens.length; j++) {
  82.             if (hideForTokens[j] == serverType) {
  83.                 hideForBool = true;
  84.                 break;
  85.             }
  86.         }
  87.  
  88.         if (hideForBool) {
  89.             box.setAttribute("hidden", "true");
  90.         }
  91.         else {
  92.             box.removeAttribute("hidden");
  93.         }
  94.     }
  95. }
  96.  
  97.  
  98. function setDivText(divname, value) {
  99.     var div = document.getElementById(divname);
  100.     if (!div) return;
  101.     div.setAttribute("value", value);
  102. }
  103.  
  104.  
  105. function openImapAdvanced()
  106. {
  107.     var imapServer = getImapServer();
  108.     dump("Opening dialog..\n");
  109.     window.openDialog("chrome://messenger/content/am-imap-advanced.xul",
  110.                       "_blank",
  111.                       "chrome,modal,titlebar", imapServer);
  112.  
  113.     saveServerLocally(imapServer);
  114. }
  115.  
  116. function getImapServer() {
  117.     var imapServer = new Array;
  118.  
  119.     imapServer.dualUseFolders = document.getElementById("imap.dualUseFolders").checked
  120.  
  121.     imapServer.usingSubscription = document.getElementById("imap.usingSubscription").checked;
  122.  
  123.     // string prefs
  124.     imapServer.personalNamespace = document.getElementById("imap.personalNamespace").getAttribute("value");
  125.     imapServer.publicNamespace = document.getElementById("imap.publicNamespace").getAttribute("value");
  126.     imapServer.serverDirectory = document.getElementById("imap.serverDirectory").getAttribute("value");
  127.     imapServer.otherUsersNamespace = document.getElementById("imap.otherUsersNamespace").getAttribute("value");
  128.  
  129.     imapServer.overrideNamespaces = document.getElementById("imap.overrideNamespaces").checked;
  130.     return imapServer;
  131. }
  132.  
  133. function saveServerLocally(imapServer)
  134. {
  135.     document.getElementById("imap.dualUseFolders").checked = imapServer.dualUseFolders;
  136.     document.getElementById("imap.usingSubscription").checked = imapServer.usingSubscription;
  137.  
  138.     // string prefs
  139.     document.getElementById("imap.personalNamespace").setAttribute("value", imapServer.personalNamespace);
  140.     document.getElementById("imap.publicNamespace").setAttribute("value", imapServer.publicNamespace);
  141.     document.getElementById("imap.serverDirectory").setAttribute("value", imapServer.serverDirectory);
  142.     document.getElementById("imap.otherUsersNamespace").setAttribute("value", imapServer.otherUsersNamespace);
  143.  
  144.     document.getElementById("imap.overrideNamespaces").checked = imapServer.overrideNamespaces;
  145.  
  146. }
  147.  
  148. function getEnclosingContainer(startNode) {
  149.  
  150.     var parent = startNode;
  151.     var box;
  152.     
  153.     while (parent && parent != document) {
  154.  
  155.         var isContainer =
  156.             (parent.getAttribute("iscontrolcontainer") == "true");
  157.           
  158.         // remember the FIRST container we encounter, or the first
  159.         // controlcontainer
  160.         if (!box || isContainer)
  161.             box=parent;
  162.         
  163.         // break out with a controlcontainer
  164.         if (isContainer)
  165.             break;
  166.         parent = parent.parentNode;
  167.     }
  168.     
  169.     return box;
  170. }
  171.  
  172. function secureSelect() {
  173.     var serverType   = document.getElementById("server.type").getAttribute("value");
  174.     var protocolInfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + serverType].getService(Components.interfaces.nsIMsgProtocolInfo);
  175.  
  176.     // If the secure option is checked, protocolInfo returns a secure port value
  177.     // for the corresponding protocol. Otherwise, a default value is returned.
  178.     if (document.getElementById("server.isSecure").checked)
  179.         document.getElementById("server.port").value = protocolInfo.getDefaultServerPort(true);
  180.     else
  181.         document.getElementById("server.port").value = protocolInfo.getDefaultServerPort(false);
  182. }
  183.  
  184. function setupBiffUI()
  185.    var broadcaster = document.getElementById("broadcaster_doBiff");
  186.  
  187.    var dobiff = document.getElementById("server.doBiff");
  188.    var checked = dobiff.checked;
  189.    var locked = getAccountValueIsLocked(dobiff);
  190.  
  191.    if (checked)
  192.      broadcaster.removeAttribute("disabled");
  193.    else
  194.      broadcaster.setAttribute("disabled", "true");
  195.    if (locked)
  196.      broadcaster.setAttribute("disabled","true");
  197. }
  198.  
  199. function setupMailOnServerUI()
  200.    var checked = document.getElementById("pop3.leaveMessagesOnServer").checked;
  201.    var locked = getAccountValueIsLocked(document.getElementById("pop3.leaveMessagesOnServer"));
  202.    document.getElementById("pop3.deleteMailLeftOnServer").disabled = locked || !checked ;
  203. }
  204.  
  205.