home *** CD-ROM | disk | FTP | other *** search
/ Online Praxis 1998 March / Image.iso / CD-ROM / NETSCAPE / CCK / CONF_ED.Z / cejs.jar / general.js < prev    next >
Encoding:
JavaScript  |  1998-02-12  |  5.9 KB  |  191 lines

  1. // Copyright (C) 1996, 1997 Netscape Communications Corporation, All rights reserved.
  2.  
  3. var prefs = parent.prefs;
  4. var configs = parent.configs;
  5. var gp = parent;
  6. var focusfield;
  7.  
  8. // -- auto controls
  9. var type_string = 1;
  10. var type_number = 2;
  11. var type_bool   = 3;  // Associates true w/ checked
  12. var type_bool2  = 9;  // Associates false w/ checked
  13. var type_bool3  = 10; // Associates "true" w/ checked
  14. var type_radio1 = 4;  // Associates true/false
  15. var type_radio2 = 5;  // Associates "true"/"false"
  16. var type_radio3 = 6;  // Associates string with the buttons
  17. var type_string2 = 7;
  18. var type_select1 = 8;
  19.  
  20. function mapper(control_name, lock_name, pref_name, type)
  21. {
  22.     this.control_name = control_name;
  23.     this.pref_name = pref_name;
  24.     this.type = type;
  25.     this.lock_name = lock_name;
  26. }
  27.  
  28. // Takes the mapping of controls to XPprefs specified in mappers
  29. // and fills in the controls with the corresponding pref values.
  30. function initValue()
  31. {
  32.   var dp = document.prefsform;
  33.  
  34.   for (i = 0; i < mappers.length; i++) 
  35.   {
  36.     var map = mappers[i];
  37.     var pref = gp.get_pref(map.pref_name, prefs);           
  38.     var selector = (map.type == type_bool) ? "checked" : "value";
  39.  
  40.     if ((pref!=null) && (pref.default_value!=null))
  41.     {
  42.       if ((map.type == type_radio1) || (map.type == type_select1))
  43.       {
  44.         var setter = (map.type == type_radio1) ? "checked" : "selected";
  45.         for (j=0; j < dp[map.control_name].length; j++)  
  46.         {
  47.           if (parseInt(dp[map.control_name][j].value)==pref.default_value)
  48.             dp[map.control_name][j][setter]=true;
  49.         }
  50.       } 
  51.       if (map.type == type_radio2)  {
  52.         for (j=0; j < dp[map.control_name].length; j++)  
  53.         {
  54.           if ( ((dp[map.control_name][j].value=="true") && (pref.default_value==true)) ||
  55.                ((dp[map.control_name][j].value=="false") && (pref.default_value==false)) )
  56.             dp[map.control_name][j].checked=true;
  57.         }
  58.       } 
  59.       if (map.type == type_radio3)  {
  60.         dbgMsg("Pref: " + pref.default_value);
  61.         for (j=0; j < dp[map.control_name].length; j++)  
  62.         {
  63.           dbgMsg("Control: " + dp[map.control_name][j].value);
  64.           if(dp[map.control_name][j].value == pref.default_value)
  65.             dp[map.control_name][j].checked = true;
  66.         }
  67.       }
  68.  
  69.       if (map.type == type_bool2)
  70.       {
  71.         if (pref.default_value==false) dp[map.control_name].checked=true;
  72.         if (pref.default_value==true) dp[map.control_name].checked=false;
  73.       }
  74.       else  {
  75.         dp[ map.control_name ][selector] = pref.default_value;
  76.       }
  77.  
  78.       if (map.type == type_bool3)
  79.       {
  80.         if (pref.default_value=="false") dp[map.control_name].checked=false;
  81.         if (pref.default_value=="true") dp[map.control_name].checked=true;
  82.       }
  83.       else  {
  84.         dp[ map.control_name ][selector] = pref.default_value;
  85.       }
  86.  
  87.       if (map.lock_name!="") dp[map.lock_name].checked = pref.locked;
  88.     }
  89.   }
  90. }
  91.  
  92. // Takes the mapping of controls to XPprefs specified in mappers
  93. // and updates the pref values with the values in the correspoding controls
  94. function doCommit()
  95. {
  96.   var dp = document.prefsform;
  97.  
  98.   for (i = 0; i < mappers.length; i++) 
  99.   {
  100.     var map = mappers[i];
  101.  
  102.     var isLocked = (map.lock_name=="") ? false : dp[map.lock_name].checked;
  103.     if ( (map.type == type_radio1) || (map.type == type_select1) )
  104.     {
  105.       var setter = (map.type == type_radio1) ? "checked" : "selected";
  106.       for (j=0; j<dp[map.control_name].length; j++)
  107.       {
  108.         if (dp[map.control_name][j][setter]==true)
  109.           gp.set_pref(map.pref_name, 
  110.                parseInt(dp[map.control_name][j].value),
  111.                isLocked); 
  112.       }
  113.     }
  114.     else if (map.type == type_radio2)
  115.     {
  116.       gp.set_pref(map.pref_name, false, isLocked); 
  117.       for (j=0; j<dp[map.control_name].length; j++)
  118.       {
  119.         if (dp[map.control_name][j].checked==true)
  120.           if (dp[map.control_name][j].value=="true")
  121.             gp.set_pref(map.pref_name, true, isLocked); 
  122.           else if (dp[map.control_name][j].value=="false")
  123.             gp.set_pref(map.pref_name, false, isLocked); 
  124.       }
  125.     }
  126.     else if (map.type == type_radio3)
  127.     {
  128.       for (j=0; j<dp[map.control_name].length; j++)
  129.       {
  130.         if (dp[map.control_name][j].checked==true)
  131.           gp.set_pref(map.pref_name, dp[map.control_name][j].value, isLocked); 
  132.       }
  133.     }
  134.     else if (map.type == type_bool2)
  135.     {
  136.       if (dp[map.control_name].checked==true)
  137.         gp.set_pref(map.pref_name, false, isLocked);
  138.       else
  139.         gp.set_pref(map.pref_name, true, isLocked);
  140.     }
  141.     else if (map.type == type_bool3)
  142.     {
  143.       if (dp[map.control_name].checked==true)
  144.         gp.set_pref(map.pref_name, "true", isLocked);
  145.       else
  146.         gp.set_pref(map.pref_name, "false", isLocked);
  147.     }
  148.     else if (map.type == type_number) 
  149.     {
  150.      if (dp[map.control_name].value!="")
  151.         gp.set_pref(map.pref_name, 
  152.                     parseInt( dp[ map.control_name ].value ),
  153.                     isLocked);
  154.     }
  155.     else 
  156.     {
  157.       var selector = (map.type == type_bool) ? "checked" : "value";
  158.         gp.set_pref(map.pref_name, 
  159.                     dp[ map.control_name ][selector],
  160.                     isLocked);
  161.     }
  162.   }
  163. }
  164.  
  165. function isANumber (checkstring)
  166. {
  167.   for (var i=0; i<checkstring.length; i++)
  168.   {
  169.     if (isNaN(parseInt(checkstring.substring(i,i+1))))
  170.       return false
  171.   }
  172.   return(true);
  173. }
  174.  
  175. function verifyIsANumber(field)
  176. {
  177.   focusfield = field;
  178.   if (! isANumber(field.value))
  179.   {
  180.     setTimeout("alert('This field must contain a number');focusfield.focus();",300);
  181.   }
  182. }
  183.  
  184. // should check to make sure it starts with # and contains only 
  185. // 0-9 and A-F
  186. function verifyIsAColor(field)
  187. {
  188.   return(true);
  189.   // alert("Colors must be in the format \"#nnnnnn\" where n is a hexidecimal digit");
  190. }
  191.