home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / NETSCAPE / CCK / ASE.Z / isetting.js < prev    next >
Encoding:
Text File  |  1997-08-21  |  15.1 KB  |  386 lines

  1. <!--  to hide script contents from old browsers
  2.  
  3.  
  4. //    THIS IS THE API for functions you will want to access from outside of this javascript file:
  5. //    you probably want to use these functions in the OnLoad and OnUnload event handlers of your htmls files,
  6. //    in order     (1) Get all the appropriate information from the config files and set the appropriate form fields on load
  7. //    and            (2)    To write the data from your form fields back out to the config files on unload    
  8.  
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. //    these functions interface with the config files (e.g., ACCTSET.INI)
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12.  
  13. //    function GetNameValuePair(fileName, sectionName, flagName)            //    looks in the file fileName for a line that looks like "flagName=value"
  14.                                                                         //    under the section called "[sectionName]".  If it finds one, returns value.
  15.                                                                         
  16. //    function SetNameValuePair(fileName, sectionName, flagName, data)    //    in the file fileName, writes a line that looks like "flagname=data" under
  17.                                                                         //    the section called "[sectionName]" -will create the file and/or section name
  18.                                                                         //    if necessary    
  19.  
  20. //    function getFileListFromConfigFolder(fileSuffix)                    //    returns a list of files with the specified suffix that live
  21.                                                                         //    in the Config Folder
  22.                                                                         
  23.                                                                         
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. //    these functions set the elements of your form    (all return nothing)
  26. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27. //    function setCheckBox(formName, boxName, inValue)    //    if inValue = 0 sets checkbox to off, else to on
  28. //    function setRadio(formName, radioName, inValue)        //    inValue is yes or no - yes is first, no is second radio.  If inValue is a number, sets
  29.                                                         //    the inValueth radio with that name to on.  (0 < inValue < 33, jsut for sanity checking0
  30. //    function setText(formName, textFieldName, inValue)    //    sets the specified textField to the input value
  31.  
  32. //    function setCardTypes(formName, cardTypesString)        // cardTypesString is a string of the form "AX,MC,DC,VI" as per ACCTSET.INI requirements, this sets
  33.                                                 // four checkboxes whose names MUST be: "AX", "MC", "DC", and "VI"
  34. //    function fillSelectListWithConfigFiles(formName, selectListName, fileSuffix, offerNew)    // finds all files with the suffix fileSuffix
  35.                                                                                     // (should look like ".NCI") and fills in the specified list
  36.                                                                                     // this is used by the following two functions
  37.                                                                                     // if offerNew is true, an option will be provided with name
  38.                                                                                     // "New Configuration" and value "_new_"
  39.  
  40. //    function fillNCIFileList(formName, selectListName)    //will fill the specified select list with the names of all NCI files in the Config folder
  41. //    function fillIASFileList(formName, selectListName)    //will fill the specified select list with the names of all IAS files in the Config folder
  42.                                                         //selects RegServ.SR if that file exists
  43. //    function setSelectList(formName, selectListName, inValue)    // sets the selectlist to select the option whose text is inValue, if it exists
  44.                                                                 // used internally to set the value of the NCI file list, for example
  45.                                                                 
  46. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  47. //    these functions get the values of elements of your form and return text suitable for writing into Config files (all return strings)
  48. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. //    function getRadio(formName, radioName)            //     returns "yes" if first radio is selected, "no" if second is selected, else returns
  50.                                                     //    index of selected radio (-1 if none selected)
  51. //    function getText(formName, textFieldName)        //    returns the text inside a text field
  52. //    function getCheckBox(formName, selectListName)    //    returns true if checkbox is checked, false if not
  53. //    function getSelectListSelection(formName, selectListName)
  54.  
  55. ////////these are specific functions which get specfic information using the above functions//////////////////
  56. //    function getCardTypes(formName)        // returns a string of the form "AX,MC,DC,VI", based on the values of the four checkboxes in
  57.                                         // the specified form, whose names MUST be: "AX", "MC", "DC", and "VI"
  58.                                         
  59. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. //    Other Functions
  61. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62.  
  63. //function yesNoToNoYes(inValue)    // if inValue == "yes" returns "no".  if invalue == "no" returns yes, else nothing
  64.  
  65. //function getAcctSetupFilename()    //returns the name of ACCTSET.INI
  66.  
  67. //function debug(theString)    // writes the string to the java console, using the setUpPlugin
  68.  
  69. //these should be overriden if this file is included from within another javascript file
  70. //    function checkData()        // this should return true in most cases, you can add checks in here for determining if any necessary fields
  71.                                 // have been left empty, etc. - if it returns false, account setup's global navigation won't proceed when next is clicked
  72. //    function getAcctSetFlags()    // this is an example of a function that would be used as an onLoad handler in a file where the form name is
  73.                                 // "acctsetForm", and it has form elements for all the flags in ACCTSET.INI 
  74. //    function saveAcctSetFlags()    // this is an example of a function that would be used as an onUnLoad handler in a file where the form name is
  75.                                 // "acctsetForm", and it has form elements for all the flags in ACCTSET.INI 
  76.  
  77. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. //    LOCATION DEPENDENT FUNCTIONS
  79. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. // The following functions are dependent on the LOCATION OF THIS FILE and the LOCATION OF THE globals.js FILE
  81. //    actually, they are really dependent on the part of the frameset heirarchy in which this file is included
  82. //    right now we assume it is included two framesets deep, and the outermost frameset contains a frame called "globals", 
  83. //    which includes the "globals.js" file which is the meat of the account setup javascript universe - it interfaces with the plugin
  84. //  SO, if the heirarchy changes, the path of the "globals" frame should be updated
  85.  
  86. //    function getGlobalsLocation()
  87.  
  88.  
  89. //this is the function that determines where access to the globals is
  90. //from the document that is including this file.
  91. //it's made out of ugly hacks and ricotta cheese
  92. function getGlobalsLocation()
  93. {
  94.  
  95.         var loc = "top.globals";
  96.         
  97.     return loc;
  98. }
  99.  
  100.  
  101.  
  102. function getAcctSetupFilename()
  103. {
  104.     return     "ACCTSET.INI";
  105. }
  106.  
  107. function completeConfigFilePath(inFileName)
  108. {
  109.     var outFileName = (top.globals.getConfigFolder(top.globals) + inFileName);
  110.     return outFileName;
  111. }
  112.  
  113.  
  114. ///WARNING THE LOCATION OF THE GLOBALS IS HARDCODED IN THIS FCN - it can only be accessed by children windows
  115. function saveNewConfigFile(fileName, inValue, doPrompt)
  116. {
  117.  
  118.     // Request privilege
  119.     netscape.security.PrivilegeManager.enablePrivilege("AccountSetup");
  120.  
  121.     if ((doPrompt != true) && (doPrompt != false))
  122.         doPrompt = false;    //should we really assume false?
  123.     
  124.     if ((fileName != null) && (fileName != ""))
  125.     {
  126.         var cFileName = completeConfigFilePath(fileName);
  127.         
  128.         if ((cFileName != null) && (inValue != null) && (cFileName != "") && (inValue != ""))
  129.             top.globals.document.setupPlugin.SaveTextToFile(cFileName, inValue, doPrompt);
  130.         
  131.     }
  132. }
  133.  
  134. function debug(theString)
  135. {
  136.     top.globals.debug(theString);
  137. }
  138.  
  139.  
  140. function GetNameValuePair(inFileName, sectionName, flagName)
  141. {
  142.  
  143.     // Request privilege
  144.     netscape.security.PrivilegeManager.enablePrivilege("AccountSetup");
  145.     
  146.     var fileName = completeConfigFilePath(inFileName);
  147.     
  148.     var data = top.globals.document.setupPlugin.GetNameValuePair(fileName, sectionName, flagName);
  149.     
  150.     
  151.     debug("\tGetNameValuePair: (" + inFileName + ") [" +sectionName+ "] " +flagName+ "=" + data);
  152.     return data;
  153. }
  154.  
  155. function SetNameValuePair(inFileName, section, variable, data)
  156. {
  157.  
  158.     // Request privilege
  159.     netscape.security.PrivilegeManager.enablePrivilege("AccountSetup");
  160.  
  161.     var fileName = completeConfigFilePath(inFileName);
  162.  
  163.     top.globals.document.setupPlugin.SetNameValuePair(fileName, section, variable, data);
  164.     debug("\tSetNameValuePair: (" + fileName + ")[" +section+ "] " +variable+ "=" + data);
  165. }
  166.  
  167. function getFileListFromConfigFolder(fileSuffix)
  168. {
  169.  
  170.     // Request privilege
  171.     netscape.security.PrivilegeManager.enablePrivilege("AccountSetup");
  172.  
  173.     var pathName = top.globals.getConfigFolder(top.globals);
  174.     var theList = top.globals.document.setupPlugin.GetFolderContents(pathName, fileSuffix);
  175.     return theList;
  176. }
  177.  
  178. function fillSelectListWithConfigFiles(formName, selectListName, fileSuffix, offerNew)
  179. {
  180.     var curConfigName = "";
  181.     var curConfigDescription = "";
  182.  
  183.     //blank out old list
  184.     for (var i = (parent.tabs.tabbody.document[formName][selectListName].length -1); i >= 0 ; i--)
  185.     {
  186.         parent.tabs.tabbody.document[formName][selectListName].options[i] = null;
  187.     }    
  188.     
  189.     //make a blank so the user can choose nothing
  190.     parent.tabs.tabbody.document[formName][selectListName].options[0] = new Option("< None Selected >","",false, false); 
  191.     
  192.     //Only offer a new if we said so
  193.     if (offerNew == true)
  194.         parent.tabs.tabbody.document[formName][selectListName].options[1] = new Option("< New Configuration >","_new_",false, false); 
  195.  
  196.     // Get a list of the files in the Config folder
  197.     fileList = getFileListFromConfigFolder(fileSuffix);
  198.     
  199.     //debug( "filelist: " + fileList);
  200.     
  201.     if (fileList != null)    {
  202.         for (var i=0; i<fileList.length; i++)    {
  203.                 curConfigName             = GetNameValuePair(fileList[i], "Dial-In Configuration", "SiteName");
  204.                 curConfigDescription     = GetNameValuePair(fileList[i], "Dial-In Configuration", "Description");
  205.  
  206.                 if ((curConfigName != null)  && (curConfigName != ""))
  207.                     parent.tabs.tabbody.document[formName][selectListName].options[parent.tabs.tabbody.document[formName][selectListName].length] = new Option(curConfigName,fileList[i], false, false);
  208.                 else if ((curConfigDescription != null) && (curConfigDescription != ""))
  209.                     parent.tabs.tabbody.document[formName][selectListName].options[parent.tabs.tabbody.document[formName][selectListName].length] = new Option(curConfigDescription,fileList[i], false, false);
  210.                 else
  211.                     parent.tabs.tabbody.document[formName][selectListName].options[parent.tabs.tabbody.document[formName][selectListName].length] = new Option(fileList[i],fileList[i], false, false);
  212.                     
  213.             }
  214.         }
  215. }
  216.  
  217.  
  218. //this is a helper function that converts "yes" to 0 and "no" to 1 - but leaves integers alone
  219. function ynToZeroOne(inValue)
  220. {
  221.     var ynValue = new String(inValue);
  222.     var intValue = -1;
  223.     
  224.     if (ynValue == "yes") 
  225.     {
  226.         intValue = 0;    
  227.     }
  228.     
  229.     else if (ynValue == "no")
  230.     {
  231.         intValue = 1;        
  232.     }
  233.     
  234.     else
  235.     {
  236.     if (!isNaN(parseInt(inValue)))
  237.         {
  238.                 intValue = inValue;
  239.         }
  240.     }
  241.     return intValue;    
  242. }
  243.  
  244.  
  245. function yesNoToNoYes(inValue)
  246. {
  247.     var tempValue = new String(inValue);
  248.     
  249.     if ((tempValue != null))
  250.     {
  251.         if (tempValue == "yes")
  252.         {
  253.             return "no";    
  254.         }        
  255.         else if (tempValue == "no")
  256.         {
  257.             return "yes";
  258.         }    
  259.         else
  260.             return inValue;    
  261.     }
  262. }
  263.  
  264. //set checkbox on if inValue is "yes" or 0, off otherwise
  265. function setCheckBox(formName, boxName, inValue)
  266. {
  267.  
  268.     debug("SetCheckbox: " + inValue);
  269.     var intValue = ynToZeroOne(inValue);
  270.  
  271.     if (intValue == 0)
  272.         parent.tabs.tabbody.document[formName][boxName].checked = 1;
  273.     else
  274.         parent.tabs.tabbody.document[formName][boxName].checked = 0;
  275. }
  276.  
  277. function getCheckBox(formName, boxName)        // returns yes if checked, no if not
  278. {
  279.     var outValue = "no";
  280.     
  281.     var tfValue =    (parent.tabs.tabbody.document[formName][boxName].checked);
  282.         
  283.     if (tfValue == true)
  284.         outValue = "yes";
  285.         
  286.     return outValue;    
  287. }
  288.  
  289. function setRadio(formName, radioName, inValue)
  290. {
  291.     var intValue = ynToZeroOne(inValue);
  292.  
  293.     parent.tabs.tabbody.document[formName][radioName][intValue].checked = 1;
  294.     debug("Setting radio " +radioName + " to " + intValue);
  295. }
  296.  
  297. function getRadio(formName, radioName)
  298. {
  299.     
  300.     var radioIndex = -1;
  301.     //based on the assumption that yes is the first radio, "no" is the second radio
  302.     
  303.     if (parent.tabs.tabbody.document[formName][radioName][0].checked == 1)
  304.     {
  305.         //debug("getRadio: returning yes");
  306.         return ("yes");
  307.     }
  308.     else if (parent.tabs.tabbody.document[formName][radioName][1].checked == 1)
  309.     {    
  310.         //debug("getRadio: returning no");
  311.         return ("no");
  312.     }
  313.     else
  314.     {
  315.         //debug("getRadio: radio[0]" + parent.tabs.tabbody.document[formName][radioName][0].checked);
  316.         //debug("getRadio: radio[1]" + parent.tabs.tabbody.document[formName][radioName][1].checked);
  317.          
  318.         for (var i = 0; i < parent.tabs.tabbody.document[formName][radioName].length; i++)
  319.         {
  320.             if (parent.tabs.tabbody.document[formName][radioName][i].checked == 1)    
  321.                 radioIndex = i;        
  322.         }
  323.         return radioIndex;
  324.     }
  325. }
  326.  
  327. function getText(formName, textFieldName)
  328. {
  329.     //return document[formName][textFieldName].value;
  330.     return parent.tabs.tabbody.document[formName][textFieldName].value;
  331. }
  332.  
  333. function setText(formName, textFieldName, inValue)
  334. {
  335.     debug("Setting Text for " + textFieldName + " to " + inValue);
  336.     //document[formName][textFieldName].value = inValue;
  337.     parent.tabs.tabbody.document[formName][textFieldName].value = inValue;
  338. }
  339.  
  340.  
  341. function setSelectList(formName, selectListName, inValue)
  342. {
  343.     if (inValue != null)
  344.     { 
  345.          for (var i = (parent.tabs.tabbody.document[formName][selectListName].length - 1); i >= 0 ; i--)
  346.          {
  347.              if(inValue.toString() == (parent.tabs.tabbody.document[formName][selectListName].options[i].value.toString()))
  348.              {
  349.                  //debug("Found select list Match (" + i + ")(" + inValue + ")");
  350.                  parent.tabs.tabbody.document[formName][selectListName].options[i].selected = true;
  351.              }
  352.          }
  353.     }    
  354. }
  355.  
  356.  
  357.  
  358. function fillNCIFileList(formName, listName)
  359. {
  360.         fillSelectListWithConfigFiles(formName, listName, ".NCI", true);
  361.         
  362.         var acctSetupFile = getAcctSetupFilename();
  363.          var selectedNCIFile = GetNameValuePair(acctSetupFile,"Mode Selection","ExistingSRFile");
  364.         setSelectList(formName, listName, selectedNCIFile);
  365. } // fillNCIFileList
  366.  
  367.  
  368.  
  369. function getSelectListSelection(formName, selectListName)
  370. {
  371.     return    parent.tabs.tabbody.document[formName][selectListName].options[parent.tabs.tabbody.document[formName][selectListName].options.selectedIndex].value.toString();
  372. }
  373.  
  374.  
  375.  
  376.  
  377. function checkData()
  378. {
  379.     return true;
  380. }
  381.  
  382.  
  383.  
  384.  
  385. // end hiding contents from old browsers  -->
  386.