2010-01-21 10:51:13 +01:00
|
|
|
/**
|
2010-10-22 12:03:42 +02:00
|
|
|
* LemonLDAP::NG Portal jQuery scripts
|
2010-01-21 10:51:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Used variables
|
|
|
|
* - displaytab
|
2010-10-22 12:03:42 +02:00
|
|
|
* - choicetab
|
2010-01-21 10:51:13 +01:00
|
|
|
* - autocomplete
|
|
|
|
* - login
|
|
|
|
* - newwindow
|
2010-10-22 12:03:42 +02:00
|
|
|
* - antiframe
|
2010-01-21 10:51:13 +01:00
|
|
|
*/
|
|
|
|
|
2010-01-22 17:04:15 +01:00
|
|
|
/* Set autocomplete real value */
|
|
|
|
if(autocomplete.match('1')){autocomplete='on';}
|
|
|
|
if(autocomplete.match('0')){autocomplete='off';}
|
|
|
|
|
2011-01-04 15:35:59 +01:00
|
|
|
/* Set newwindow value (default is false) */
|
2013-09-30 16:00:38 +02:00
|
|
|
if(newwindow.match('1')){newwindow=true;}else{newwindow=false;}
|
2011-01-04 15:35:59 +01:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Set antiframe value (default is true) */
|
2013-09-30 16:00:38 +02:00
|
|
|
if(antiframe.match('0')){antiframe=false;}else{antiframe=true;}
|
2010-10-22 12:03:42 +02:00
|
|
|
|
2010-01-22 17:04:15 +01:00
|
|
|
/* jQuery */
|
2010-01-21 10:51:13 +01:00
|
|
|
$(document).ready(function(){
|
2010-10-22 12:03:42 +02:00
|
|
|
|
|
|
|
/* AntiFrame script */
|
|
|
|
if(antiframe && top!=self){
|
|
|
|
top.location.href = location.href;
|
|
|
|
}
|
|
|
|
|
2012-12-04 17:31:12 +01:00
|
|
|
/* Sortable menu */
|
|
|
|
$("#appslist").sortable({
|
|
|
|
axis: "y",
|
|
|
|
cursor: "move",
|
|
|
|
opacity: 0.5,
|
|
|
|
revert: true,
|
|
|
|
items: "> div.category",
|
2013-07-18 13:04:15 +02:00
|
|
|
update: function(){ getOrder(); }
|
2012-12-04 17:31:12 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
restoreOrder();
|
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Display message */
|
2010-01-21 10:51:13 +01:00
|
|
|
$("div.message").fadeIn('slow');
|
2010-10-22 12:03:42 +02:00
|
|
|
|
|
|
|
/* Set timezone */
|
2010-01-21 10:51:13 +01:00
|
|
|
$("input[name=timezone]").val( -(new Date().getTimezoneOffset()/60) );
|
2010-10-22 12:03:42 +02:00
|
|
|
|
|
|
|
/* Menu tabs */
|
2013-10-28 18:32:41 +01:00
|
|
|
var menuTabs = $("#menu").tabs({active:0});
|
|
|
|
var menuIndex = $('#menu a[href="#'+displaytab+'"]').parent().index();
|
|
|
|
menuTabs.tabs("option","active",menuIndex);
|
2010-09-03 15:21:03 +02:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Authentication choice tabs */
|
2013-10-28 18:32:41 +01:00
|
|
|
var authMenuTabs = $("#authMenu").tabs({active:0});
|
|
|
|
// TODO: cookie
|
2013-10-27 21:11:50 +01:00
|
|
|
//$("#authMenu").tabs({cookie: {name: 'lemonldapauthchoice'}});
|
2013-10-28 18:32:41 +01:00
|
|
|
if(choicetab){
|
|
|
|
var authMenuIndex = $('#authMenu a[href="#'+choicetab+'"]').parent().index();
|
|
|
|
authMenuTabs.tabs("option","active",authMenuIndex);
|
|
|
|
}
|
2010-09-03 15:21:03 +02:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Focus on first visible input */
|
2010-01-21 10:51:13 +01:00
|
|
|
$("input[type!=hidden]:first").focus();
|
2010-10-22 12:03:42 +02:00
|
|
|
if(login){ $("input[type=password]:first").focus(); }
|
2010-09-20 12:39:23 +02:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Password autocompletion */
|
|
|
|
$("input[type='password']").attr("autocomplete",autocomplete);
|
2010-09-20 12:39:23 +02:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Open links in new windows */
|
2011-01-04 15:35:59 +01:00
|
|
|
if(newwindow){ $('#appslist a').attr("target", "_blank"); }
|
2010-08-20 17:07:55 +02:00
|
|
|
|
2010-10-22 12:03:42 +02:00
|
|
|
/* Complete removeOther link */
|
2010-08-20 17:07:55 +02:00
|
|
|
if ($("p.removeOther").length) {
|
|
|
|
var action = $("form.login").attr("action");
|
|
|
|
var method = $("form.login").attr("method");
|
|
|
|
|
2010-08-20 17:36:06 +02:00
|
|
|
var back_url = "";
|
|
|
|
if (action.indexOf("?") != -1) {
|
|
|
|
back_url = action.substring(0,action.indexOf("?")) + "?";
|
|
|
|
} else {
|
|
|
|
back_url = action + "?";
|
|
|
|
}
|
2010-08-20 17:07:55 +02:00
|
|
|
|
|
|
|
$("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);
|
|
|
|
|
|
|
|
}
|
2010-01-21 10:51:13 +01:00
|
|
|
});
|
2010-04-26 15:10:04 +02:00
|
|
|
|
2012-12-04 17:31:12 +01:00
|
|
|
/* Code from http://snipplr.com/view/29434/ */
|
|
|
|
// set the list selector
|
|
|
|
var setSelector = "#appslist";
|
|
|
|
// function that writes the list order to session
|
|
|
|
function getOrder() {
|
|
|
|
// save custom order to persistent session
|
|
|
|
$.ajax({
|
|
|
|
type:"POST",
|
|
|
|
url:scriptname,
|
|
|
|
data:{storeAppsListOrder:$(setSelector).sortable("toArray").join()},
|
2013-07-18 13:04:15 +02:00
|
|
|
dataType:'json'
|
2012-12-04 17:31:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// function that restores the list order from session
|
|
|
|
function restoreOrder() {
|
|
|
|
var list = $(setSelector);
|
|
|
|
if (list == null) return;
|
|
|
|
|
|
|
|
// fetch the session value (saved order)
|
|
|
|
if (!appslistorder) return;
|
|
|
|
|
|
|
|
// make array from saved order
|
|
|
|
var IDs = appslistorder.split(",");
|
|
|
|
|
|
|
|
// fetch current order
|
|
|
|
var items = list.sortable("toArray");
|
|
|
|
|
|
|
|
// make array from current order
|
|
|
|
var rebuild = new Array();
|
|
|
|
for ( var v=0, len=items.length; v<len; v++ ){
|
|
|
|
rebuild[items[v]] = items[v];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0, n = IDs.length; i < n; i++) {
|
|
|
|
|
|
|
|
// item id from saved order
|
|
|
|
var itemID = IDs[i];
|
|
|
|
|
|
|
|
if (itemID in rebuild) {
|
|
|
|
|
|
|
|
// select item id from current order
|
|
|
|
var item = rebuild[itemID];
|
|
|
|
|
|
|
|
// select the item according to current order
|
|
|
|
var child = $(setSelector+".ui-sortable").children("#" + item);
|
|
|
|
|
|
|
|
// select the item according to the saved order
|
|
|
|
var savedOrd = $(setSelector+".ui-sortable").children("#" + itemID);
|
|
|
|
|
|
|
|
// remove all the items
|
|
|
|
child.remove();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
*/
|
2010-04-26 15:10:04 +02:00
|
|
|
function isHiddenFormValueSet(option){
|
|
|
|
if($('#lmhidden_'+option).length){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-10-25 08:25:20 +02:00
|
|
|
function ping() {
|
|
|
|
$.ajax({type:"POST",
|
|
|
|
url:scriptname,
|
|
|
|
data:{ping:1},
|
|
|
|
dataType:'json',
|
|
|
|
success:function(data){
|
|
|
|
if(!data.auth){
|
|
|
|
location.reload(true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
setTimeout('ping();',60000);
|
|
|
|
}
|
|
|
|
}/*,
|
|
|
|
error:function(xhr, ajaxOptions, thrownError){
|
|
|
|
alert('Request failed Error code: '+xhr.status+', '+thrownError);
|
|
|
|
}*/
|
|
|
|
});
|
|
|
|
}
|
2010-10-22 12:03:42 +02:00
|
|
|
|