Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: Modal progress window

$
0
0
Re: Modal progress window
Web Connection 5.0
Re: Modal progress window
04/19/2012
08:31:31 AM
3HE0I9WHG Show this entire thread in new window
Gratar Image based on email address
From:
Luca
To:
Attachments:
None
Hi Marty,
I did not understand what and where I have to look for.
I find this occurrence about Ajax in Process.prg:
FUNCTION WebResource() LOCAL lcKey, lnIndex, loContent, lcContent, lc lcKey = LOWER(Request.QueryString("Resource")) DO CASE #IF WWC_LOAD_WEBCONTROLSAJAX *** Fixed Resources CASE lcKey == "wwscriptlibrary" lcContentType = "application/x-javascript" *** Allow GZip compression if the client allows *** Note this property will automatically go to .F. if *** the client doesn't support gzip Response.GzipCompression = .T. DO CASE CASE lcKey = "wwscriptlibrary" *** Pass the value explicitly so .F. WILL properly be passed if not supported lcContent = GetwwScriptLibrary_JavaScript(Response.GZipCompression) ENDCASE *** Now manually set the Content-Encoding IF Response.GZipCompression Response.AppendHeader("Content-Encoding","gzip") ENDIF *** Turn off the default compression processing because *** the content is already compressed (and cached) Response.GzipCompression = .F. #ENDIF OTHERWISE *** Retrieve globally stored Resource loContent = Server.oResources.Item(lcKey) IF ISNULL(loContent) Response.Status="404 Not Found" return ENDIF lcContentType = loContent.ContentType lcContent = loContent.Content ENDCASE Response.ContentType=lcContentType Response.AddCacheHeader(1200) && Cache this output Response.Write(lcContent) ENDFUNC

and this in generated code boundary:

