lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/portal.js

218 lines
4.9 KiB
JavaScript
Raw Normal View History

/**
2010-10-22 12:03:42 +02:00
* LemonLDAP::NG Portal jQuery scripts
*/
/* Used variables
* - displaytab
2010-10-22 12:03:42 +02:00
* - choicetab
* - login
* - newwindow
2010-10-22 12:03:42 +02:00
* - antiframe
*/
/* Set newwindow value (default is false) */
2014-02-05 17:30:30 +01:00
if (newwindow.match('1')) {
2016-01-21 12:36:23 +01:00
newwindow = true;
2014-02-05 17:30:30 +01:00
} else {
2016-01-21 12:36:23 +01:00
newwindow = false;
2014-02-05 17:30:30 +01:00
}
2010-10-22 12:03:42 +02:00
/* Set antiframe value (default is true) */
2014-02-05 17:30:30 +01:00
if (antiframe.match('0')) {
2016-01-21 12:36:23 +01:00
antiframe = false;
2014-02-05 17:30:30 +01:00
} else {
2016-01-21 12:36:23 +01:00
antiframe = true;
2014-02-05 17:30:30 +01:00
}
2010-10-22 12:03:42 +02:00
/* Set activeTimer value (default is true) */
if (activeTimer.match('0')) {
2016-01-21 12:36:23 +01:00
activeTimer = false;
} else {
2016-01-21 12:36:23 +01:00
activeTimer = true;
}
/* jQuery */
2014-02-05 17:30:30 +01:00
$(document).ready(function() {
2010-10-22 12:03:42 +02:00
2016-01-21 12:36:23 +01:00
/* AntiFrame script */
if (antiframe && top != self) {
top.location.href = location.href;
}
/* Sortable menu */
$("#appslist").sortable({
axis: "y",
cursor: "move",
opacity: 0.5,
revert: true,
items: "> div.category",
update: function() {
getOrder();
}
});
restoreOrder();
/* Display message */
$("div.message").fadeIn('slow');
/* Set timezone */
$("input[name=timezone]").val(-(new Date().getTimezoneOffset() / 60));
/* Menu tabs */
var menuTabs = $("#menu").tabs({
active: 0
});
var menuIndex = $('#menu a[href="#' + displaytab + '"]').parent().index();
if (menuIndex < 0) {
menuIndex = 0;
}
menuTabs.tabs("option", "active", menuIndex);
/* Authentication choice tabs */
var authMenuTabs = $("#authMenu").tabs({
active: 0
});
// TODO: cookie
//$("#authMenu").tabs({cookie: {name: 'lemonldapauthchoice'}});
if (choicetab) {
var authMenuIndex = $('#authMenu a[href="#' + choicetab + '"]').parent().index();
authMenuTabs.tabs("option", "active", authMenuIndex);
}
/* Focus on first visible input */
$("input[type!=hidden]:first").focus();
if (login) {
$("input[type=password]:first").focus();
}
/* Open links in new windows */
if (newwindow) {
$('#appslist a').attr("target", "_blank");
}
/* Complete removeOther link */
if ($("p.removeOther").length) {
var action = $("form.login").attr("action");
var method = $("form.login").attr("method");
var back_url = "";
if (action.indexOf("?") != -1) {
back_url = action.substring(0, action.indexOf("?")) + "?";
} else {
back_url = action + "?";
}
$("form.login input[type=hidden]").each(function(index) {
back_url = back_url + "&" + $(this).attr("name") + "=" + $(this).val();
});
var link = $("p.removeOther a").attr("href");
link = link + "&method=" + method + "&url=" + $.base64Encode(back_url);
$("p.removeOther a").attr("href", link);
}
});
/* Code from http://snipplr.com/view/29434/ */
// set the list selector
var setSelector = "#appslist";
// function that writes the list order to session
function getOrder() {
2016-01-21 12:36:23 +01:00
// save custom order to persistent session
$.ajax({
type: "POST",
url: scriptname,
data: {
storeAppsListOrder: $(setSelector).sortable("toArray").join()
},
dataType: 'json'
});
}
// function that restores the list order from session
function restoreOrder() {
2016-01-21 12:36:23 +01:00
var list = $(setSelector);
if (list == null) return;
2016-01-21 12:36:23 +01:00
// fetch the session value (saved order)
if (!appslistorder) return;
2016-01-21 12:36:23 +01:00
// make array from saved order
var IDs = appslistorder.split(",");
2016-01-21 12:36:23 +01:00
// fetch current order
var items = list.sortable("toArray");
2016-01-21 12:36:23 +01:00
// make array from current order
var rebuild = new Array();
for (var v = 0, len = items.length; v < len; v++) {
rebuild[items[v]] = items[v];
}
2016-01-21 12:36:23 +01:00
for (var i = 0, n = IDs.length; i < n; i++) {
2016-01-21 12:36:23 +01:00
// item id from saved order
var itemID = IDs[i];
2016-01-21 12:36:23 +01:00
if (itemID in rebuild) {
2016-01-21 12:36:23 +01:00
// select item id from current order
var item = rebuild[itemID];
2016-01-21 12:36:23 +01:00
// select the item according to current order
var child = $(setSelector + ".ui-sortable").children("#" + item);
2016-01-21 12:36:23 +01:00
// select the item according to the saved order
var savedOrd = $(setSelector + ".ui-sortable").children("#" + itemID);
2016-01-21 12:36:23 +01:00
// remove all the items
child.remove();
2016-01-21 12:36:23 +01:00
// add the items in turn according to saved order
// we need to filter here since the "ui-sortable"
// class is applied to all ul elements and we
// only want the very first! You can modify this
// to support multiple lists - not tested!
$(setSelector + ".ui-sortable").filter(":first").append(savedOrd);
}
}
}
2010-10-22 12:03:42 +02:00
/* function boolean isHiddenFormValueSet(string option)
* Check if an hidden option is set
* @param option Option name
* @return true if option is set, false else
*/
2014-02-05 17:30:30 +01:00
function isHiddenFormValueSet(option) {
2016-01-21 12:36:23 +01:00
if ($('#lmhidden_' + option).length) {
return true;
} else {
return false;
}
}
2014-02-06 16:55:27 +01:00
/* function void ping()
* Check if session is alive on server side
* @return nothing
*/
function ping() {
2016-01-21 12:36:23 +01:00
$.ajax({
type: "POST",
url: scriptname,
data: {
ping: 1
},
dataType: 'json',
success: function(data) {
if (!data.auth) {
location.reload(true);
}
else {
setTimeout('ping();', pingInterval);
}
}
});
}