Sample Code

Sample Code

Below is annotated sample code illustrating the use of the O4W toolkit.  Specific information for each O4W API call is later in the document; however, this sample code illustrates the "flow" of the O4W design.

Define the name of the stored procedure (with the O4W_ prefix), and include the insert item that defines the O4W toolkit routines

   Subroutine O4W_MYROUTINE(CtlEntId, Event, Request)

   $Insert O4WEquates

Check for the 'create' event, and verify that we have all the information needed to run this routine; if not, return an error

   Begin Case

Case Event _eqc "CREATE"

* Initial form creation

ReportName = Inet_QueryParam(Request, "REPORTID")

If ReportName = "" Then

O4WError("No report specified")

Return

End

Read ReportDef From O4WReportFile%, ReportName else

O4WError("Report '":ReportName:"' not on file")

Return

End

Load the HTML "template" that will serve as the basis for our form, and set some default style information for the form (colors, images, and alignment) and for any "links" on the page

O4WForm(ReportDef<TEMPLATE_NAME$>, O4WColors("", ReportDef<BGCOLOR$>, ReportDef<TEXTCOLOR$>, ReportDef<BGIMAGE$>):@FM:O4WTextStyle("","","","",ReportDef<Align$>+0))

O4WLinkStyle(ReportDef<LINKCOLOR$>, ReportDef<VISITEDCOLOR$> )

Set the "title" of the web page (which is displayed in the browser window)

O4WTitle(ReportDef<TITLE$>)

Define a style, called "RPTALIGN", that we will re-use with various other elements (including the "headline" of the web page)

O4WTextStyle("RPTALIGN", "", "", "", ReportDef<Align$>+0)

O4WHeader(ReportDef<BANNER$>, 1, "BANNER", "RPTALIGN")

Define a section that will contain our results (presented as a table).  Note that the section uses the "RPTALIGN" style defined earlier

O4WSectionStart("DATATABLE", "RPTALIGN")

bBorder = 0

bWidth = ReportDef<TableBorder$> + 0

If ReportDef<TableBorder$> <> "0" And ReportDef<TableBorder$> <> "" Then bBorder = 1

Start the table, named RESULTS, and set its style

O4WTableStart("RESULTS", O4WTableStyle("", bBorder, bWidth, ReportDef<Align$>+0))

For each column in the table, define a "column header" with the desired color and text style

NUM.FIELDS = DCOUNT(ReportDef<DisplayField$>, @VM)

For each.field = 1 To num.fields

colColor = ReportDef<ColumnColor$, each.field>

colBGColor = ReportDef<ColumnBGColor$, each.field>

colBold = ReportDef<ColumnBold$, each.field>

colAlign = ReportDef<columnalign$, each.field>

colItalic = ReportDef<columnItalic$, each.field>

O4WTableHeader(ReportDef<ColumnName$, each.field>, each.field, "",

O4WColors("",colBGColor, colColor):@FM:

O4WTextStyle("", "", colBold, colItalic, colAlign))

Define the styles for the columns themselves, saving them as the style named "RESULTS_<colnumber>"

valColor = ReportDef<ValueColor$, each.field>

valBGColor = ReportDef<ValueBGColor$, each.field>

valAlign = ReportDef<ValueAlign$, each.field>

O4WColors("RESULTS_":each.field, valBGColor, valColor)

O4WTextStyle("RESULTS_":each.field, "", "", "", valAlign)

O4WTableStyle("RESULTS_":each.field, bBorder, bWidth)

Next each.field

Build some results (ommitted from the sample code) and populate the table with the data. Note the use of the style "RESULTS_<colno>" defined for each column (above)

for Cntr = 1 to Num.ROWS

For EACH.FIELD = 1 To NUM.FIELDS

O4WSetCell(CNTR, Each.field, '', 'RESULTS_':EACH.FIELD)

RSLT = ResultData<CNTR, Each.Field>

O4WText(RSLT)

Next each.field

Next Cntr

The RESULTS table is now complete

O4WTableEnd("RESULTS")

 

As an illustration of advanced functionality, convert the table using a "tablesorter" plugin.  This requires some scripts and stylesheets to be added, before the plugin is "attached" to the RESULTS table

O4WScript("/weboi/O4W/jquery.tablesorter.min.js")

O4WScript("/weboi/O4W/jquery.tablesorter.pager.js")

O4WStyleSheet("/weboi/O4W/style.css")

O4WPlugin("RESULTS", "tablesorter", "widthFixed: true, widgets: ['zebra']")

Put a "break" between the table, and add two buttons.  Add events for these buttons when they are "clicked"

O4WBreak()

O4WButton("Download As CSV", "BTNCSV")

O4WButton("Download As PDF", "BTNPDF")

O4WQualifyEvent("BTNCSV", "CLICK")

O4WQualifyEvent("BTNPDF", "CLICK")

The DATATABLE section is now complete

O4WSectionEnd("DATATABLE")

Add a "link" at the bottom of the page, another break, and a "footer"

O4WLink("Home Page", "", "http://www.revelation.com")

O4WBreak()

O4WFooter(ReportDef<FOOTER$>, 3, "FOOTER")

The CREATE event is now complete.  The following section will be called when one of the buttons is clicked, and the "CLICK" event is passed back to the O4W commuter module

 

Case event _eqc "CLICK"

Gosub GenerateTable

 

Finish up the commuter code logic

 

   End case

   Return