home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / messenger.jar / content / messenger / am-server.js < prev    next >
Text File  |  2001-02-14  |  6KB  |  179 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-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  */
  20.  
  21. var stringBundle;
  22.  
  23. function onInit() {
  24.     stringBundle = srGetStrBundle("chrome://messenger/locale/messenger.properties");
  25.     initServerType();
  26. }
  27.  
  28. function onPreInit(account, accountValues)
  29. {
  30.     var type = parent.getAccountValue(account, accountValues, "server", "type");
  31.     
  32.     hideShowControls(type);
  33. }
  34.  
  35.  
  36. function initServerType() {
  37.   var serverType = document.getElementById("server.type").getAttribute("value");
  38.   
  39.   var verboseName;
  40.  
  41.   var propertyName = "serverType-" + serverType;
  42.  
  43.   verboseName = stringBundle.GetStringFromName(propertyName);
  44.  
  45.   var hostname = document.getElementById("server.hostName").getAttribute("value");
  46.   var username = document.getElementById("server.username").getAttribute("value");
  47.  
  48.   setDivText("servertype.verbose", verboseName);
  49.   setDivText("servername.verbose", hostname);
  50.   setDivText("username.verbose", username);
  51.  
  52. }
  53.  
  54. function hideShowControls(serverType)
  55. {
  56.     var controls = document.getElementsByAttribute("wsm_persist", "true");
  57.     var len = controls.length;
  58.     for (var i=0; i<len; i++) {
  59.         var control = controls[i];
  60.         var controlName = control.id;
  61.         if (!controlName) continue;
  62.         var controlNameSplit = controlName.split(".");
  63.         
  64.         if (controlNameSplit.length < 2) continue;
  65.         var controlType = controlNameSplit[0];
  66.  
  67.         // skip generic server/identity things
  68.         var hideFor = control.getAttribute("hidefor");
  69.         if ((!hideFor || hideFor == "") &&
  70.             (controlType == "server" ||
  71.              controlType == "identity")) continue;
  72.  
  73.         var box = getEnclosingContainer(control);
  74.  
  75.         if (!box) continue;
  76.  
  77.         // hide unsupported server type
  78.  
  79.         // adding support for hiding multiple server types using hideFor="server1,server2"
  80.         var hideForBool = false;
  81.         var hideForTokens = hideFor.split(",");
  82.         for (j = 0; j < hideForTokens.length; j++) {
  83.             if (hideForTokens[j] == serverType) {
  84.                 hideForBool = true;
  85.                 break;
  86.             }
  87.         }
  88.  
  89.         if ((controlType != "server" &&
  90.              controlType != "identity" &&
  91.              controlType != serverType) ||
  92.             hideForBool) {
  93.             box.setAttribute("hidden", "true");
  94.         }
  95.         else {
  96.             box.removeAttribute("hidden");
  97.         }
  98.     }
  99.  
  100.     var serverPrefContainer = document.getElementById("serverPrefContainer");
  101.     if (serverPrefContainer)
  102.         serverPrefContainer.removeAttribute("hidden");
  103. }
  104.  
  105.  
  106. function setDivText(divname, value) {
  107.     var div = document.getElementById(divname);
  108.     if (!div) return;
  109.     div.setAttribute("value", value);
  110. }
  111.  
  112.  
  113. function openImapAdvanced()
  114. {
  115.     var imapServer = getImapServer();
  116.     dump("Opening dialog..\n");
  117.     window.openDialog("chrome://messenger/content/am-imap-advanced.xul",
  118.                       "_blank",
  119.                       "chrome,modal,titlebar", imapServer);
  120.  
  121.     saveServerLocally(imapServer);
  122. }
  123.  
  124. function getImapServer() {
  125.     var imapServer = new Array;
  126.  
  127.     imapServer.dualUseFolders = document.getElementById("imap.dualUseFolders").checked
  128.  
  129.     imapServer.usingSubscription = document.getElementById("imap.usingSubscription").checked;
  130.  
  131.     // string prefs
  132.     imapServer.personalNamespace = document.getElementById("imap.personalNamespace").getAttribute("value");
  133.     imapServer.publicNamespace = document.getElementById("imap.publicNamespace").getAttribute("value");
  134.     imapServer.serverDirectory = document.getElementById("imap.serverDirectory").getAttribute("value");
  135.     imapServer.otherUsersNamespace = document.getElementById("imap.otherUsersNamespace").getAttribute("value");
  136.  
  137.     imapServer.overrideNamespaces = document.getElementById("imap.overrideNamespaces").checked;
  138.     return imapServer;
  139. }
  140.  
  141. function saveServerLocally(imapServer)
  142. {
  143.     document.getElementById("imap.dualUseFolders").checked = imapServer.dualUseFolders;
  144.     document.getElementById("imap.usingSubscription").checked = imapServer.usingSubscription;
  145.  
  146.     // string prefs
  147.     document.getElementById("imap.personalNamespace").setAttribute("value", imapServer.personalNamespace);
  148.     document.getElementById("imap.publicNamespace").setAttribute("value", imapServer.publicNamespace);
  149.     document.getElementById("imap.serverDirectory").setAttribute("value", imapServer.serverDirectory);
  150.     document.getElementById("imap.otherUsersNamespace").setAttribute("value", imapServer.otherUsersNamespace);
  151.  
  152.     document.getElementById("imap.overrideNamespaces").checked = imapServer.overrideNamespaces;
  153.  
  154. }
  155.  
  156. function getEnclosingContainer(startNode) {
  157.  
  158.     var parent = startNode;
  159.     var box;
  160.     
  161.     while (parent && parent != document) {
  162.  
  163.         var isContainer =
  164.             (parent.getAttribute("iscontrolcontainer") == "true");
  165.           
  166.         // remember the FIRST container we encounter, or the first
  167.         // controlcontainer
  168.         if (!box || isContainer)
  169.             box=parent;
  170.         
  171.         // break out with a controlcontainer
  172.         if (isContainer)
  173.             break;
  174.         parent = parent.parentNode;
  175.     }
  176.     
  177.     return box;
  178. }
  179.