home *** CD-ROM | disk | FTP | other *** search
- <!--#INCLUDE FILE="MSGlobal.inc"-->
- <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
- ////////////////////////////////////////////////////////////////////
- // //
- // Fusion ASP Components //
- // Custom JScript Object: MSDBDynaField //
- // //
- ////////////////////////////////////////////////////////////////////
- /*
- Object: MSDBDynaField
-
- Version: 1.0 9/04/97
-
- Written By: Application Methods, Inc.
- 6300 Southcenter Blvd.
- Seattle, WA 98188
- (206) 244-2400
- http://www.appmethods.com
-
-
- Description: This object definition describes properties and methods for a
- dynamically constructed edit box or label. From this object definition, a
- valid HTML edit box or label may be constructed from a LiveWire database cursor object.
- One column from the cursor is selected to be the value and for the edit box or label, and the option
- isEditable is used to determine which will be created by the .java file.
-
- Note: Generation of a number of hidden fields is necessary to pass information
- on to other components. All hidden fields created by this object are prefixed
- with 'amaspHidden_' or 'amlivewireComponent_'. Devlopers should never create
- any form element with these prefixes or unexpected results will occur.
-
- Properties:
- name - Name of Dynafield
- useQuery - Whether to use value from query (otherwise uses default)
- queryComponentName - Name of query component to be used
- defaultValue - default value used if useQuery is false
- dataField - field name
- dataType - type of field
- isEditable - Whether the field should be editable or rather whether the field
- is displayed as text or an input box
- visibleLength - Length of input box, in characters
- maxLength - Maximum accepted input length, in characters
- visibleHeight - Height of input box, in approximated lines
- font - Font face for text
- fontSize - Font size for text
- fontColor - Font color for text
- bold - Whether text is bold
- italic - Whether text is italicized
- underline - Whether text is underlined
-
- Methods:
- getColumnValue - Gets values for dataField
- render - renders visual elements of Dynafield
- emitProperties - displays all the properties for the Dynafield
-
-
- Usage: The following example shows a value being displayed to create a edit box
- containing a value from the table "lookup." The column named "ShipCity" will be
- used to get a value.
-
- <HTML>
- <HEAD>
-
- <!SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
-
- // Create and connect the database object
- MSDBConnection1 = new MSDBConnection("test", "ODBC","MS Access", "Northwind","admin","",false);
- MSDBConnection1.connect();
-
- // Create the query object
- MSDBQuery1 = new MSDBQuery("MSDBQuery1", "MSDBConnection1", false, "*", "Customers", "customerID > 7", "lastname");
-
- // Create the dynafield object
- MSDBDynaField1 = new MSDBDynaField( "MSDBDynaField1",
- "true",
- "MSDBQuery1",
- "",
- "ShipCity",
- "string",
- "false",
- 10,
- 10,
- 1,
- "Arial",
- "+0",
- "black",
- "false",
- "false",
- "false");
- <!/SCRIPT>
-
- <META NAME="Generator" CONTENT="NetObjects Fusion 2.0 for Windows">
-
- </HEAD>
- <body>
-
- write("<FORM METHOD=POST>");
- <%
- MSDBConnection1.render()
- MSDBDynaField1.render()
- %>
- write("</FORM>");
-
- </BODY>
- </HTML>
-
- =====================================================================*/
-
- //
- // MSDBDynaField object constructor
- //
- function MSDBDynaField(
- name,
- useQuery,
- queryComponentName,
- defaultValue,
- dataField,
- dataType,
- isEditable,
- visibleLength,
- maxLength,
- visibleHeight,
- font,
- fontSize,
- fontColor,
- bold,
- italic,
- underline)
- {
- // Assign property values
-
- this.name = name;
- this.useQuery = useQuery;
- this.queryComponentName = queryComponentName;
- this.defaultValue = defaultValue;
- this.dataField = dataField;
- this.dataType = dataType;
- this.isEditable = isEditable;
- this.visibleLength = visibleLength;
- this.visibleHeight = visibleHeight
- this.maxLength = maxLength;
- this.font = font;
- this.fontSize = fontSize + "";
- this.fontColor = fontColor;
- this.bold = bold;
- this.italic = italic;
- this.underline = underline;
-
- // Define Methods
- this.getColumnValue = dfGetColumnValue;
- this.render = dfRender;
- this.emitProperties = dfEmitProperties;
-
- if (this.useQuery == "true") {
- // Increment global cursor usage counter since this component will try to use the cursor
- incCursorCallCount();
- }
-
- } //END MSDBDynaField Constructor.
-
- //
- // Method - dbEmitProperties()
- // emits all the object's properties. Used as a debuging tool to verify correct
- // manipulation of the object.
- //
- function dfEmitProperties ()
- {
- debug("Writing MSDBDynaField properties...");
- write("\n<BR><B>MSDBDynaField Properties:</B>");
- write("\n<BR>name = " + this.name);
- write("\n<BR>useQuery = " + this.useQuery);
- write("\n<BR>defaultValue = " + this.defaultValue);
- write("\n<BR>dataField = " + this.dataField);
- write("\n<BR>dataType = " + this.dataType);
- write("\n<BR>isEditable = " + this.isEditable);
- write("\n<BR>visibleLength = " + this.visibleLength);
- write("\n<BR>visibleHeight = " + this.visibleHeight);
- write("\n<BR>font = " + this.font);
- write("\n<BR>fontSize = " + this.fontSize);
- write("\n<BR>fontColor = " + this.fontColor);
- write("\n<BR>bold = " + this.bold);
- write("\n<BR>italic = " + this.italic);
- write("\n<BR>underline = " + this.underline);
- write("<BR>");
- } // END dfEmitProperties;
-
-
- /* Method of MSDBDynaField - GetColumnValue
- Check if the dataField property is not null or blank,
- same for the queryComponentName property.
- If one of the checks fail then return a blank string. Otherwise the
- method uses the eval argument to parse together a value
- for the Query that the MSDBDynaField refers to.
- */
- function dfGetColumnValue() {
- var retStr = '';
- var dynaCursor = new Object();
-
- if ( (this.dataField == null) ||
- (this.dataField == "") ||
- (this.queryComponentName == null) ||
- (this.queryComponentName == "") ) {
- return "";
- }
- else {
- // Get the current cursor for the Query. If none exists getCurrentCursor
- // will create it.
- //debug("Getting cursor from query '"+ this.queryComponentName + "'");
- dynaCursor = eval(this.queryComponentName + ".getCurrentCursor()");
- //dynaCursor = Session("MSDBQuery1");
- //debug("val is '" + dynaCursor.Fields(this.dataField) + "'")
-
- if (dynaCursor != null) {
- //debug("Cursor not null");
- // Check to see if cursor is initialized. If it is not then initialize it
- if (eval(this.queryComponentName + ".initializeCursor()")) {
- //debug("Cursor initialized, attempting to get field '" + this.dataField + "'");
- //debug("val is '" + dynaCursor.Fields(this.dataField) + "'")
- // Retrieve the value for the MSDBDynaField
-
- if (dynaCursor.fields(this.dataField) != null) {
- // If Date value, format before checking for null because
- // JScript cannot detect this datatype untill it is formated.
- // This is a bug specific to JScript.
- if (!(this.dataType == "date" && formatDataValue (dynaCursor.fields(this.dataField), this.dataType) == ""))
- retStr = dynaCursor.fields(this.dataField);
-
- // If boolean return to numeric representation
- // This fixes a JScript nuisance that is automaticly
- // converting boolean values to non numbers.
- if (this.dataType == "boolean")
- retStr = (retStr+"" == "false") ? "0":"-1"
-
- //debug("Getting field");
- }
- }
- }
- else {
- write("\n<BR>Unable to obtain a valid cursor.");
- }
-
- } // end "if ( (this.dataField == null) || ..."
-
- return retStr;
- } // END method GetColumnValue
-
-
- /* Method of MSDBDynaField - dfRender
- This method first examines the this.isEditable variable of the MSDBDynaField object
- if isEditable is true, then the method writes out the HTML statement to generate
- an edit box. If it is false, then it examines the font and other cosmetic properties
- of the MSDBDynaField, and generates the appropriate HTML.
- NOTE! The MSDBDynaField.render() method depends of an existing FORM tag
- allready existing in the HTML. It will not appear if it is set to isEditable = true
- and no FORM tag exisits.
- */
- function dfRender() {
-
- var columnValue;
-
- // if useQuery is true, then get the column value from the cursor.
- // otherwise use the defaultValue,
- if (this.useQuery == "true") {
- if (this.dataType.toUpperCase() == "DATE") {
- columnValue = new Object();
- }
- columnValue = this.getColumnValue();
- }
- else
- columnValue = this.defaultValue;
-
- // output the hidden field for the dataType
- var pre = "amaspHidden_";
- var fieldPre = "amaspField_"; // Used to designate field values passed over in URL that will
- // generally be used in the "where" clause of an SQL query
-
- write("\r\n<INPUT NAME=\"" + pre + this.dataField + "_dataType\" VALUE=\"" + this.dataType + "\" TYPE=\"HIDDEN\">");
-
- if (this.isEditable == "true") {
- // If visibleHeight does not equal one then output a textarea, otherwise output a text input element
- if (this.visibleHeight > 1)
- write("<TEXTAREA NAME=\"" + fieldPre + this.dataField + "\" COLS=\"" + this.visibleLength + "\" ROWS=\"" + this.visibleHeight + "\">" + formatDataValue(columnValue, this.dataType) + "</TEXTAREA>")
- else
- // Format the data value based on its datatype before rendering
- write("<Input TYPE=text NAME=\"" + fieldPre + this.dataField + "\" VALUE=\"" + formatDataValue(columnValue, this.dataType) + "\" SIZE=" + this.visibleLength + " MAXLENGTH=" + this.maxLength + ">")
- //write("<Input TYPE=text NAME=\"" + fieldPre + this.dataField + "\" VALUE=\"" + columnValue + "\" SIZE=" + this.visibleLength + " MAXLENGTH=" + this.maxLength + ">")
- }
- else {
- write("<FONT COLOR="+this.fontColor+" SIZE= \"" + this.fontSize + "\" " +((this.font != null) ? "FACE=\""+ this.font+"\"":"") +">");
- if (this.bold == "true")
- write("<B>");
- if (this.italic == "true")
- write("<I>");
- if (this.underline == "true")
- write("<U>");
-
- // Format the data value based on its datatype before rendering
- //write(formatDataValue(columnValue, this.dataType));
- write(columnValue);
-
- if (this.bold == "true")
- write("</B>");
- if (this.italic == "true")
- write("</I>");
- if (this.underline == "true")
- write("</U>");
- write("</FONT>")
- }
-
- // Decrement global cursor usage counter since this component has tried to use the cursor
- // If the counter has reached zero after doing so, then this is the last cursor using
- // component on the page, so call the DBQuery object's "cursorClose()" method to close
- // the cursor if it's still open.
- if (this.useQuery == "true") {
- decCursorCallCount(this.queryComponentName);
- } // end if
-
- } // END method dfRender
- </SCRIPT>
-