2016-04-18 22:23:38 +02:00
|
|
|
###
|
|
|
|
LemonLDAP::NG Portal jQuery scripts
|
|
|
|
###
|
|
|
|
|
|
|
|
# Translation mechanism
|
2016-05-21 08:52:16 +02:00
|
|
|
|
|
|
|
translationFields = {}
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
translatePage = (lang) ->
|
2016-05-21 08:52:16 +02:00
|
|
|
$.getJSON "#{window.staticPrefix}languages/#{lang}.json", (data) ->
|
|
|
|
translationFields = data
|
|
|
|
$("[trspan]").each ->
|
|
|
|
$(this).text translate $(this).attr 'trspan'
|
2016-05-22 08:58:03 +02:00
|
|
|
$("[trmsg]").each ->
|
|
|
|
$(this).text translate "PE#{$(this).attr 'trmsg'}"
|
2016-03-30 22:57:48 +02:00
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
translate = (str) ->
|
2016-05-21 08:52:16 +02:00
|
|
|
return if translationFields[str] then translationFields[str] else str
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2017-02-08 19:10:06 +01:00
|
|
|
window.translate = translate
|
|
|
|
|
2017-01-19 12:33:11 +01:00
|
|
|
# Initialization variables
|
2017-01-19 07:09:20 +01:00
|
|
|
getValues = () ->
|
|
|
|
values = {}
|
|
|
|
$("script[type='application/init']").each ->
|
|
|
|
try
|
2017-01-19 13:13:36 +01:00
|
|
|
tmp = JSON.parse $(this).text()
|
2017-01-19 07:09:20 +01:00
|
|
|
for k of tmp
|
|
|
|
values[k] = tmp[k]
|
|
|
|
catch e
|
|
|
|
console.log 'Parsing error', e
|
2017-01-19 13:13:36 +01:00
|
|
|
console.log 'JSON', $(this).text()
|
2017-01-19 07:09:20 +01:00
|
|
|
values
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
# Set default values
|
|
|
|
|
|
|
|
# Code from http://snipplr.com/view/29434/
|
|
|
|
# ----------------------------------------
|
|
|
|
setSelector = "#appslist"
|
|
|
|
|
|
|
|
# function that writes the list order to session
|
|
|
|
getOrder = ->
|
|
|
|
$.ajax
|
|
|
|
type: "POST"
|
2017-01-19 12:33:11 +01:00
|
|
|
url: datas['scriptname']
|
2016-04-18 22:23:38 +02:00
|
|
|
data:
|
|
|
|
storeAppsListOrder: $(setSelector).sortable("toArray").join()
|
|
|
|
dataType: 'json'
|
|
|
|
|
|
|
|
# function that restores the list order from session
|
|
|
|
restoreOrder = ->
|
|
|
|
list = $(setSelector)
|
2017-01-19 12:33:11 +01:00
|
|
|
return null unless list? and datas['appslistorder']
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
# make array from saved order
|
2017-01-19 12:33:11 +01:00
|
|
|
IDs = datas['appslistorder'].split ','
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
# fetch current order
|
|
|
|
items = list.sortable "toArray"
|
|
|
|
|
|
|
|
# make array from current order
|
|
|
|
rebuild = []
|
|
|
|
for v in items
|
|
|
|
rebuild[v] = v
|
2017-01-19 22:48:07 +01:00
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
for itemID in IDs
|
|
|
|
if itemID in rebuild
|
|
|
|
|
|
|
|
# select item id from current order
|
|
|
|
item = rebuild[itemID]
|
|
|
|
|
|
|
|
# select the item according to current order
|
|
|
|
child = $(setSelector + ".ui-sortable").children "#" + item
|
|
|
|
|
|
|
|
# select the item according to the saved order
|
|
|
|
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
|
|
|
|
1
|
|
|
|
|
|
|
|
# function boolean isHiddenFormValueSet(string option)
|
|
|
|
# Check if an hidden option is set
|
|
|
|
# @param option Option name
|
|
|
|
# @return true if option is set, false else
|
|
|
|
isHiddenFormValueSet = (option) ->
|
|
|
|
return $('#lmhidden_' + option).length
|
|
|
|
|
|
|
|
# function void ping()
|
|
|
|
# Check if session is alive on server side
|
|
|
|
# @return nothing
|
|
|
|
ping = ->
|
|
|
|
$.ajax
|
|
|
|
type: "POST"
|
2017-01-19 12:33:11 +01:00
|
|
|
url: datas['scriptname']
|
2016-04-18 22:23:38 +02:00
|
|
|
data:
|
|
|
|
ping: 1
|
|
|
|
dataType: 'json'
|
|
|
|
success: (data) ->
|
|
|
|
if data.auth
|
2017-01-19 12:33:11 +01:00
|
|
|
setTimeout ping, datas['pingInterval']
|
2016-04-18 22:23:38 +02:00
|
|
|
else
|
|
|
|
location.reload true
|
|
|
|
|
2016-05-20 19:09:32 +02:00
|
|
|
window.ping = ping
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
# Initialization
|
2017-01-19 12:33:11 +01:00
|
|
|
datas = {}
|
2016-03-30 22:57:48 +02:00
|
|
|
$(document).ready ->
|
2017-01-19 12:33:11 +01:00
|
|
|
datas = getValues()
|
|
|
|
# Export datas for other scripts
|
|
|
|
window.datas = datas
|
|
|
|
if datas['antiframe'] and top != self
|
2016-04-18 22:23:38 +02:00
|
|
|
top.location.href = location.href
|
|
|
|
|
|
|
|
$("#appslist").sortable
|
|
|
|
axis: "y"
|
|
|
|
cursor: "move"
|
|
|
|
opacity: 0.5
|
|
|
|
revert: true
|
|
|
|
items: "> div.category"
|
|
|
|
update: ->
|
|
|
|
getOrder()
|
|
|
|
|
|
|
|
restoreOrder()
|
|
|
|
|
|
|
|
$("div.message").fadeIn 'slow'
|
|
|
|
|
|
|
|
# Set timezone
|
|
|
|
$("input[name=timezone]").val -(new Date().getTimezoneOffset() / 60)
|
|
|
|
|
|
|
|
# Menu tabs
|
|
|
|
menuTabs = $("#menu").tabs
|
|
|
|
active: 0
|
2017-01-19 12:33:11 +01:00
|
|
|
menuIndex = $('#menu a[href="#' + datas['displaytab'] + '"]').parent().index()
|
2016-04-18 22:23:38 +02:00
|
|
|
menuIndex = 0 if menuIndex < 0
|
|
|
|
menuTabs.tabs "option", "active", menuIndex
|
|
|
|
|
|
|
|
# Authentication choice tabs
|
|
|
|
authMenuTabs = $("#authMenu").tabs
|
|
|
|
active: 0
|
|
|
|
|
|
|
|
# TODO: cookie
|
|
|
|
# $("#authMenu").tabs
|
|
|
|
# cookie:
|
|
|
|
# name: 'lemonldapauthchoice'
|
2017-01-19 12:33:11 +01:00
|
|
|
if datas['choicetab']
|
|
|
|
authMenuTabs.tabs "option", "active", $('#authMenu a[href="#' + datas['choicetab'] + '"]').parent().index()
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2017-01-19 12:33:11 +01:00
|
|
|
if datas['login']
|
2016-04-18 22:23:38 +02:00
|
|
|
$("input[type=password]:first").focus()
|
|
|
|
else
|
|
|
|
# Focus on first visible input
|
|
|
|
$("input[type!=hidden]:first").focus()
|
|
|
|
|
|
|
|
# Open links in new windows
|
2017-01-19 12:33:11 +01:00
|
|
|
if datas['newwindow']
|
2016-04-18 22:23:38 +02:00
|
|
|
$('#appslist a').attr "target", "_blank"
|
|
|
|
|
|
|
|
# Complete removeOther link
|
|
|
|
if $("p.removeOther").length
|
|
|
|
action = $("form.login").attr "action"
|
|
|
|
method = $("form.login").attr "method"
|
|
|
|
|
|
|
|
back_url = ""
|
|
|
|
if action.indexOf("?") != -1
|
|
|
|
action.substring(0, action.indexOf("?")) + "?"
|
|
|
|
else
|
|
|
|
back_url = action + "?"
|
|
|
|
|
|
|
|
$("form.login input[type=hidden]").each (index) ->
|
|
|
|
back_url += "&" + $(this).attr("name") + "=" + $(this).val()
|
|
|
|
|
|
|
|
link = $("p.removeOther a").attr("href") + "&method=" + method + "&url=" + btoa(back_url)
|
|
|
|
$("p.removeOther a").attr "href", link
|
|
|
|
|
2016-05-21 08:52:16 +02:00
|
|
|
# Language detection
|
|
|
|
if navigator
|
|
|
|
langs = []
|
|
|
|
langs2 = []
|
|
|
|
nlangs = [ navigator.language ]
|
|
|
|
if navigator.languages
|
|
|
|
nlangs = navigator.languages
|
|
|
|
for nl in nlangs
|
|
|
|
for al in window.availableLanguages
|
|
|
|
if al == nl
|
|
|
|
langs.push al
|
|
|
|
else if al.substring(0, 1) == nl.substring(0, 1)
|
|
|
|
langs2.push al
|
|
|
|
lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else 'en';
|
|
|
|
else
|
|
|
|
lang = 'en'
|
2017-01-19 12:33:11 +01:00
|
|
|
|
|
|
|
# Ping if asked
|
|
|
|
if datas['pingInterval'] and datas['pingInterval'] > 0
|
|
|
|
window.setTimeout ping, datas['pingInterval']
|
2017-01-19 22:48:07 +01:00
|
|
|
|
|
|
|
# Set local dates (used to display history)
|
|
|
|
$(".localeDate").each ->
|
|
|
|
s = new Date($(this).attr("val")*1000)
|
|
|
|
$(this).text s.toLocaleString()
|
2016-03-30 22:57:48 +02:00
|
|
|
translatePage(lang)
|
|
|
|
|