plugins.busy.block() -- having a tough time

I’m having difficulty understanding how to initiate the busy plugin. It seems like there is no call to it in the actual looping method, so how then does it get called? What if I have many looping methods on the same form?

When I try to run this, it drops into the catch. If I take out the plugin calls, the method itself reverts to working.

Thank you,
Don


I created this global method,

function UTIL_startBusy(activeFunction, messageText, cancelBtnText, dialogName) {	
	if(activeFunction) {
		var params = { 			
			processFunctionName: activeFunction, 
			opacity: 0.5,
			paneColor: '#000000',
			textColor: '#FF0000'
		}
		
		if(messageText) {
			params.message = messageText;
	    }
	    if(cancelBtnText) {
	    	params.showCancelButton = true; 
	    	params.cancelButtonText = cancelBtnText;
	    }
	    if(dialogName) {  
	    	params.dialogName = dialogName;
	    }
	    plugins.busy.block(params);
	}
}

onShow for base form (where the loop is located),

function onShow_browse_form(firstShow, event) {		
	var recs = 0;
	if(firstShow == true) {			
		if (application.getApplicationType() == APPLICATION_TYPES.WEB_CLIENT) {  // 7.31.2012
		    plugins.busy.prepare();
		}		
		vBrowseWelcome = 'Welcome ' + current_user_to_user_info.usr_user_name + ' / ' + current_selpa_to_system_settings.sys_selpa_name;
		if(current_user_to_user_info.usr_privilege_level) {
			if(current_user_to_user_info.usr_privilege_level.match(/administrator/i)) {
				vBrowseWelcome += " (administrator)";
			} else if(current_user_to_user_info.usr_privilege_level.match(/teacher/i)) {
				vBrowseWelcome += " (teacher/provider)";
			} else if(current_user_to_user_info.usr_privilege_level.match(/read-only/i)) {
				vBrowseWelcome += " (read only)";
			}
		}
		forms.browse_form.elements.tabs_150.dividerLocation = 130; // this is the *horizontal* divider from the left tab panel	
		onAction_studentsTab(event);  // default is to students browse
	} else { // not firstShow
		browse_vBrowseInfo_set();  // change the record display at form bottom, as needed
	}
}

Here is the looping method, on the base form (Reader’s Digest condensation),

function browse_complianceTimeline() {
       // This calls a dialog where the user selects options for the loop. When the
       // user clicks on OK, the dialog script destroys its own window, and calls browse_complianceTimeline2 (below). 
	var win = application.createWindow("complTimeDlg",JSWindow.MODAL_DIALOG);
	win.title = "Compliance timeline...";
	win.show("complianceCalcBatch_dlg");
}

function browse_complianceTimeline2() {	
      // (define variables and get preferences from browse_complianceTimeline dialog
     	recs = databaseManager.getFoundSetCount(fsStd);
	if(recs == 0) {
		tempText = "Could not find any eligible students, for whom to calculate compliance. "
		globals.UTIL_alertDlg(tempText,"Compliance timeline...",null);		
	} else {		
		try {
			application.updateUI();			
			globals.UTIL_startBusy(forms.browse_form.browse_complianceTimeline2,"Calculating compliance...","Cancel",null);
			var aProblems = new Array();
			for(i = 1 ; i <= recs ; i++) {  // for each student
                              // validate and process each record; there are a second set of "j" loops in this section
                        	if (plugins.busy.isCanceled()) {					
					studentErrorText = fsStd.std_record_number + " - " + fsStd.std_name_last + ", " + fsStd.std_name_first + " (user cancel on this student, no further evaluations)."
					aProblems.push(studentErrorText);
				    break;
				}
                        }  // loop for each student
      } catch (e) {
          failText = "Could not complete search for student compliance (contact administrator).";				
     } finally {
	plugins.busy.unblock();
     }

The processFunctionName property of the params should be replaced with processFunction and be a function that contains the ‘long running process’.

And plugins.busy.block(params); should not be called in your long running process…
The busy plugin will call your function itself.

So your dialog should probably call (when the user clicks OK:

globals.UTIL_startBusy(forms.browse_form.browse_complianceTimeline2,"Calculating compliance...","Cancel",null);

And the complianceTimeline2 function should probably be modified to something like this:

function browse_complianceTimeline2() {
    application.updateUI(); 
    // (define variables and get preferences from browse_complianceTimeline dialog
    recs = databaseManager.getFoundSetCount(fsStd);
    if(recs == 0) {
        plugins.busy.unblock();
        application.updateUI(); 
        tempText = "Could not find any eligible students, for whom to calculate compliance. "
        globals.UTIL_alertDlg(tempText,"Compliance timeline...",null);      
    } else {   
        try {       
            var aProblems = new Array();
            for(i = 1 ; i <= recs ; i++) {  // for each student
                // validate and process each record; there are a second set of "j" loops in this section
                if (plugins.busy.isCanceled()) {               
                   studentErrorText = fsStd.std_record_number + " - " + fsStd.std_name_last + ", " + fsStd.std_name_first + " (user cancel on this student, no further evaluations)."
                   aProblems.push(studentErrorText);
                   break;
                }
             }  // loop for each student
        } catch (e) {
             failText = "Could not complete search for student compliance (contact administrator).";            
        } finally {
             plugins.busy.unblock();
        }
    }
}

I changed the code more-or-less the way you suggested, and have been successful in getting it to work :)

When is the application.updateUI() needed, if at all?

Thanks so much,
Don

application.updateUI() is needed to give a chance to the busy plugin to show its glass pane, if you don’t put it as the first call of your method, the UI will be blocked but the busy pane won’t show…