home *** CD-ROM | disk | FTP | other *** search
- <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
- <!--#INCLUDE FILE="MSGlobal.inc"-->
- ////////////////////////////////////////////////////////////////////
- // //
- // NetObjects Fusion ASP Components //
- // Custom JScript Object: MSDBList //
- // //
- ////////////////////////////////////////////////////////////////////
- /*
- Object: MSDBList
-
- Version: 1.0 9/16/97
-
- Written By: Application Methods, Inc.
- 6300 Southcenter Blvd.
- Seattle, WA 98188
- (206) 244-2400
- http://www.appmethods.com
-
- Description: The MSDBList object is responsible for displaying the selected results of
- a query in table format. Properties of the MSDBList controls such things as the displayed
- fields, field labels, hyperlink field, hyperlink key values, and various other layout
- and format attributes.
-
- 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 'amaspField_'. Devlopers should never create
- any form element with these prefixes or unexpected results will occur.
-
- Properties:
- queryComponent - Name of Query component used by the MSDBList component
- navComponent - Name of Nav component which navigates the list
- hyperlinkField - Field on which the hyperlink is placed (Field should be listed in fieldNames list<enforced>))
- hyperlinkPage - Page to which the link jumps
-
- labelBold - Is label text bold?
- labelItalic - Is label text italic?
- labelUnderline - Is label text underlined?
- labelSize - Label text size
- labelFont - Label text font name
- labelTextColor - Label text color
-
- dataBold - Is data text bold?
- dataItalic - Is data text italic?
- dataUnderline - Is data text underlined?
- dataSize - Data text size
- dataFont - Data text font name
- dataTextColor - Data text color
-
- cellPadding - Table cell padding
- cellSpacing - Table cell spacing
- borderSize - Table border size
- tableWidth - Total width of Table
-
- keyFieldCount - Count of key fields
- keyFieldNames - Name of key fields
- keyFieldLabels - Label of key fields. Replaces key field name in URL
- keyFieldDataType - Data type of key fields
-
- fieldCount - Count of fields to display (must be less than number of fields selected in query <not-enforced>)
- fieldNames - Name of fields (must be selected from available fields in query component <not-enforced>)
- fieldLabels - Field Labels for each field
-
- Methods:
- emitTableHeader - Opens table, sets formatting, outputs table field labels, always successful
- emitTableBody - Writes out data, possibly successful
- emitTableFooter - Closes table, always successful
-
- Usage: The following displays a list of records from the Orders table
- <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, "*", "Orders", "", "OrderDate");
-
- //Create necessary field arrays for MSDBList component
- MSDBList1keyFieldNames = new Array(1);
- MSDBList1keyFieldLabels = new Array(1);
- MSDBList1keyFieldDataTypes = new Array(1);
-
- MSDBList1keyFieldNames[0] = "OrderID";
- MSDBList1keyFieldLabels[0] = "OrderID";
- MSDBList1keyFieldDataTypes[0] = "number";
-
- MSDBList1fieldNames = new Array(3);
- MSDBList1fieldLabels = new Array(3);
-
- MSDBList1fieldNames[0] = "OrderID"
- MSDBList1fieldLabels[0] = "Order ID"
- MSDBList1fieldNames[1] = "Customer"
- MSDBList1fieldLabels[1] = "Customer"
- MSDBList1fieldNames[2] = "OrderDate"
- MSDBList1fieldLabels[2] = "Order Date"
-
- //Construct MSDBList component
- MSDBList1 = new MSDBList(
- "MSDBQuery1",
- "",
- "OrderID",
- "../index.asp",
- true,
- false,
- false,
- "+0",
- "Times New Roman",
- "black",
- false,
- false,
- false,
- "+0",
- "Times New Roman",
- "black",
- 1,
- 3,
- 2,
- 505,
- 1,
- MSDBList1keyFieldNames,
- MSDBList1keyFieldLabels,
- MSDBList1keyFieldDataTypes,
- 3,
- MSDBList1fieldNames,
- MSDBList1fieldLabels
- );
- <!/SCRIPT>
-
- </HEAD>
- <BODY>
-
- <%
- MSDBConnection1.render()
-
- ' Automatically render list
- MSDBList1.render()
-
- ' -OR- Manually render list
- MSDBList1.emitTableHeader()
- MSDBList1.emitTableBody()
- MSDBList1.emitTableFooter()
- %>
-
- </BODY>
- </HTML>
-
- =====================================================================*/
-
- //
- // MSDBList Object Constructor
- //
- function MSDBList (queryComponent, navComponent, hyperlinkField, hyperlinkPage,
- labelBold, labelItalic, labelUnderline, labelSize, labelFont, labelTextColor,
- dataBold, dataItalic, dataUnderline, dataSize, dataFont, dataTextColor,
- cellPadding, cellSpacing, borderSize, tableWidth,
- keyFieldCount, keyFieldNames, keyFieldLabels, keyFieldDataTypes,
- fieldCount, fieldNames, fieldLabels)
- {
-
- // Properties
- this.queryComponent = (queryComponent != null) ? queryComponent : "";
- this.navComponent = (navComponent != null) ? navComponent : "";
- this.hyperlinkField = (hyperlinkField != null) ? hyperlinkField : "";
- this.hyperlinkPage = (hyperlinkPage != null) ? hyperlinkPage : "";
-
- //Label text format properties
- this.labelBold = (labelBold != null) ? labelBold : false;
- this.labelItalic = (labelItalic != null) ? labelItalic : false;
- this.labelUnderline = (labelUnderline != null) ? labelUnderline : false;
- this.labelSize = (labelSize != null) ? labelSize : "0";
- this.labelFont = (labelFont != null) ? labelFont : "";
- this.labelTextColor = (labelTextColor != null) ? labelTextColor : "black";
-
- //Data text format properties
- this.dataBold = (dataBold != null) ? dataBold : false;
- this.dataItalic = (dataItalic != null) ? dataItalic : false;
- this.dataUnderline = (dataUnderline != null) ? dataUnderline : false;
- this.dataSize = (dataSize != null) ? dataSize : "0";
- this.dataFont = (dataFont != null) ? dataFont : "";
- this.dataTextColor = (dataTextColor != null) ? dataTextColor : "black";
-
- //Table format properties
- this.cellPadding = (cellPadding != null) ? cellPadding : 0;
- this.cellSpacing = (cellSpacing != null) ? cellSpacing : 0;
- this.borderSize = (borderSize != null) ? borderSize : 0;
- this.tableWidth = (tableWidth != null) ? tableWidth : 0;
-
-
- //Key field properties
- this.keyFieldCount = (keyFieldCount != null) ? keyFieldCount : 0;
- if (keyFieldNames != null) {
- this.keyFieldNames = keyFieldNames
- }
- else {
- this.keyFieldNames = new Array();
- for (var i = 0; i < keyFieldCount - 1; i++) this.keyFieldNames[i]="";
- }
-
- if (keyFieldLabels != null) {
- this.keyFieldLabels = keyFieldLabels;
- }
- else {
- this.keyFieldLabels = new Array();
- for (var i = 0; i < keyFieldCount - 1; i++) this.keyFieldLabels[i]="";
- }
-
- if (keyFieldDataTypes != null) {
- this.keyFieldDataTypes = keyFieldDataTypes;
- }
- else {
- this.keyFieldDataTypes = new Array();
- for (var i = 0; i < keyFieldCount - 1; i++) this.keyFieldDataTypes[i]="";
- }
-
- //Display field properties
- this.fieldCount = (fieldCount != null) ? fieldCount : 0;
- if (fieldNames != null) {
- this.fieldNames = fieldNames;
- }
- else {
- this.fieldNames = new Array();
- for (var i = 0; i < fieldCount; i++) fieldNames[i] = "";
- }
-
- if (fieldLabels != null) {
- this.fieldLabels = fieldLabels;
- }
- else {
- this.fieldLabels = new Array();
- for (var i = 0; i < fieldCount; i++) fieldLabels[i] = "";
- }
-
- this.hyperlinkError = false;
-
- // Methods
- this.render = liRender;
- this.emitTableHeader = liEmitTableHeader;
- this.emitTableRow = liEmitTableRow;
- this.emitTableBody = liEmitTableBody;
- this.emitTableFooter = liEmitTableFooter;
- this.checkFieldErrors = liCheckFieldErrors;
-
- this.emitProperties = liEmitProperties;
-
- // Increment global cursor usage counter since this component will try to use the cursor
- incCursorCallCount();
-
- } // END MSDBList constructor
-
-
- //
- // Checks for field names, key field names, and hyperlink fields not present
- // in query, returns a list of printable errors if found, "" if not found.
- //
- function liCheckFieldErrors () {
- //debug("Searching for field errors")
-
- var arrayObjectName = new Array();
-
- var errorMsg="";
- var fieldError = true;
- this.hyperlinkError = false;
-
- var fcnt;
- var ccnt;
-
- //Check field name existance
- //debug("searching fields");
- for (fcnt = 0; fcnt < this.fieldCount; fcnt++) {
- fieldError=true;
- if (this.fieldNames[fcnt] != "") {
- // flip though existing cursor fields looking for a match
- for (ccnt = 0; ccnt < this.theCursor.Fields.Count; ccnt++) {
-
- if (this.theCursor.Fields(ccnt).name.toUpperCase() == this.fieldNames[fcnt].toUpperCase()) {
- fieldError=false;
- } // end if
- } // end if fields for
- }
- else {
- //debug("blank field error found");
- errorMsg += "\n<TR><TD COLSPAN="+this.fieldCount+">***Warning: Field name " + fcnt + " is blank</TD></TR>";
- fieldError = false;
- }
- if (fieldError) {
- //debug("field error found");
- errorMsg += "\n<TR><TD COLSPAN="+this.fieldCount+">***Warning: Field name: '" + this.fieldNames[fcnt] + "' not found in query</TD></TR>";
- }
- }
-
- //Check key field name existance
- //debug("searching key fields")
- for (fcnt = 0; fcnt < this.keyFieldCount; fcnt++) {
- fieldError = true;
- if (this.keyFieldNames[fcnt] != "") {
- // Flip through existing cursor fields looking for match
- for (ccnt = 0; ccnt < this.theCursor.Fields.Count; ccnt++) {
- if (this.theCursor.Fields(ccnt).name.toUpperCase() == this.keyFieldNames[fcnt].toUpperCase()) fieldError=false;
- }
- }
- else {
- //debug("blank key field error found");
- errorMsg += "\n<TR><TD COLSPAN=" + this.fieldCount + ">***Warning: Hyperlink key field name " + fcnt + " is blank</TD></TR>";
- fieldError = false;
- this.hyperlinkError = true;
- }
- if (fieldError) {
- //debug("key field error found");
- errorMsg += "\n<TR><TD COLSPAN=" + this.fieldCount + ">***Warning: Hyperlink key field name" + fcnt + ": '" + this.keyFieldNames[fcnt] + "' not found in query</TD></TR>";
- this.hyperlinkError = true;
- }
- }
-
- // if no hyperlink field or page specified, don't print jump
- if (this.hyperlinkPage == "") this.hyperlinkError = true;
-
- //Check hyperlink field name existance
- if (!this.hyperlinkError) {
- //debug("searching hyperlink field");
- fieldError=true;
- if (this.hyperlinkField != "") {
- for (ccnt = 0; ccnt < this.theCursor.Fields.Count; ccnt++) {
- if (this.theCursor.Fields(ccnt).Name.toUpperCase() == this.hyperlinkField.toUpperCase()) fieldError=false;
- }
- }
- else {
- //debug("blank hyperlink field error found");
- errorMsg += "\n<TR><TD COLSPAN=" + this.fieldCount + ">***Warning: Hyperlink field name is blank</TD></TR>";
- this.hyperlinkError = true;
- fieldError = false;
- }
- if (fieldError) {
- //debug("hyperlink field error found");
- errorMsg += "\n<TR><TD COLSPAN=" + this.fieldCount + ">***Warning: Hyperlink field name" + fcnt + ": '" + this.keyFieldNames[fcnt] + "' not found in query</TD></TR>";
- this.hyperlinkError = true;
- }
- }
-
- //debug("Error search complete");
- return errorMsg;
- } // END liCheckFieldErrors
-
-
- //
- // Writes out HTML that displays all of the list's properties
- //
- function liEmitProperties () {
- //debug("Writing MSDBList properties...");
- write("\n<BR><B>MSDBList Properties:</B>");
- write("\n<BR>queryComponent = " + this.queryComponent);
- write("\n<BR>navComponent = " + this.navComponent);
- write("\n<BR>hyperlinkField = " + this.hyperlinkField);
- write("\n<BR>hyperlinkPage = " + this.hyperlinkPage);
-
- write("\n<BR>labelBold = " + this.labelBold);
- write("\n<BR>labelItalic = " + this.labelItalic);
- write("\n<BR>labelUnderline = " + this.labelUnderline);
- write("\n<BR>labelSize = " + this.labelSize);
- write("\n<BR>labelFont = " + this.labelFont);
- write("\n<BR>labelTextColor = " + this.labelTextColor);
-
- write("\n<BR>dataBold = " + this.dataBold);
- write("\n<BR>dataItalic = " + this.dataItalic);
- write("\n<BR>dataUnderline = " + this.dataUnderline);
- write("\n<BR>dataSize = " + this.dataSize);
- write("\n<BR>dataFont = " + this.dataFont);
- write("\n<BR>dataTextColor = " + this.dataTextColor);
-
-
- write("\n<BR>cellPadding = " + this.cellPadding);
- write("\n<BR>cellSpacing = " + this.cellSpacing);
- write("\n<BR>borderSize = " + this.borderSize);
- write("\n<BR>tableWidth = " + this.tableWidth);
-
- write("\n<BR>keyFieldCount = " + this.keyFieldCount);
- write("\n<BR>fieldCount = " + this.fieldCount);
- var i;
- for (i = 0; i < this.keyFieldCount; i++) {
- write("\n<BR>keyFieldNames" + i + " = " + this.keyFieldNames[i]);
- write("\n<BR>keyFieldLabels" + i + " = " + this.keyFieldLabels[i]);
- write("\n<BR>keyFieldDataTypes" + i + " = " + this.keyFieldDataTypes[i]);
- }
-
- for (i=0; i<this.fieldCount; i++) {
- write("\n<BR>FieldNames " + i + " = " + this.fieldNames[i]);
- write("\n<BR>FieldLabels " + i + " = " + this.fieldLabels[i]);
- }
- write("<BR>");
- } // END liEmitProperties
-
-
- //
- // Writes out HTML that displays the entire list
- //
- function liRender () {
- this.emitTableHeader();
- this.emitTableBody();
- this.emitTableFooter();
-
- // 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.
- decCursorCallCount(this.queryComponent);
-
- } // END liRender
-
-
- //
- // Writes out HTML that displays the list's header
- //
- function liEmitTableHeader () {
- //debug("Writing table header...");
- write("\n<TABLE CELLPADDING="+this.cellPadding+" CELLSPACING="+this.cellSpacing+" BORDER="+this.borderSize)
- write(" WIDTH="+this.tableWidth+">");
- write("\n<THEAD>");
-
- for (var i = 0; i < this.fieldCount; i++) {
- var fieldWidth = 0;
- if (this.fieldCount > 0) fieldWidth = this.tableWidth/this.fieldCount;
- if (fieldWidth > 0)
- write("\n<TD WIDTH = "+fieldWidth+" >");
- else
- write("\n<TD>");
-
- write("<FONT COLOR=" + this.labelTextColor + " SIZE=\""+this.labelSize+((this.labelFont != null) ? "\" FACE=\""+this.labelFont+"\"":"")+">");
- if (this.labelUnderline) write("<U>");
- if (this.labelBold) write("<B>");
- if (this.labelItalic) write("<I>");
-
- write(this.fieldLabels[i]);
-
- if (this.labelItalic) write("</I>");
- if (this.labelBold) write("</B>");
- if (this.labelUnderline) write("</U>");
- write("</FONT>");
- write("</TD>");
- }
- write("\n</THEAD>");
-
- } // END liEmitTableHeader
-
-
- //
- // Builds and writes out HTML that displays the current list row
- //
- function liEmitTableRow () {
- var LinkStr="";
- var pre = "amaspHidden_";
- var fieldPre = "amaspField_"; // Prefix that indicates the field is a database field to be
- // used generally in the where clause of an SQL statement
-
- for (var i=0; i<this.fieldCount; i++) {
- var fieldWidth = 0;
- if (this.fieldCount > 0) fieldWidth = this.tableWidth/this.fieldCount;
- if (fieldWidth > 0)
- write("\n<TD WIDTH = "+fieldWidth+" >");
- else
- write("\n<TD>");
-
- write("<FONT COLOR=" + this.dataTextColor + " SIZE=\""+this.dataSize+((this.dataFont != null) ? "\" FACE=\"" + this.dataFont+"\"":"") + ">");
- if (this.dataUnderline) write("<U>");
- if (this.dataBold) write("<B>");
- if (this.dataItalic) write("<I>");
-
- // Begin constructing URL string. Set "listActive" parameter equal to "true" for listening Query objects
- // that are set to use the previous query from this list
- if (this.fieldNames[i].toUpperCase() == this.hyperlinkField.toUpperCase() && !this.hyperlinkError) {
- LinkStr = this.hyperlinkPage + "?" + pre + "listActive=true";
-
- // Add key fields, values and types to URL string
- if (this.keyFieldCount > 0)
- LinkStr += "&";
-
- // Build up URL-encoded string of key fields, labels and their data types
- for (var kcnt = 0; kcnt < this.keyFieldCount; kcnt++) {
-
- LinkStr += fieldPre + this.keyFieldLabels[kcnt] + "=" +
- escape(formatDataValue(this.theCursor.fields(this.keyFieldNames[kcnt]), this.keyFieldDataTypes[kcnt]));
- LinkStr += "&" + pre + this.keyFieldLabels[kcnt] + "_dataType" + "=" + this.keyFieldDataTypes[kcnt];
- if (kcnt < this.keyFieldCount-1) LinkStr += "&";
- } // end for
-
- write("<A href= \""+LinkStr+"\">");
-
- } // end if
-
- if (this.theCursor.fields(this.fieldNames[i]) != null) {
- write(this.theCursor.fields(this.fieldNames[i]));
- }
- else {
- write("");
- } // end if
-
- if (this.fieldNames[i].toUpperCase() == this.hyperlinkField.toUpperCase() & !this.hyperlinkError) write("</A>");
- if (this.dataItalic) write("</I>");
- if (this.dataBold) write("</B>");
- if (this.dataUnderline) write("</U>");
- write("</FONT>");
- write("</TD>");
- } //end for
-
- } // END liEmitTableRow
-
-
- //
- // Writes out HTML that displays all rows in list
- //
- function liEmitTableBody () {
-
- var count = 0;
- var limit = 0;
- //debug("Writing table body...");
- write("<TBODY>");
-
- //debug("Getting cursor from query '" + this.queryComponent + "'");
- this.theCursor= eval(this.queryComponent + ".getCurrentCursor()");
- //this.createDebugCursor()
-
- if (this.theCursor != null) {
- if (eval(this.queryComponent + ".initializeCursor()")) {
-
- write(this.checkFieldErrors());
-
- // Loop through the 2nd through nth rows where there are n rows in the
- // data set.
-
- // check to see if we have a DBNav component specified
- if ((this.navComponent != null) && (this.navComponent != ""))
- limit = eval(this.navComponent + ".getNumRecords()");
-
- // If a limit was specified, only show that many records
- if (limit != 0)
- while( !eval(this.queryComponent + ".isCursorEnd()") && (count < limit)) {
- write("\n<TR>");
- this.emitTableRow();
- write("</TR>");
- count++;
- eval(this.queryComponent + ".moveNext(1)");
- }
- else // otherwise, show all records in the recordset
- while(!eval(this.queryComponent + ".isCursorEnd()")) {
- write("\n<TR>");
- this.emitTableRow();
- write("</TR>");
- count++;
- eval(this.queryComponent + ".moveNext(1)");
- }
-
- // rewind the cursor
- eval(this.queryComponent + ".movePrevious(" + count + ")");
- eval(this.queryComponent + ".closeCursor()");
- }
- else {
- write("\n<TR><TD COLSPAN=" + this.fieldCount + ">No records found.");
- eval(this.queryComponent + ".closeCursor()");
- }
- }
- else {
- write("\n<TR><TD COLSPAN=" + this.fieldCount + ">Unable to obtain a valid cursor.");
- }
-
- write("\n</TBODY>");
-
- } // END liEmitTableBody
-
-
- //
- // Writes out HTML that displays list footer
- //
- function liEmitTableFooter () {
- //debug("Writing table footer...");
- write("</TABLE>");
- } // END liEmitTableFooter
-
- </SCRIPT>