Page 1 of 1

Wait-Screen

Posted: Wed May 27, 2015 7:18 pm
by Peter
Here is a little snippet for showing a Wait-Screen during long time operations (like HTTPRequest()).

The code is using the jquery.msg - Library.

Code: Select all

Procedure.i PageInclude(FileName.s, FileType.s="")
  ; by eddy (http://forums.spiderbasic.com/viewtopic.php?f=9&t=153)
  If FileType = "" : FileType = GetExtensionPart(FileName) : EndIf
  Select LCase(FileType)
    Case "less"
      !$('<link rel="stylesheet/less" type="text/css">').attr('href',v_filename).appendTo('head');
    Case "css"
      !$('<link rel="stylesheet" type="text/css">').attr('href',v_filename).appendTo('head');
    Case "js"
      !$('<script type="text/javascript"></script>').attr('src',v_filename).appendTo('head');
  EndSelect
EndProcedure

PageInclude("jquery.center.min.js")
PageInclude("jquery.msg.css")
PageInclude("jquery.msg.min.js")

Procedure Wait(Flag)
  
  ; http://dreamerslab.com/blog/en/jquery-blockui-alternative-with-jquery-msg-plugin/
  
  If Flag
    ! $.msg({ autoUnblock : false, clickUnblock : false, content : '<center><h1>Please wait...</h1><p>(this window will be closed in 5 Seconds)</p><img src="wait.gif" /></center>' });
  Else
    ! $.msg( 'unblock' );
  EndIf
  
EndProcedure

Enumeration
  #Desktop
  #TestWindow
  #TestButton
  #myTimer
EndEnumeration

Procedure CloseWait()
  
  Wait(#False)
  
  RemoveWindowTimer(#Desktop, #myTimer)
  
EndProcedure

Procedure OpenWait()
  
  Wait(#True)
  
  AddWindowTimer(#Desktop, #myTimer, 5000)
  BindEvent(#PB_Event_Timer, @CloseWait(), #Desktop)
  
EndProcedure

Procedure TestButtonEvent()
  OpenWait()
EndProcedure

OpenWindow(#Desktop, 0, 0, 0, 0, "msg-Demo", #PB_Window_Background)
OpenWindow(#TestWindow, 100, 100, 300, 300, "Test-Window")
ButtonGadget(#TestButton, 10, 10, 200, 30, "Show Wait-Screen")
BindGadgetEvent(#TestButton, @TestButtonEvent())
Here you can see a demo. (The server is a little bit slow)

Here is the complete package to download (~63 KB)

Greetings ... Peter

Re: Wait-Screen

Posted: Tue Jun 02, 2015 9:02 pm
by tj1010
or you could just use asynchronous requests like are in 99% of JS snippets on the internet. I don't even think JQuery supports synchronous AJAX anymore.

Re: Wait-Screen

Posted: Tue Jun 02, 2015 9:48 pm
by Peter
HTTPRequest() is asynchronous.

Greetings ... Peter