shouldClose function
When a close task request is submitted, if your task needs to perform cleanup actions or collect information from users before z/OSMF closes the task, consider defining a shouldClose function to override requests to close your task. Doing so gives your task an unlimited amount of time to perform the actions, and allows your task to inform z/OSMF when it is ready to be closed.
Invoking the function
z/OSMF core calls the shouldClose function provided for your task when a user clicks the X icon to close the tab that contains your task. The shouldClose function must be defined off the zosmfExternalTools object. To define the shouldClose function, use the syntax shown in Figure 1.
Figure 1. Syntax
to use for the shouldClose function
win.global.zosmfExternalTools.shouldClose = function ( ) {
//Define your function here.
//Return either true or false.
return true|false;
}
Return values
The shouldClose function returns a Boolean value, which indicates the following:
- true
- Indicates that z/OSMF core should close the task.
- false
- Indicates that z/OSMF core
should not close the task at this time. The task will submit a close
task request when it is ready to be closed. Return false if
you need to perform additional steps or cleanup before closing the
task. The task will remain open until your task calls the programmaticallyCloseTab
function. Tip: There is no time limit on how long the tab can remain open after a user requests for it to be closed. If the additional actions will take more than a few seconds to complete, consider providing an indicator so that users know the close request is being processed.
Note: If the zosmfExternalTools object or the shouldClose function
do not exist, z/OSMF core
will close the task.
Example
var functionToCall = function(){
//Task tab is now open indefinitely.
//Perform all cleanup work.
....
//When its finished, call the programmaticallyCloseTab function.
win.global.zosmfExternalTools.programmaticallyCloseTab(myPluginId,myTaskId);
}
win.global.zosmfExternalTools.shouldClose = function(){
if(longCleanupNeeded){
//If cleanup actions will take longer than one second,
//call the shouldClose function, and sSet the cleanup
//function to start asynchronously after the shouldClose
//function returns false.
setTimeout(functionToCall,5);
return false;
}else{
//if we dont need more time and should close
return true;
}
}