DEFINE CLASS test_Page_WCSX AS test_Page Id = [test_Page] *** Control Definitions HIDDEN CTL0002 CTL0002 = null Header = null HIDDEN CTL0004 CTL0004 = null HIDDEN CTL0005 CTL0005 = null form1 = null HIDDEN CTL0007 CTL0007 = null HIDDEN CTL0008 CTL0008 = null HIDDEN CTL0009 CTL0009 = null Progress = null HIDDEN CTL0011 CTL0011 = null ShowCode0 = null HIDDEN CTL0013 CTL0013 = null ShowCode1 = null HIDDEN CTL0015 CTL0015 = null HIDDEN CTL0016 CTL0016 = null HIDDEN CTL0017 CTL0017 = null FUNCTION Initialize(loPage) LOCAL __lcHtml DODEFAULT(loPage) THIS.Attributes.Add("Language","C#") __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [<!DOCTYPE html>]+ CRLF +; [<html>] THIS.CTL0002 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0002") THIS.CTL0002.Text = __lcHtml THIS.AddControl(THIS.CTL0002) THIS.Header = CREATEOBJECT("wwwebhead",THIS.Page,"Header") THIS.AddControl(THIS.Header) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [ <title>Progress Bar and AJAX Demo</title>]+ CRLF +; [ <link href="westwind.css" rel="stylesheet" type="text/css" />] THIS.CTL0004 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0004") THIS.CTL0004.Text = __lcHtml THIS.CTL0004.UniqueId = [Header_CTL0004] THIS.Header.AddControl(THIS.CTL0004) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [<body>]+ CRLF +; [ ] THIS.CTL0005 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0005") THIS.CTL0005.Text = __lcHtml THIS.AddControl(THIS.CTL0005) THIS.form1 = CREATEOBJECT("wwWebform",THIS.Page,"form1") THIS.AddControl(THIS.form1) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [ <h1>Progress Bar</h1>]+ CRLF +; [ ]+ CRLF +; [ <div class="toolbarcontainer">]+ CRLF +; [ <a href="default.htm" class="hoverbutton"><img src="../images/home.gif" /> Sample Home</a> | ]+ CRLF +; [ <a href="progressBar.wcsx" class="hoverbutton"><img src="../images/refresh.gif" /> Reset Form</a> | ]+ CRLF +; [ <small>Rendered at: ] THIS.CTL0007 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0007") THIS.CTL0007.Text = __lcHtml THIS.AddControl(THIS.CTL0007) THIS.CTL0008 = CREATEOBJECT("EvalControl",THIS.Page,"CTL0008") THIS.CTL0008.EvalExpression = [ DateTime() ] THIS.AddControl(THIS.CTL0008) __lcHtml = [] __lcHtml = __lcHtml + [</small>]+ CRLF +; [ </div>]+ CRLF +; [ ]+ CRLF +; [ <div class="descriptionheader" >]+ CRLF +; [ This sample demonstrates how to asynchronously run a task on the server while displaying]+ CRLF +; [ progress in the current page by utilizing AJAX. Using this mechanism it's possible to run long running]+ CRLF +; [ tasks in the background and continue working on the client side while displaying context ]+ CRLF +; [ specific progress.]+ CRLF +; [ </div>]+ CRLF +; [ ] + CRLF __lcHtml = __lcHtml + [ <div class="containercontent" style="margin: 0 auto;text-align: left;">]+ CRLF +; [ ]+ CRLF +; [ <input id="btnStartProcessing" type="button" value="Start Processing" onclick="StartProcessing()" />]+ CRLF +; [ <input id="btnStopProcessing" type="button" value="Cancel Processing" onclick="Cancelled = true;" />]+ CRLF +; []+ CRLF +; []+ CRLF +; [&nbsp;<div style="margin: 20px;">]+ CRLF +; [ ] THIS.CTL0009 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0009") THIS.CTL0009.Text = __lcHtml THIS.AddControl(THIS.CTL0009) THIS.Progress = CREATEOBJECT("wwwebprogressbar",THIS.Page,"Progress") THIS.Progress.Text = [Waiting to get started] THIS.Progress.Width = [500px] THIS.AddControl(THIS.Progress) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [ </div>]+ CRLF +; [ ]+ CRLF +; [ <!-- Demonstrate manually updating the progress bar -->]+ CRLF +; [ <input type="text" id="txtPercent" value="58" size="4"/>]+ CRLF +; [ <input id=btnSetPercent" type="button" value="Set Percentage" ]+ CRLF +; [ onclick="UpdateProgressBar('Progress',$('#txtPercent').val(),'Updated...')" /> ]+ CRLF +; [ <hr /> ]+ CRLF +; [ ]+ CRLF +; [ <div id="lblResult"></div> ] + CRLF __lcHtml = __lcHtml + [ ]+ CRLF +; [ <blockquote>]+ CRLF +; [ This example demonstrates using the wwWebProgressBar control to show progress of an operation running on the server.]+ CRLF +; [ The server form has three client functions: StartProcessing, UpdateProgress and ProcessComplete, which are fired from script]+ CRLF +; [ code using the wwMethodCallbackControl that handles the remote processing.]+ CRLF +; [ <br />]+ CRLF +; [ <br />]+ CRLF +; [ The code pings this server once a second and requests updated status information - an object returned from the server]+ CRLF +; [ that contains a message a percentage and completion and cancellation status in this case. If complete the client calls]+ CRLF +; [ the server again to ProcessComplete which returns a final result in the form of a DataGrid generated string to the] + CRLF __lcHtml = __lcHtml + [ client. ]+ CRLF +; [ <br />]+ CRLF +; [ <br />]+ CRLF +; [ All of this happens in the context of a single page, without post backs. Notice that during the update process the]+ CRLF +; [ page remains live so you can for example set the percentage manually with the percentage button. The value will be]+ CRLF +; [ set briefly until the next server update brings back more information and updates the progress bar again.]+ CRLF +; [ </blockquote>]+ CRLF +; [ ]+ CRLF +; [ <hr />]+ CRLF +; [ ] + CRLF __lcHtml = __lcHtml + [ ] THIS.CTL0011 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0011") THIS.CTL0011.Text = __lcHtml THIS.AddControl(THIS.CTL0011) THIS.ShowCode0 = CREATEOBJECT("wwwebshowcode",THIS.Page,"ShowCode0") THIS.ShowCode0.DisplayMode = [WCSX] THIS.ShowCode0.Text = [Show WCSX] THIS.AddControl(THIS.ShowCode0) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [ ] THIS.CTL0013 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0013") THIS.CTL0013.Text = __lcHtml THIS.AddControl(THIS.CTL0013) THIS.ShowCode1 = CREATEOBJECT("wwwebshowcode",THIS.Page,"ShowCode1") THIS.ShowCode1.DisplayMode = [VFP] THIS.ShowCode1.Text = [Show PRG] THIS.AddControl(THIS.ShowCode1) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [ ]+ CRLF +; [ </div>]+ CRLF +; [ ]+ CRLF +; [<script type="text/javascript">]+ CRLF +; [var Cancelled = false;]+ CRLF +; [var TimerInterval = 50;]+ CRLF +; []+ CRLF +; [function StartProcessing()]+ CRLF +; [{] + CRLF __lcHtml = __lcHtml + [ Cancelled = false;]+ CRLF +; [ $('#btnStartProcessing').attr("disabled",true);]+ CRLF +; [ $('#btnStopProcessing').attr("disabled",false); ]+ CRLF +; [ $('#lblResult').html("");]+ CRLF +; [ ]+ CRLF +; [ // *** Progress_Ajax is the name of the Progress Control _Ajax for the wwWebAjax instance]+ CRLF +; [ Progress_Ajax.callMethod("StartProcessing_Callback",[] + ']' + [,]+ CRLF +; [ function(result) {]+ CRLF +; [ // *** Start the chain - request progress information in timeout seconds]+ CRLF +; [ window.setTimeout(GetProgress,TimerInterval); ] + CRLF __lcHtml = __lcHtml + [ });]+ CRLF +; [} ]+ CRLF +; [function GetProgress()]+ CRLF +; [{]+ CRLF +; [ // *** Iniate a callback to the server to get the progress]+ CRLF +; [ // *** Pass cancelled flag as parameter so server can now if to cancel]+ CRLF +; [ Progress_Ajax.callMethod("UpdateProgress_Callback", [Cancelled] + ']' + [,]+ CRLF +; [ // this returns the server's response as an object]+ CRLF +; [ // result is ProgressEventArgs returned from server]+ CRLF +; [ function(result) {] + CRLF __lcHtml = __lcHtml + [ // Update the progress bar settings]+ CRLF +; [ UpdateProgressBar("Progress",result.percent,result.message);]+ CRLF +; [ ]+ CRLF +; [ if (result.cancelled)]+ CRLF +; [ {]+ CRLF +; [ alert('Operation cancelled on the server.');]+ CRLF +; [ $('#btnStartProcessing').attr("disabled",false);]+ CRLF +; [ $('#btnStopProcessing').attr("disabled",true);]+ CRLF +; [ }]+ CRLF +; [ else if (result.completed || result.percent >= 100)] + CRLF __lcHtml = __lcHtml + [ ProcessComplete();]+ CRLF +; [ else]+ CRLF +; [ window.setTimeout( GetProgress, TimerInterval );]+ CRLF +; [ });]+ CRLF +; [}]+ CRLF +; [function ProcessComplete()]+ CRLF +; [{]+ CRLF +; [ // *** pick up the final result]+ CRLF +; [ Progress_Ajax.callMethod("ProcessComplete_Callback",[] + ']' + [,]+ CRLF +; [ function(Result)] + CRLF __lcHtml = __lcHtml + [ {]+ CRLF +; [ $('#btnStartProcessing').attr("disabled",false);]+ CRLF +; [ $('#btnStopProcessing').attr("disabled",true);]+ CRLF +; [ $("#lblResult").html("<center>" + Result + "</center>");]+ CRLF +; [ UpdateProgressBar('Progress',100,"Customer List Download complete");]+ CRLF +; [ });]+ CRLF +; [} ]+ CRLF +; [</script>]+ CRLF +; []+ CRLF +; [ ] THIS.CTL0015 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0015") THIS.CTL0015.Text = __lcHtml THIS.AddControl(THIS.CTL0015) THIS.CTL0016 = CREATEOBJECT("wwWebForm",THIS.Page,"CTL0016") THIS.CTL0016.RenderType = 2 THIS.AddControl(THIS.CTL0016) __lcHtml = [] __lcHtml = __lcHtml + []+ CRLF +; [</body>]+ CRLF +; [</html>] THIS.CTL0017 = CREATEOBJECT("wwWebLiteral",THIS.Page,"CTL0017") THIS.CTL0017.Text = __lcHtml THIS.AddControl(THIS.CTL0017) ENDFUNC ENDDEFINE

Thanks


Hey Luca,

What I'm curious about is where your Ajax Callback functions are located; the StartProcess_Callback and the UpdateProgress_Callback functions. They should be in your Codebehind PRG file for the WCSX page.

Marty


Hi Marty,
I did not understand what and where I have to look for.
I find this occurrence about Ajax in Process.prg:

FUNCTION WebResource() LOCAL lcKey, lnIndex, loContent, lcContent, lc lcKey = LOWER(Request.QueryString("Resource")) DO CASE #IF WWC_LOAD_WEBCONTROLSAJAX *** Fixed Resources CASE lcKey == "wwscriptlibrary" lcContentType = "application/x-javascript" *** Allow GZip compression if the client allows *** Note this property will automatically go to .F. if *** the client doesn't support gzip Response.GzipCompression = .T. DO CASE CASE lcKey = "wwscriptlibrary" *** Pass the value explicitly so .F. WILL properly be passed if not supported lcContent = GetwwScriptLibrary_JavaScript(Response.GZipCompression) ENDCASE *** Now manually set the Content-Encoding IF Response.GZipCompression Response.AppendHeader("Content-Encoding","gzip") ENDIF *** Turn off the default compression processing because *** the content is already compressed (and cached) Response.GzipCompression = .F. #ENDIF OTHERWISE *** Retrieve globally stored Resource loContent = Server.oResources.Item(lcKey) IF ISNULL(loContent) Response.Status="404 Not Found" return ENDIF lcContentType = loContent.ContentType lcContent = loContent.Content ENDCASE Response.ContentType=lcContentType Response.AddCacheHeader(1200) && Cache this output Response.Write(lcContent) ENDFUNC

Thanks


No worries!

Where does your Ajax code live? Is it in the Code-behind for the WCSX file, or is it in your Process method?

Marty


Thank you very much for patience :)

