VLWeb Completed Event for File Downloads
Posted: Fri Apr 24, 2020 3:33 am
When downloading a file from a Server Module that uses the Response(*RESOURCE) parameter, is there any way to get a notification that download is completed?
For example, here is a simple Server Module
Here is a Web Page that downloads the CSV
As you can see, what I am trying to do is toggle a loading image while the server module is working.
The Execute is supposed to be synchronous but it seems to be acting asynchronously in that it returns right after the execute call.
We have gotten around this in the past by using target(NEW) on download definition, to force the download in a new window.
Wondering if anyone has better way to handle this.
Thanks,
Joe
For example, here is a simple Server Module
Code: Select all
begin_com role(*EXTENDS #PRIM_SRVM)
srvroutine name(DownloadCSV) response(*resource #Response)
define_com class(#XPRIM_OSUtil) name(#util)
define field(#contentstring) type(*CHAR) length(256) decimals(0)
* simulate a lot of work
#util.ThreadSleep( 10000 )
* not a CSV, but it get the the job done. :D
#contentstring := '{"JOBID":"' + *JOBNBR + '","ServerStatus":"OK",' + '"CPUTYPE":"' + *CPUTYPE + '",' + '"LANSAPGMLIB":"' + *LANSAPGMLIB + '"}'
#Response.ContentString := #ContentString
#Response.AttachmentFileName := 'MyCSV.CSV'
endroutine
end_com
Code: Select all
begin_com role(*EXTENDS #PRIM_WEB) LayoutManager(#Layout1)
define_com class(#PRIM_TBLO) name(#Layout1)
define_com class(#PRIM_TBLO.Row) name(#Layout1Row1) DisplayPosition(1) Parent(#Layout1)
define_com class(#PRIM_TBLO.Column) name(#Layout1Column1) DisplayPosition(1) Parent(#Layout1)
define_com class(#PRIM_MD.RaisedButton) name(#Button) Caption('PRIMARY') DisplayPosition(1) Left(165) Parent(#COM_OWNER) TabPosition(1) ThemeDrawStyle('MediumTitle') Top(203)
define_com class(#PRIM_IMAG) name(#LoadingImage) DisplayPosition(2) Image(#xImageImage32) ImageSizing(None) Left(428) Parent(#COM_OWNER) TabPosition(2) TabStop(False) Top(172) Visible(False)
define_com class(#JoesTestModule.DownloadCSV) name(#Download)
evtroutine handling(#Com_owner.Initialize)
#LoadingImage.Image <= #SYS_WEB.LoadingImage
endroutine
evtroutine handling(#Button.Click)
#LoadingImage.Visible := True
#Download.Execute
#LoadingImage.Visible := False
endroutine
end_com
The Execute is supposed to be synchronous but it seems to be acting asynchronously in that it returns right after the execute call.
We have gotten around this in the past by using target(NEW) on download definition, to force the download in a new window.
Wondering if anyone has better way to handle this.
Thanks,
Joe