Standby Dialog Custom control


<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
  <xp:this.resources>
    <xp:dojoModule name="dojox.widget.Standby"></xp:dojoModule>
  </xp:this.resources>
  <xp:scriptBlock id="scriptBlock1">
  	<xp:this.value><![CDATA[
    //Standby Dialog V.3.2
    //Code Compile by Fredrik Norling www.xpagedeveloper.com
    //used with permission from the authors of the original code
    //http://dontpanic82.blogspot.com/2010/01/xpages-hijackingpublishing-partial.html
    //http://lotusnotus.com/lotusnotus_en.nsf/dx/xpages-tip-a-modal-waiting-dialog-for-background-processes..htm
 var init_hijackAndPublishPartialRefresh=false;
if(typeof hijackAndPublishPartialRefresh != 'function')
 { 
 //Load only once check
 init_hijackAndPublishPartialRefresh=true;
    var obj_hijackAndPublishPartialRefresh=function (){
 // Hijack the partial refresh 

 XSP._inheritedPartialRefresh = XSP._partialRefresh;
 XSP._partialRefresh = function( method, form, refreshId, options ){  
     // Publish init
     dojo.publish( 'partialrefresh-init', [ method, form, refreshId, options ]);
     this._inheritedPartialRefresh( method, form, refreshId, options );
 }
  
 // Publish start, complete and error states 
 dojo.subscribe( 'partialrefresh-init', function( method, form, refreshId, options ){
   
  if( options ){ // Store original event handlers
   var eventOnStart = options.onStart; 
   var eventOnComplete = options.onComplete;
   var eventOnError = options.onError;
  }
 
  options = options || {};  
  options.onStart = function(){
   dojo.publish( 'partialrefresh-start', [ method, form, refreshId, options ]);
   if( eventOnStart ){
    if( typeof eventOnStart === 'string' ){
     eval(eventOnStart)
    } else {
     eventOnStart();
    }
   }
  };
   
  options.onComplete = function(){
   dojo.publish( 'partialrefresh-complete', [ method, form, refreshId, options ]);
   if( eventOnComplete ){
    if( typeof eventOnComplete === 'string' ){
     eval( eventOnComplete );
    } else {
     eventOnComplete();
    }
   }
  };
   
  options.onError = function(){
   dojo.publish( 'partialrefresh-error', [ method, form, refreshId, options ]);
   if( eventOnError ){
    if( typeof eventOnError === 'string' ){
     eval( eventOnError );
    } else {
     eventOnError();
    }
   }
  };
 });
}
hijackAndPublishPartialRefresh=obj_hijackAndPublishPartialRefresh;
}
var StandbyDialog_Do;   
function StandbyDialog_Started() { 
try{
      if(StandbyDialog_Do==true){
          if(this.StandbyDialog_Obj==null) {          
          		  var forms=dojo.body()    				
                  this.StandbyDialog_Obj = new dojox.widget.Standby({ 
                          target: forms,
                          zIndex: 10000
                  }); 
                 document.body.appendChild(this.StandbyDialog_Obj.domNode); 
                 this.StandbyDialog_Obj.startup(); 
          }
          StandbyDialog_StoreField()
          setTimeout("if(StandbyDialog_Do==true){StandbyDialog_StoreField()}",50);
          setTimeout("if(StandbyDialog_Do==true){this.StandbyDialog_Obj.show()}",200); 
      }
      }catch(e){
      console.log("StandbyDialog_Started:"+e.toString())
      }
  }
  function StandbyDialog_StoreField(){
                if(document.activeElement){
  			  sessionStorage.setItem("StandbyDialog_Field",document.activeElement.id)
        	  this.StandbyDialog_Field=document.activeElement.id
                    }
        	  this.StandbyDialog_ScrollX=window.scrollX
        	  this.StandbyDialog_ScrollY=window.scrollY
        
        
  }
  
  function StandbyDialog_Completed() { 
   try{
    StandbyDialog_Do=false
    if(this.StandbyDialog_Obj!=null) this.StandbyDialog_Obj.hide();
    if(this.StandbyDialog_Field===null){return true}
    var ActiveId="";
     if(document.activeElement){
       if(document.activeElement.id){
        	ActiveId=document.activeElement.id;
        }}
    if(this.StandbyDialog_Field!=ActiveId){
    	var prevElement = dojo.byId(this.StandbyDialog_Field);
    	if( prevElement){
    	if('INPUT|SELECT|TEXTAREA'.indexOf(prevElement.nodeName)!=-1){
    			prevElement.focus();
    			if( prevElement.nodeName !== 'SELECT' ){
    					prevElement.select();
    			}
    	}}  	
    }
 	//	XSP.scrollWindow(this.StandbyDialog_ScrollX,this.StandbyDialog_ScrollY)
 	}catch(e){
      console.log("StandbyDialog_Completed:"+e.toString())
      }
  }
  function FieldOnfocus(){
	  console.log(refreshId)
  }
  function StandbyDialog_Enable(){
  try{
	  //dojo-subscribe('onfocus',null,function(method,form,refreshId){FieldOnfocus()})
    dojo.subscribe( 'partialrefresh-start', null, function( method, form, refreshId ){
 
    StandbyDialog_Do=true
   StandbyDialog_Started() 
    } );
    dojo.subscribe( 'partialrefresh-complete', null, function( method, form, refreshId ){
      StandbyDialog_Completed()
      
    } );
    dojo.subscribe( 'partialrefresh-error', null, function( method, form, refreshId ){
      StandbyDialog_Completed()
    } );
    }catch(e){
    console.log(e)
    }
  }

  if(init_hijackAndPublishPartialRefresh==true){
	  hijackAndPublishPartialRefresh()
  }
dojo.addOnLoad(StandbyDialog_Enable)]]></xp:this.value>
  </xp:scriptBlock>

</xp:view>
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
Patrick Kwintensson
(at 06:15 on 27.01.2021)
I would like to see that I could apply a list of component id's that initiate the dialog to appear e.g. only when I hit the submit button. otherwise I experience for a long form with multiple partial refreshes the dialog becomes a bit painfl