isContentChanged function

If your task allows users to save input values, modified content, or selections, consider defining an isContentChanged function that will check for unsaved changes before z/OSMF closes the task. Doing so prevents users from inadvertently discarding their work.

Invoking the function

The isContentChanged function must be defined off the zosmfExternalTools object. To define the isContentChanged function, use the syntax shown in Figure 1.

Figure 1. Syntax to use for the isContentChanged function
win.global.zosmfExternalTools.isContentChanged = function ( ) {
   //Define your function here.

   //Return either true or false.
   return true|false;
}

z/OSMF core calls the isContentChanged function provided for your task when a user clicks the X icon to close the tab that contains your task or when your task calls the programmaticallyCloseTask function.

Return values

The isContentChanged function returns a Boolean value, which indicates the following:
true
Indicates that changes are pending. In this case, z/OSMF core displays a prompt that warns the user that unsaved changes will be discarded, and gives the user the option to proceed with closing the task or to cancel the close task request. Figure 2 depicts a sample prompt.
Figure 2. Sample confirmation window for a close task request
Depicts sample confirmation window that is displayed for a close task request

  

false
Indicates that no changes are pending. In this case, z/OSMF core closes the task tab and does not display a prompt.
Note: If the zosmfExternalTools object or the isContentChanged function do not exist, z/OSMF core will display a prompt regardless of whether changes are pending.

Example

Suppose your plug-in contains a task that has multiple editable fields on a single page. When the user clicks the X icon to close your task tab, you want to check for changes for each field. Figure 3 provides sample code you can use for this scenario.
Figure 3. Sample code for the isContentChanged function
//Define the default zosmfExternalTools.isContentChanged() function.
function init(){
   win.global.zosmfExternalTools = new zosmfExternalTools();
   win.global.zosmfExternalTools.isContentChanged = function (){
     return false;
   }  			       
}

//When the page is created, call the internal _isContentChanged() function.
postCreate: function() {

   //Define the isContentChanged function.
   var that = this;   
   win.global.zosmfExternalTools.isContentChanged = function (){
     return that._isContentChanged();
   }

},

//Determine if the content was changed.
_isContentChanged: function(){
   ...
},

//When the page is destroyed, restore the default isContentChanged function. 
uninitialize: function() {
   win.global.zosmfExternalTools.isContentChanged = function (){
     return false;
   }              

}