home *** CD-ROM | disk | FTP | other *** search
- /* ======================================================================
- OBJECT: com_netobjects_CheckBox
-
- PLATFORMS: Netscape Navigator 4.01 or higher,
- Microsoft Internet Explorer 4.02 or higher
-
- DESC: This object allows developers to create CheckBoxes with common built
- in behaviors.
- ====================================================================== */
- function com_netobjects_CheckBox(params) {
- // Public Properties
- this.name = (params.name != null) ? params.name : "";
- this.checkBoxName = (params.checkBoxName != null) ? params.checkBoxName : "";
- this.formName = (params.formName != null) ? params.formName : "";
- this.checked = (params.checked == true) ? params.checked : false;
- this.checkedVal = (params.checkedVal != null) ? params.checkedVal : "";
- this.uncheckedVal = (params.uncheckedVal != null) ? params.uncheckedVal : "";
- this.state = (params.state != null) ? params.state : "";
-
- this.testMode = (params.testMode != null) ? params.testMode : "none"
-
- // Private Properties
- this.checkBoxIndex = 0
-
- // Public Methods
- this.render = _CheckBox_render;
-
- // Private Methods
- this.validateProperties = _CheckBox_validateProperties;
-
- // Public Events
- this.onBlur = _CheckBox_onBlur;
- this.onClick = _CheckBox_onClick;
- this.onFocus = _CheckBox_onFocus;
- this.onRender = _CheckBox_onRender;
-
- // Private Events (internal event driven functionality)
- this.eOnClick = _CheckBox_eOnClick;
-
- // Validate object properties
- this.validateProperties();
-
- // Public Methods ----------------------------------------
- function _CheckBox_render() {
- // Initialize Variables
- var sCheckBoxName = "";
- var svalue = "";
- var schecked = "";
-
- var sonBlur = "";
- var sonClick = "";
- var sonFocus = "";
-
- // Set Variables
- sCheckBoxName = " Name = \"" + this.checkBoxName + "\""
-
- // Build Nav & IE shared link events
- sonBlur = " onBlur=\"" + this.name + ".onBlur();\""
- sonClick = " onclick=\"return " + this.name + ".eOnClick();\""
- sonFocus = " onFocus=\"" + this.name + ".onFocus();\""
- eEvents = sonBlur + sonClick + sonFocus;
-
- // Write HTML
- if (this.state == "hidden") {
- svalue = " VALUE = \""+ ((this.checked) ? this.checkedVal : this.uncheckedVal) +"\""
- document.write( "<Input Type=hidden" + sCheckBoxName + svalue + ">\n");
- } else if (this.state == "read-only") {
- schecked = (this.checked) ? this.checkedVal : this.uncheckedVal
- document.write( schecked + "\n");
- } else {
- svalue = " Value = \"" + this.checkedVal + "\""
- schecked = (this.checked) ? " Checked " : ""
- document.write( "<Input Type=Checkbox " + sCheckBoxName + svalue + schecked + eEvents + ">\n");
-
- }
-
- // Set control index:
- // The control index is used by the object to identify its respective form element
- // in the event that there is more than one form element with the same name.
- if (this.state != "read-only") {
- // Set control index if multiple controls exist
- this.checkBoxIndex = eval("window.document." + this.formName + "." + this.checkBoxName + ".length")-1
- if (isNaN(this.checkBoxIndex)) {this.checkBoxIndex=0}
- }
-
- // Fire public events
- this.onRender();
-
- } // END _CheckBox_render
-
-
- /* ======================================================================
-
- METHOD: _CheckBox_validateProperties. If the test mode is set,
- generate error and/or warning messages if required or recommended properties
- are set with invalid property values or are not set at all.
-
- ====================================================================== */
- function _CheckBox_validateProperties() {
- if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
- var errors = new Array()
- iIndex = 0;
-
- // Check for errors
- if (this.name == "")
- errors[iIndex++] = "Name is a required property.";
- if (this.checkBoxName == "")
- errors[iIndex++] = "checkBoxName is a required property.";
- if (this.checkBoxName == this.name)
- errors[iIndex++] = "checkBoxName and object name may not be the same.";
-
- // Display errors
- for (var i=0; i<errors.length; i++) {
- if (this.testMode.toLowerCase() == "text")
- document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_CheckBox, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
- else
- alert("TEST MODE, com_netobjects_CheckBox, '" + this.name + "' : " + errors[i]);
-
- }
- }
- } // END _CheckBox_validateProperties
-
- // Public Event Handlers ----------------------------------------
- function _CheckBox_onBlur() {
- }
- function _CheckBox_onClick() {
- }
- function _CheckBox_onFocus() {
- }
- function _CheckBox_onRender() {
- }
-
- // Private Events ----------------------------------------
- /* ======================================================================
-
- METHOD: _CheckBox_eOnChange. Internal on change event. Updates the value
- from the checkbox.
-
- ====================================================================== */
- function _CheckBox_eOnClick() {
- // use control index if more than one control exists
- var index = ""
- if (!isNaN(eval("window.document." + this.formName + "." + this.checkBoxName + ".length"))) {
- index = "[" + this.checkBoxIndex + "]"
- }
-
- // update value
- this.checked = eval("window.document." + this.formName + "." + this.checkBoxName + index + ".checked")
-
- // Fire public events
- this.onClick()
-
- } // END _CheckBox_eOnClick
-
- } // END CONSTRUCTOR com_netobjects_CheckBox
-
-