Visual Report Writer and The Web (XII)¶
In this twelfth blog about Visual Report Writer and the Web, I want to take you through some features that are not directly related to reports but can be found on the Live Demo website (European Server, USA server). If this is the first blog you are reading, I encourage you to check out the eleven other blogs: (1: The Solution, 2: Invoices Report, 3: The Cleanup, 4: The CustomerList, 5: The OrderList, 6: The Credit and Balances Overview, 7: Inventory Stock Levels, 8: Sick Leave, 9: FileList (RDS), 10: Four Wine Data Based Reports, 11: Top 10 Salespersons). Meanwhile, we have released the Alpha II version of Visual Report Writer 3.0 and the 2.1+ Library only setup. The latter is needed to facilitate web reporting using the 17.1 DataFlex Web Framework, making it resemble the demo website.
Toolbars¶
If you navigate around the demo website, you will discover that in some cWebView-based views, there is a toolbar to find data to be used as selection criteria. The toolbar shown is the standard find toolbar created when you create a new web project; however, it is not always visible. How is this achieved?
The solution I devised consists of two parts. First, the site supports a login system where a visitor is automatically logged in as a guest, and a guest user has limited rights. These limited rights instruct the application to hide the standard find toolbar. The automatic login is accomplished with the following code:
Object oWebApp is a cWebApp
Set psTheme to "Df_Web_Creme"
Procedure OnLoad
Boolean bIsLoggedIn
Get IsLoggedIn of ghoWebSessionManager to bIsLoggedIn
If (not (bIsLoggedIn)) Begin
Get UserLogin of ghoWebSessionManager C_$GUESTLOGINID C_$GUESTLOGINPWD to bIsLoggedIn
End
End_Procedure
Logging in or connecting to the web application triggers the OnChangeRights event. In the oFileMenu object, this event is caught to hide the normal file pull-down options such as find, save, and delete, as well as the standard find toolbar.
Object oFileMenu is a cWebMenuItem
Set psCaption to "File"
Procedure OnChangeRights
Integer iUserRights
Get piUserRights of ghoWebSessionManager to iUserRights
WebSet pbRender of oClearMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oClearAllMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oPromptMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oFindMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oNextMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oPreviousMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oLastMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oFirstMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oSaveMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oDeleteMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbBeginGroup of oLoginMenuItem to (iUserRights <= C_DATAEDITRIGHTS)
WebSet pbRender of oFileToolBar to (iUserRights <= C_DATAEDITRIGHTS)
End_Procedure
With the above, a guest user - who does not have data edit rights - does not see a standard file pull-down or a standard find toolbar. How is it that some views still display a find toolbar while the guest user is logged in?
This is managed from the view object itself. Each view, normally instantiated from cWebView, is instantiated from a subclass named cVRWWebView. In this subclass, the methods OnShow and OnHide are utilized to handle the find toolbar-related actions. The class defines a property named pbUseFindToolBar, which defaults to false but can be set to true on a view-by-view basis.
Class cVRWWebView is a cWebView
Procedure Construct_Object
Forward Send Construct_Object
Property Boolean pbUseFindToolBar False
Set pbServerOnShow to True
Set pbServerOnHide to True
End_Procedure
The OnShow event takes the property and sends a message to the command bars object to show or hide the find toolbar.
Procedure OnShow
Handle hoCommandBar
Boolean bUseFindToolBar
Get phoCommandBar of oWebApp to hoCommandBar
Get pbUseFindToolBar to bUseFindToolBar
Send EnableFindToolBar of hoCommandBar bUseFindToolBar
End_Procedure
When the view focus changes to another view, the find toolbar is always hidden.
Procedure OnHide
Handle hoCommandBar
Get phoCommandBar of oWebApp to hoCommandBar
Send EnableFindToolBar of hoCommandBar False
End_Procedure
Finally, the command bars object (in WebApp.Src) sets the pbRender property of the find toolbar based on the passed true/false value.
Procedure EnableFindToolBar Boolean bShow
WebSet pbRender of oFindToolBar to bShow
End_Procedure
End_Object
Use SessionManager.wo
Next to the find toolbar, there is a file toolbar. This bar is only available if the logged-in user has data or doc edit rights. Doc edit rights allow changes to the contents of "The Solution" page as well as the contents of the "Show Documentation" modal dialogs, which contain the same text. Data edit rights enable the logged-in user to edit, delete, or create rows in the web order, wines, or adventure works data via the views that can be opened from the view pull-down. These rights are intended for demonstration purposes, allowing the views to be opened to inspect the report results if desired.
Login¶
As mentioned, the demo web application supports user login. Normally, when your application invokes the login dialog, the name and password fields are empty, requiring the user to enter the information. Since an automatic login is coded in this demo application, and you might not know the login credentials, I decided to pre-fill the login credentials when the login dialog is invoked. For a data or doc edit session, the operator knows the other login account information values and can change them. For a visitor, all that is needed is to click OK. Pre-entering the login credentials is accomplished via the OnShow event of the login dialog.
Set pbServerOnShow to True
Procedure OnShow
WebSet psValue of oLoginName to C_$GUESTLOGINID
WebSet psValue of oPassword to C_$GUESTLOGINPWD
End_Procedure
The rest of the login dialog remains the same as the standard login dialog provided by the framework.
Documentation¶
In all report views, you will find a toolbar item labeled "Documentation." Clicking this button opens a modal dialog displaying text that explains information about the report view. The text is the same as that displayed when you click individual examples on "The Solution" page. The "The Solution" blog describes where the data is stored. The documentation button sends the message ShowViewDocumentation to the cVRWWebView based object. In this method, the name of the view is retrieved, and a row in the documentation table is located. The ID of the documentation row is passed to the method that displays the modal dialog.
Procedure ShowViewDocumentation Handle hoReturn
Handle hoView
String sViewName
Get ViewObject to hoView
Get Object_Label of hoView to sViewName
Clear Documentation
Move sViewName to Documentation.ViewName
Find Ge Documentation by 2
If (Found and (Documentation.ViewName = sViewName)) Begin
Send ShowDocumentation of oModalDocumentationDialog hoReturn Documentation.ID
End
End_Procedure
The oModalDocumentationDialog is a "normal" cWebModalDialog object where the upper panel (cWebPanel) has only one child object, a cWebHtmlBox object.
Object oModalDocumentationDialog is a cWebModalDialog
Set psCaption to "Documentation"
Set piMinWidth to 600
Set piMinHeight to 400
Object oMainPanel is a cWebPanel
Object oWebDocumentationBox is a cWebHtmlBox
Set psHtmlId to "SolutionText"
Set pbFillHeight to True
End_Object
End_Object
The ShowDocumentation method stores the passed ID of the documentation row instead of the full HTML documentation string because the client first needs to be instructed to open the modal dialog before the value can be displayed. Storing the ID takes less memory and transport space than storing the full HTML string, especially since the property is a web synchronized property. The drawback of storing the ID is that the system needs to read the row in the documentation table twice (once for locating the correct topic and once for showing).
{ WebProperty = True DesignTime = False }
Property Integer piDocumentationId
Procedure ShowDocumentation Handle hoReturn Integer iDocumentationId
WebSet piDocumentationId to iDocumentationId
Send Popup hoReturn
End_Procedure
When the dialog opens, the OnShow event is triggered, which is used to fill the contents of the cWebHtmlBox object. This is accomplished with the following code enhancement.
Set pbServerOnShow to True
Procedure OnShow
Clear Documentation
WebGet piDocumentationId to Documentation.Id
Find Eq Documentation by 1
Send UpdateHtml of oWebDocumentationBox (Trim(Documentation.Value))
End_Procedure
This concludes this twelfth blog about Visual Report Writer and the Web. There is one more blog in this series that will address the HTML report supporting the onclick event. The 3.0 product will support this, and we are currently working on its interface (the current implementation is a "hack"), so this blog may take a few more weeks before it appears here.
We hope these twelve blogs and the demo website have encouraged you to get started with Visual Report Writer in the Web framework.