JSDO properties, methods, and events reference : logout( ) method (JSDOSession class)
  

logout( ) method (JSDOSession class)

Note: Updated for Progress Data Objects Version 4.4.1 and later.
Terminates the login session on the web application managed by the current JSDOSession object and leaves the object available to start a new login session with a call to its login( ) method.
This method throws an error if the underlying communication layer throws an error.
On a successful logout, the JSDOSession object sets its connected property to false. If the logout fails, the object leaves its connected property set to true, unless the failure happened because the app cannot access the server.
Once logout( ) is executed, no further communication (other than a login( ) call) can occur between the mobile app and the server using this JSDOSession object. However, any catalogs loaded in the object remain available to create and maintain JSDOs, though these JSDOs cannot make requests to the server until a new login session is established for the object (including for anonymous access).
This method is always executed asynchronously and returns results in callbacks that you register using methods of a Promise object returned as the method value.
Note: In order to invoke this method successfully, jQuery Promises must be supported in your development environment. Otherwise, the method throws an exception.
Note: If you do not need to reuse the current JSDOSession instance, you can call invalidate( ) (instead of logout( )) to permanently disable the instance and prevent any additional calls to its login( ) method. If you want to permanently disable all current JSDOSession instances, you can also call invalidateAllSessions( ) instead.
Return type: jQuery Promise
Applies to: progress.data.JSDOSession class

Syntax

logout ( )

Promise method signatures

jQuery Promise objects define methods that register a callback function with a specific signature. The callback signatures depend on the method that returns the Promise. Following are the signatures of callbacks registered by methods in any Promise object that logout( ) returns:
Syntax:
promise.done( function ( session , result , info ) )
promise.fail( function ( session , result , info ) )
promise.always( function ( session , result , info ) )
promise
A reference to the Promise object that is returned as the value of the logout( ) method. For more information on Promises, see the notes on Promises in the description of the progress.data.JSDOSession class.
session
A reference to the JSDOSession object on which logout( ) was called.
result
A constant indicating the overall result of the call that can have one of the following values:
*progress.data.Session.SUCCESS — The session logout completed successfully.
*progress.data.Session.GENERAL_FAILURE — The session logout failed because of some error.
Note: It is not always necessary to test the value of result in a Promise method callback for the logout( ) method, especially if the callback is registered using promise.done( ) or promise.fail( ), where the callback always executes with the same value (progress.data.Session.SUCCESS and progress.data.Session.GENERAL_FAILURE, respectively).
info
A JavaScript object that can have the following properties:
*errorObject — An error object thrown while attempting to terminate the login session.
*xhr — A reference to the XMLHttpRequest object sent to the web server to terminate the login session.

Detailed logout behavior

When this method terminates the associated login session, the JSDOSession object can be re-used to start a new session using the same serviceURI and authenticationModel configuration settings originally passed to the object's constructor. The JSDOSession object's properties retain their values from the previous login session, with the following exceptions:
*clientContextId is reset to null.
*loginHttpStatus is reset to null.
*loginResult is reset to null.
*userName is reset to null.
Existing JSDOs and catalog information are not affected by a successful execution of logout( ). However, any attempt to call addCatalog( ) or a JSDO method that requires contacting the server results in an error object being thrown.

Example

The following code fragment calls the logout( ) method on the JSDOsession object, session. This example uses try and catch blocks in case logout( ) throws an unexpected exception, and displays messages returned from Promise handlers accordingly:
var serviceURI = "http://oemobiledemo.progress.com/OEMobileDemoServicesForm/",
session = new progress.data.JSDOSession({
"authenticationModel": progress.data.Session.AUTH_TYPE_FORM,
"serviceURI": serviceURI
});

try { // Login, add catalogs, create additional JSDO instances,
// and do JSDO tasks for this session, ...then(...) ...
session.logout()
.then(function(session, result, info) {
// Success handler of logout
return "Employee session logged out successfully";
}, function(session, result, info) {
// Failure handler of logout
if ( result === progress.data.Session.GENERAL_FAILURE ) {
if ( info.errorObject ) {
// Process error object thrown during logout...
}
if ( info.xhr ) {
// Process XHR sent during logout...
}
return "Employee session logout failed. Unspecified error.";
}
else {
return "Unexpected failed logout result";
}
})
.then(function (msg) {
console.log(msg);
});
}
catch(ex) {
console.log("There was an unexpected error from attempted logout: " + ex);
}

See also:

invalidate( ) method, invalidateAllSessions( ) stand-alone function, login( ) method (JSDOSession class), offline event, online event