home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / CheckBox / CheckBox.js < prev    next >
Encoding:
JavaScript  |  1998-10-05  |  5.5 KB  |  157 lines

  1. /* ======================================================================
  2. OBJECT:        com_netobjects_CheckBox
  3.  
  4. PLATFORMS:    Netscape Navigator 4.01 or higher, 
  5.                 Microsoft Internet Explorer 4.02 or higher
  6.  
  7. DESC:            This object allows developers to create CheckBoxes with common built
  8.                 in behaviors.
  9. ====================================================================== */
  10. function com_netobjects_CheckBox(params) {
  11.    // Public Properties    
  12.     this.name                 = (params.name != null) ? params.name : "";
  13.     this.checkBoxName        = (params.checkBoxName != null) ? params.checkBoxName : "";
  14.     this.formName            = (params.formName != null) ? params.formName : "";
  15.     this.checked            = (params.checked == true) ? params.checked : false;
  16.     this.checkedVal        = (params.checkedVal != null) ? params.checkedVal : "";
  17.     this.uncheckedVal        = (params.uncheckedVal != null) ? params.uncheckedVal : "";
  18.     this.state                 = (params.state != null) ? params.state : "";
  19.  
  20.     this.testMode            = (params.testMode != null) ? params.testMode : "none"
  21.     
  22.     // Private Properties
  23.     this.checkBoxIndex = 0
  24.  
  25.     // Public Methods
  26.     this.render             = _CheckBox_render;
  27.  
  28.     // Private Methods
  29.     this.validateProperties = _CheckBox_validateProperties;
  30.  
  31.     // Public Events
  32.     this.onBlur              = _CheckBox_onBlur;
  33.     this.onClick             = _CheckBox_onClick;
  34.     this.onFocus           = _CheckBox_onFocus;
  35.     this.onRender         = _CheckBox_onRender;
  36.  
  37.     // Private Events (internal event driven functionality)
  38.     this.eOnClick              = _CheckBox_eOnClick;
  39.  
  40.     // Validate object properties
  41.     this.validateProperties();
  42.  
  43.     // Public Methods ----------------------------------------
  44.     function _CheckBox_render() {
  45.         // Initialize Variables
  46.         var sCheckBoxName = "";
  47.         var svalue = "";
  48.         var schecked = "";
  49.  
  50.         var sonBlur  = "";
  51.         var sonClick = "";
  52.         var sonFocus = "";
  53.  
  54.         // Set Variables
  55.         sCheckBoxName = " Name = \"" + this.checkBoxName + "\""
  56.  
  57.         // Build Nav & IE shared link events
  58.         sonBlur  = " onBlur=\"" + this.name + ".onBlur();\""
  59.         sonClick   = " onclick=\"return " + this.name + ".eOnClick();\""
  60.         sonFocus    = " onFocus=\"" + this.name + ".onFocus();\""
  61.         eEvents  = sonBlur + sonClick + sonFocus;
  62.  
  63.         // Write HTML
  64.         if (this.state == "hidden") {
  65.             svalue = " VALUE = \""+ ((this.checked) ? this.checkedVal : this.uncheckedVal) +"\""
  66.            document.write( "<Input Type=hidden" + sCheckBoxName + svalue + ">\n");
  67.         } else if (this.state == "read-only") {
  68.             schecked = (this.checked) ? this.checkedVal : this.uncheckedVal
  69.            document.write( schecked + "\n");
  70.         } else {
  71.             svalue = " Value = \"" + this.checkedVal     + "\""
  72.             schecked = (this.checked) ? " Checked " : ""
  73.            document.write( "<Input Type=Checkbox "  + sCheckBoxName + svalue + schecked + eEvents + ">\n");
  74.  
  75.         }
  76.  
  77.         // Set control index:
  78.         // The control index is used by the object to identify its respective form element
  79.         // in the event that there is more than one form element with the same name.
  80.         if (this.state != "read-only") {
  81.             // Set control index if multiple controls exist
  82.             this.checkBoxIndex = eval("window.document." + this.formName + "." + this.checkBoxName + ".length")-1
  83.             if (isNaN(this.checkBoxIndex)) {this.checkBoxIndex=0}
  84.         }
  85.  
  86.         // Fire public events
  87.         this.onRender(); 
  88.     
  89.     } // END _CheckBox_render
  90.  
  91.  
  92.     /* ======================================================================
  93.     
  94.    METHOD: _CheckBox_validateProperties.  If the test mode is set,
  95.     generate error and/or warning messages if required or recommended properties
  96.     are set with invalid property values or are not set at all.
  97.  
  98.     ====================================================================== */
  99.     function _CheckBox_validateProperties() {
  100.         if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
  101.             var errors = new Array()
  102.           iIndex = 0;  
  103.          
  104.             // Check for errors
  105.             if (this.name == "") 
  106.                 errors[iIndex++] = "Name is a required property.";  
  107.             if (this.checkBoxName == "") 
  108.                 errors[iIndex++] = "checkBoxName is a required property.";  
  109.             if (this.checkBoxName == this.name) 
  110.                 errors[iIndex++] = "checkBoxName and object name may not be the same.";  
  111.  
  112.             // Display errors
  113.             for (var i=0; i<errors.length; i++)  {
  114.                 if (this.testMode.toLowerCase()    == "text") 
  115.                     document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_CheckBox, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
  116.                 else
  117.                       alert("TEST MODE, com_netobjects_CheckBox, '" + this.name + "' : " + errors[i]);
  118.  
  119.             }            
  120.         } 
  121.     } // END _CheckBox_validateProperties
  122.  
  123.     // Public Event Handlers ----------------------------------------
  124.     function _CheckBox_onBlur() {
  125.     }
  126.     function _CheckBox_onClick() {
  127.     }
  128.     function _CheckBox_onFocus() {
  129.     }
  130.     function _CheckBox_onRender() {
  131.     }
  132.     
  133.     // Private Events ----------------------------------------
  134.     /* ======================================================================
  135.     
  136.    METHOD: _CheckBox_eOnChange.  Internal on change event.  Updates the value 
  137.               from the checkbox.
  138.  
  139.     ====================================================================== */
  140.     function _CheckBox_eOnClick() {
  141.         // use control index if more than one control exists
  142.         var index = ""
  143.         if (!isNaN(eval("window.document." + this.formName + "." + this.checkBoxName + ".length"))) {
  144.             index = "[" + this.checkBoxIndex + "]"
  145.         }
  146.  
  147.         // update value
  148.         this.checked = eval("window.document." + this.formName + "." + this.checkBoxName + index + ".checked")
  149.     
  150.         // Fire public events 
  151.         this.onClick()
  152.  
  153.     } // END _CheckBox_eOnClick
  154.  
  155. } // END CONSTRUCTOR com_netobjects_CheckBox
  156.  
  157.