Massimiliano Assante 2016-11-11 14:39:46 +00:00
parent e89c799746
commit b1e7313be1
4 changed files with 69 additions and 30 deletions

View File

@ -1,6 +1,6 @@
name=d4science-responsive-theme
module-group-id=liferay
module-incremental-version=2
module-incremental-version=3
tags=
short-description=
change-log=

View File

@ -1,27 +0,0 @@
/* The following function simply injects the Liferay object fields userId and scopeGroupId in the XMLHttpRequest header.
* So that every ajax call performed in the page has those parameters set.
* Author: Massimiliano Assante, CNR-ISTI */
function injectClientContext() {
if (Liferay != null) {
var userId;
var groupId;
if (Liferay.ThemeDisplay.isSignedIn()) {
userId = Liferay.ThemeDisplay.getUserId();
groupId = Liferay.ThemeDisplay.getScopeGroupId();
console.log('(d4science responsive) userId is = ' + userId);
console.log("groupId is = " + groupId);
}
else {
groupId = Liferay.ThemeDisplay.getScopeGroupId();
//console.log('Not logged in, injecting groupId only');
}
XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
var newSend = function(vData) {
this.setRequestHeader("gcube-userId", userId);
this.setRequestHeader("gcube-vreid", groupId);
this.realSend(vData);
};
XMLHttpRequest.prototype.send = newSend;
}
}

View File

@ -0,0 +1,47 @@
/*
* Author: Massimiliano Assante, CNR-ISTI
* */
/*The following function simply injects the Liferay object fields userId and scopeGroupId in the XMLHttpRequest header.
* So that every ajax call performed in the page has those parameters set.*/
function injectClientContext() {
if (Liferay != null) {
var userId;
var groupId;
if (Liferay.ThemeDisplay.isSignedIn()) {
userId = Liferay.ThemeDisplay.getUserId();
groupId = Liferay.ThemeDisplay.getScopeGroupId();
console.log("D4S groupId is = " + groupId);
}
else {
groupId = Liferay.ThemeDisplay.getScopeGroupId();
//console.log('Not logged in, injecting groupId only');
}
XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
var newSend = function(vData) {
this.setRequestHeader("gcube-userId", userId);
this.setRequestHeader("gcube-vreid", groupId);
this.realSend(vData);
};
XMLHttpRequest.prototype.send = newSend;
}
}
/*
* Override the expire function of the Liferay.Session javascript object. It makes the default behaviour and then open a modal
* */
$(function () {
AUI().use('liferay-session', function(A) {
console.log('Liferay session overrding');
if(Liferay.Session) {
console.log('Liferay session overridden ON');
Liferay.Session.expire = function() {
var instance = this;
instance.set('sessionState', 'expired', {});
$("#expirationModal").css("display", "block");
$("#expirationModal").modal({backdrop: 'static', keyboard: false},'show');
$("body div.alert.alert-block.popup-alert-warning.alert-error").html("Due to inactivity your session has expired, please <a class='refresh' href=''>Refresh</a>");
};
}
});
});

View File

@ -17,13 +17,32 @@
$theme.include($top_head_include)
<script type="text/javascript" src="$javascript_folder/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="$javascript_folder/gcube-context-injection.js"></script>
<script type="text/javascript" src="$javascript_folder/gcube-context.js"></script>
</head>
<body class="$css_class">
<!-- start customisation -->
<div class="modal" id="expirationModal" tabindex="-1" role="dialog" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="label">Your session expired!</h4>
</div>
<div class="modal-body">
<div style="text-align:center; margin-bottom: 50px;">
<i class="icon-time" style="color: #AAA; font-size: 10em;"></i>
</div>
<div style="font-size: 18px; text-align:center; margin-bottom: 50px;">
Please try <a href="javascript:location.reload();">reload</a> this page or <a href="/c/portal/logout">logout</a>
</div>
</div>
</div>
</div>
</div>
<script>
injectClientContext();
injectClientContext();
</script>
<!-- end customisation -->
<a href="#main-content" id="skip-to-content">#language ("skip-to-content")</a>
$theme.include($body_top_include)