This fix should resolve the logout from CKAN before browser window is closed
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@133739 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2d97802fb1
commit
4fa83e2e07
|
@ -7,8 +7,6 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDa
|
|||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.Window.ClosingEvent;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
|
||||
|
||||
|
@ -35,20 +33,131 @@ public class GCubeCkanDataCatalog implements EntryPoint {
|
|||
* This is the entry point method.
|
||||
*/
|
||||
public void onModuleLoad() {
|
||||
performLogoutOnBrowserClosedEvent(CKAN_LOGUT_SERVICE);
|
||||
|
||||
Window.addWindowClosingHandler(new Window.ClosingHandler() {
|
||||
/*Button butt = new Button("Click Me");
|
||||
|
||||
butt.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
performsLogout(CKAN_LOGUT_SERVICE);
|
||||
}
|
||||
});
|
||||
|
||||
RootPanel.get(DIV_PORTLET_ID).add(butt);*/
|
||||
|
||||
/*Window.addWindowClosingHandler(new Window.ClosingHandler() {
|
||||
|
||||
@Override
|
||||
public void onWindowClosing(ClosingEvent closingEvent) {
|
||||
// invoke logout
|
||||
frame.setUrl(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
|
||||
// invoking logout
|
||||
performLogout();
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
GCubeCkanDataCatalogPanel panel = new GCubeCkanDataCatalogPanel(RootPanel.get(DIV_PORTLET_ID), eventManager.getEventBus());
|
||||
eventManager.setPanel(panel);
|
||||
|
||||
frame = new CKanLeaveFrame();
|
||||
DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
|
||||
|
||||
|
||||
}
|
||||
|
||||
// public static native void performsLogout(String logoutService)/*-{
|
||||
//
|
||||
//// var frame = $wnd.frames['i-frame-logout'];
|
||||
//// console.log(frame);
|
||||
//// frame.src = logoutService;
|
||||
// // frame.contentWindow.location.reload();
|
||||
//
|
||||
// var xhttp = new XMLHttpRequest();
|
||||
// xhttp.onreadystatechange = function() {
|
||||
// if (this.readyState == 4 && this.status == 200) {
|
||||
// console.log("OK");
|
||||
// }
|
||||
// };
|
||||
// xhttp.open("GET", logoutService, false);
|
||||
// xhttp.send();
|
||||
// }-*/;
|
||||
|
||||
|
||||
/**
|
||||
* Perform logouton browser closed event.
|
||||
*
|
||||
* @param logoutService the logout service
|
||||
*/
|
||||
public static native void performLogoutOnBrowserClosedEvent(String logoutService)/*-{
|
||||
|
||||
var validNavigation = false;
|
||||
|
||||
function wireUpEvents() {
|
||||
var dont_confirm_leave = 1; //set dont_confirm_leave to 1 when you want the user to be able to leave without confirmation
|
||||
var leave_message = 'You sure you want to leave?'
|
||||
function goodbye(e) {
|
||||
if (!validNavigation) {
|
||||
//PERFORMS A SYNCHRONOUS LOGOUT
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
console.log("OK");
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", logoutService, false);
|
||||
xhttp.send();
|
||||
|
||||
if (dont_confirm_leave!==1) {
|
||||
if(!e) e = window.event;
|
||||
//e.cancelBubble is supported by IE - this will kill the bubbling process.
|
||||
e.cancelBubble = true;
|
||||
e.returnValue = leave_message;
|
||||
//e.stopPropagation works in Firefox.
|
||||
if (e.stopPropagation) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
//return works for Chrome and Safari
|
||||
return leave_message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onbeforeunload=goodbye;
|
||||
|
||||
// Attach the event keypress to exclude the F5 refresh
|
||||
$wnd.$(document).bind('keypress', function(e) {
|
||||
if (e.keyCode == 116){
|
||||
validNavigation = true;
|
||||
console.log("keypress: "+validNavigation);
|
||||
}
|
||||
});
|
||||
|
||||
// Attach the event click for all links in the page
|
||||
$wnd.$("a").bind("click", function() {
|
||||
validNavigation = true;
|
||||
console.log("click: "+validNavigation);
|
||||
});
|
||||
|
||||
// Attach the event submit for all forms in the page
|
||||
$wnd.$("form").bind("submit", function() {
|
||||
validNavigation = true;
|
||||
console.log("form: "+validNavigation);
|
||||
});
|
||||
|
||||
// Attach the event click for all inputs in the page
|
||||
$wnd.$("input[type=submit]").bind("click", function() {
|
||||
validNavigation = true;
|
||||
console.log("submit: "+validNavigation);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Wire up the events as soon as the DOM tree is ready
|
||||
$wnd.$(document).ready(function() {
|
||||
wireUpEvents();
|
||||
});
|
||||
|
||||
}-*/;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue