home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / mozapps / autofill / SetAutoLockTime.js < prev    next >
Text File  |  2005-07-29  |  6KB  |  185 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Netscape Public License
  5.  * Version 1.1 (the "License"); you may not use this file except in
  6.  * compliance with the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/NPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla Communicator client code.
  15.  *
  16.  * The Initial Developer of the Original Code is 
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 1998
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *  Alec Flett  <alecf@netscape.com>
  23.  *  Ben Goodger <ben@netscape.com>
  24.  *  Blake Ross  <blakeross@telocity.com>
  25.  *  Joe Hewitt <hewitt@netscape.com>
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  29.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the NPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the NPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41.   
  42. function setLabelForNode(aNode, aLabel, aIsLabelFlag)
  43. {
  44.   // This is for labels with possible accesskeys
  45.   var accessKeyIndex;
  46.   if (/^\&[^\&]/.test(aLabel)) { // access key is at the start
  47.    accessKeyIndex = 0;
  48.   } else {
  49.     accessKeyIndex = aLabel.search(/[^\&]\&[^\&]/) + 1;
  50.     if (accessKeyIndex == 0) {
  51.       accessKeyIndex = -1; // magic value for no accesskey
  52.     }
  53.   }
  54.  
  55.   // If a character has an & before it, then it should become an accesskey
  56.   if (accessKeyIndex >= 0 && accessKeyIndex < aLabel.length - 1) {
  57.     // This will also cause the accesskey attribute to be set via xbl
  58.     aNode.accessKey = aLabel.charAt(accessKeyIndex + 1);
  59.     // Set the label to the string without the &
  60.     aLabel = aLabel.substr(0, accessKeyIndex) + 
  61.              aLabel.substr(accessKeyIndex + 1);
  62.   }
  63.   aLabel = aLabel.replace(/\&\&/g, "&");
  64.   if (aIsLabelFlag) {    // Set text for <label> element
  65.     aNode.setAttribute("value", aLabel);
  66.   } else {    // Set text for other xul elements
  67.     aNode.label = aLabel;
  68.   }
  69. }
  70.  
  71. function setAutolockOnLoad()
  72. {
  73.   
  74.   dump("*************in setAutolockOnLoad*************");
  75.   
  76.   //get preferences
  77.   var prefs = GetPreferencesInterface();
  78.   var rbGroupElement = document.getElementById("radiogroup1");
  79.     
  80.   if (prefs != null)
  81.   {            
  82.       var selectedRadio = prefs.getCharPref("browser.preferences.autolock");
  83.       var selectedTime = prefs.getCharPref("browser.preferences.autolockTime");
  84.       var selectedTimeUnit = prefs.getCharPref("browser.preferences.autolockTimeUnit");
  85.       dump("*******The selected radiobutton is" + selectedRadio);
  86.       dump("*******The selected time is" + selectedTime);
  87.       dump("*******The selected time unit is" + selectedTimeUnit);
  88.       
  89.       if(selectedRadio == "0")
  90.       {
  91.           rbGroupElement.selectedIndex = 0;
  92.           document.getElementById("timeTextbox").value = selectedTime;
  93.           if(selectedTimeUnit == "0")
  94.               document.getElementById("dropdownMenulist").selectedIndex = 0;
  95.           else
  96.               document.getElementById("dropdownMenulist").selectedIndex = 1;
  97.       }
  98.       else
  99.           rbGroupElement.selectedIndex = 1;
  100.   }
  101.   else
  102.   {
  103.       
  104.       document.getElementById("timeTextbox").disabled = true;
  105.       document.getElementById("dropdownMenulist").disabled = true;
  106.       rbGroupElement.selectedIndex = 1;
  107.   }
  108.   
  109.   
  110.  
  111.   
  112. }
  113.  
  114. function commonDialogReenableButtons()
  115. {
  116.   document.documentElement.getButton("accept").disabled = false;
  117.   document.documentElement.getButton("extra1").disabled = false;
  118.   document.documentElement.getButton("extra2").disabled = false;
  119. }
  120.  
  121. function setElementText(aElementID, aValue, aChildNodeFlag)
  122. {
  123.   var element = document.getElementById(aElementID);
  124.   if (!aChildNodeFlag && element) {
  125.     setLabelForNode(element, aValue, true);
  126.   } else if (aChildNodeFlag && element) {
  127.     element.appendChild(document.createTextNode(aValue));
  128.   }
  129. }
  130.  
  131. function GetPreferencesInterface()
  132. {
  133.     return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  134. }
  135.  
  136.  
  137. function setCheckbox(aChkMsg, aChkValue)
  138. {
  139.   if (aChkMsg) {
  140.     // XXX Would love to use hidden instead of collapsed, but the checkbox
  141.     // fails to size itself properly when I do this.
  142.     document.getElementById("checkboxContainer").removeAttribute("collapsed");
  143.     
  144.     var checkboxElement = document.getElementById("checkbox");
  145.     setLabelForNode(checkboxElement, aChkMsg);
  146.     checkboxElement.checked = aChkValue > 0;
  147.   }
  148. }
  149.  
  150. function unHideElementById(aElementID)
  151. {
  152.   var element = document.getElementById(aElementID);
  153.   element.hidden = false;
  154. }
  155.  
  156. function hideElementById(aElementID)
  157. {
  158.   var element = document.getElementById(aElementID)
  159.   element.hidden = true;
  160. }
  161.  
  162. function isVisible(aElementId)
  163. {
  164.   return document.getElementById(aElementId).hasAttribute("hidden");
  165. }
  166.  
  167. function setAutolockOnAccept()
  168. {
  169.     var prefs = GetPreferencesInterface();
  170.     if (prefs)
  171.     {
  172.         if(document.getElementById("radio0").selected)
  173.         {
  174.             //save prefs
  175.             prefs.setCharPref("browser.preferences.autolock", "0");
  176.             prefs.setCharPref("browser.preferences.autolockTime", document.getElementById("timeTextbox").value);
  177.             prefs.setCharPref("browser.preferences.autolockTimeUnit", document.getElementById("dropdownMenulist").selectedItem.value);
  178.         }
  179.         else
  180.             prefs.setCharPref("browser.preferences.autolock", "1");
  181.     }
  182.             
  183.     
  184.   return true;
  185. }