<%@ Page Language="C#" ID="test_Page" GeneratedSourceFile="Backoffice\test_Page.prg" %> <%@ Register Assembly="WebConnectionWebControls" Namespace="Westwind.WebConnection.WebControls" TagPrefix="ww" %> <!DOCTYPE html> <html> <head> <title>Progress Bar and AJAX Demo</title> <link href="westwind.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <h1>Progress Bar</h1> <div class="toolbarcontainer"> <a href="default.htm" class="hoverbutton"><img src="../images/home.gif" /> Sample Home</a> | <a href="progressBar.wcsx" class="hoverbutton"><img src="../images/refresh.gif" /> Reset Form</a> | <small>Rendered at: <%= DateTime() %></small> </div> <div class="descriptionheader" > This sample demonstrates how to asynchronously run a task on the server while displaying progress in the current page by utilizing AJAX. Using this mechanism it's possible to run long running tasks in the background and continue working on the client side while displaying context specific progress. </div> <div class="containercontent" style="margin: 0 auto;text-align: left;"> <input id="btnStartProcessing" type="button" value="Start Processing" onclick="StartProcessing()" /> <input id="btnStopProcessing" type="button" value="Cancel Processing" onclick="Cancelled = true;" />  <div style="margin: 20px;"> <ww:wwWebProgressBar runat="server" id="Progress" Text="Waiting to get started" Width="500px" > </ww:wwWebProgressBar> </div> <!-- Demonstrate manually updating the progress bar --> <input type="text" id="txtPercent" value="58" size="4"/> <input id=btnSetPercent" type="button" value="Set Percentage" onclick="UpdateProgressBar('Progress',$('#txtPercent').val(),'Updated...')" /> <hr /> <div id="lblResult"></div> <blockquote> This example demonstrates using the wwWebProgressBar control to show progress of an operation running on the server. The server form has three client functions: StartProcessing, UpdateProgress and ProcessComplete, which are fired from script code using the wwMethodCallbackControl that handles the remote processing. <br /> <br /> The code pings this server once a second and requests updated status information - an object returned from the server that contains a message a percentage and completion and cancellation status in this case. If complete the client calls the server again to ProcessComplete which returns a final result in the form of a DataGrid generated string to the client. <br /> <br /> All of this happens in the context of a single page, without post backs. Notice that during the update process the page remains live so you can for example set the percentage manually with the percentage button. The value will be set briefly until the next server update brings back more information and updates the progress bar again. </blockquote> <hr /> <ww:wwWebShowCode ID="ShowCode0" runat="server" DisplayMode="WCSX" Text="Show WCSX" /> <ww:wwWebShowCode ID="ShowCode1" runat="server" DisplayMode="VFP" Text="Show PRG" /> </div> <script type="text/javascript"> var Cancelled = false; var TimerInterval = 500; function StartProcessing() { Cancelled = false; $('#btnStartProcessing').attr("disabled",true); $('#btnStopProcessing').attr("disabled",false); $('#lblResult').html(""); // *** Progress_Ajax is the name of the Progress Control _Ajax for the wwWebAjax instance Progress_Ajax.callMethod("StartProcessing_Callback",[], function(result) { // *** Start the chain - request progress information in timeout seconds window.setTimeout(GetProgress,TimerInterval); }); } function GetProgress() { // *** Iniate a callback to the server to get the progress // *** Pass cancelled flag as parameter so server can now if to cancel Progress_Ajax.callMethod("UpdateProgress_Callback", [Cancelled], // this returns the server's response as an object // result is ProgressEventArgs returned from server function(result) { // Update the progress bar settings UpdateProgressBar("Progress",result.percent,result.message); if (result.cancelled) { alert('Operation cancelled on the server.'); $('#btnStartProcessing').attr("disabled",false); $('#btnStopProcessing').attr("disabled",true); } else if (result.completed || result.percent >= 100) ProcessComplete(); else window.setTimeout( GetProgress, TimerInterval ); }); } function ProcessComplete() { // *** pick up the final result Progress_Ajax.callMethod("ProcessComplete_Callback",[], function(Result) { $('#btnStartProcessing').attr("disabled",false); $('#btnStopProcessing').attr("disabled",true); $("#lblResult").html("<center>" + Result + "</center>"); UpdateProgressBar('Progress',100,"Customer List Download complete"); }); } </script> </form> </body> </html>



Luca,

Can you post the code for your WCSX Page too?

Marty


Dear Marty,
I thank you very much for attention.
I am demoralized because after having spent much time to study Progressbar examples still I am not able to get it working.
I made this example using Rick's WCSX and PRG, I tested to copy a big 50 Mb file for 10 times, but the Progressbar does not progress during copy process, instead the Progressbar shows 10% at the end of copy process. I do not understand what is wrong.


********************** FUNCTION test_click ********************** FOR m.counter=1 TO 10 Session.SetSessionVar("simulate_Counter",TRANSFORM(m.Counter)) ERASE d:\bo.dbf COPY FILE c:\temp\bo.dbf to d:\bo.dbf endfor ENDFUNC ************************************************************************ * progressbar_Page :: StartProcessing **************************************** FUNCTION StartProcessing_Callback() *** Create a counter we can increment and store in Session Session.SetSessionVar("Simulate_Counter","0") *** The ID is not used here, but usually you would *** generate an ID to pass back to the client so *** the client and server have context lcId = SYS(2015) Session.SetSessionVar("progress_Id",lcId) Session.SetSessionVar("progress_StartTime",TRANSFORM(SECONDS())) this.test_click RETURN lcId ENDFUNC ************************************************************************ * progressbar_Page :: UpdateProgress **************************************** FUNCTION UpdateProgress_Callback(llCancel) lnCounter = VAL( Session.GetSessionVar("simulate_Counter") ) LOCAL loArgs as ProgressEventArgs loArgs = CREATEOBJECT("ProgressEventArgs") *** Parameters come back as literal strings only *** so we have to parse 'true' IF llCancel loArgs.Cancelled = .t. loArgs.Percent = lnCounter RETURN loArgs ENDIF *** Completed IF lnCounter >= 100 loArgs.Completed = .T. loArgs.Percent = 100 RETURN loArgs ENDIF *** HERE YOU WOULD NORMALLY DO YOUR CHECKS FOR ASYNCHRONOUS *** OPERATIONS. FOR EXAMPLE, YOU COULD USE wwWebAsyncRequest *** TO OFFLOAD PROCESSING TO ANOTHER PROCESS AND CHECK FOR *** COMPLETION ON THE EXTERNAL PROCESS loArgs.Percent = lnCounter RETURN loArgs



Hello Luca,

Take a look at the sample on the Web site here: http://www.west-wind.com/wconnect/webcontrols/progressBar.wcsx

This sample uses Ajax callbacks to provide what it seems you are wanting. Go to the bottom of the page and use the Show WCSX button and the Show PRG button to see the code in both the Web Page and the Code Behind page.

Perhaps this will help some...

Marty










Viewing all articles
Browse latest Browse all 10393

Trending Articles