2016-04-18 22:23:38 +02:00
|
|
|
###
|
|
|
|
LemonLDAP::NG Portal jQuery scripts
|
|
|
|
###
|
|
|
|
|
|
|
|
# Translation mechanism
|
2016-05-21 08:52:16 +02:00
|
|
|
|
|
|
|
translationFields = {}
|
|
|
|
|
2017-10-10 17:23:41 +02:00
|
|
|
# Launched at startup: download language JSON and translate all HTML tags that
|
|
|
|
# contains one of the following attributes using translate() function:
|
|
|
|
# - trspan : set result in tag content
|
|
|
|
# - trmsg : get error number and set result of PE<number> result in tag
|
|
|
|
# content
|
|
|
|
# - trplaceholder: set result in "placeholder" attribute
|
|
|
|
# - localtime : transform time (in ms)ing translate()
|
2022-02-01 17:09:15 +01:00
|
|
|
|
|
|
|
setDanger = (cond, field) ->
|
|
|
|
result = false
|
|
|
|
if cond
|
|
|
|
$("##{field}").addClass 'fa-check text-success'
|
|
|
|
$("##{field}").removeClass 'fa-times text-danger'
|
|
|
|
$("##{field}").attr 'role', 'status'
|
|
|
|
else
|
|
|
|
$("##{field}").addClass 'fa-times text-danger'
|
|
|
|
$("##{field}").removeClass 'fa-check text-success'
|
|
|
|
$("##{field}").attr 'role', 'alert'
|
|
|
|
result = true
|
|
|
|
result
|
|
|
|
|
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
|
2018-10-17 10:49:00 +02:00
|
|
|
for k,v of window.datas.trOver.all
|
|
|
|
translationFields[k] = v
|
|
|
|
if window.datas.trOver[lang]
|
|
|
|
for k,v of window.datas.trOver[lang]
|
|
|
|
translationFields[k] = v
|
2016-05-21 08:52:16 +02:00
|
|
|
$("[trspan]").each ->
|
2017-02-15 20:13:03 +01:00
|
|
|
args = $(this).attr('trspan').split(',')
|
2017-02-16 08:37:47 +01:00
|
|
|
txt = translate args.shift()
|
2017-02-15 20:13:03 +01:00
|
|
|
for v in args
|
2017-06-28 17:49:59 +02:00
|
|
|
txt = txt.replace /%[sd]/, v
|
2019-05-17 08:05:36 +02:00
|
|
|
$(this).html txt
|
2016-05-22 08:58:03 +02:00
|
|
|
$("[trmsg]").each ->
|
2019-05-17 08:05:36 +02:00
|
|
|
$(this).html translate "PE#{$(this).attr 'trmsg'}"
|
2019-02-26 23:03:30 +01:00
|
|
|
msg = translate "PE#{$(this).attr 'trmsg'}"
|
2019-02-27 09:49:58 +01:00
|
|
|
if msg.match /_hide_/
|
2019-02-26 23:03:30 +01:00
|
|
|
$(this).parent().hide()
|
2017-03-14 12:04:05 +01:00
|
|
|
$("[trplaceholder]").each ->
|
2022-02-01 17:20:17 +01:00
|
|
|
tmp = translate($(this).attr('trplaceholder'))
|
|
|
|
$(this).attr 'placeholder', tmp
|
|
|
|
$(this).attr 'aria-label', tmp
|
2017-03-15 22:20:10 +01:00
|
|
|
$("[localtime]").each ->
|
|
|
|
d = new Date $(this).attr('localtime') * 1000
|
|
|
|
$(this).text d.toLocaleString()
|
2016-03-30 22:57:48 +02:00
|
|
|
|
2017-10-10 17:23:41 +02:00
|
|
|
# Translate a string
|
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-10-10 17:23:41 +02:00
|
|
|
# Initialization variables: read all <script type="application/init"> tags and
|
|
|
|
# return JSON parsing result. This is set in window.data variable
|
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()
|
2019-02-19 22:51:45 +01:00
|
|
|
console.log values
|
2017-01-19 07:09:20 +01:00
|
|
|
values
|
|
|
|
|
2020-07-24 18:11:07 +02:00
|
|
|
# Gets a query string parametrer
|
|
|
|
# We cannot use URLSearchParam because of IE (#2230)
|
|
|
|
getQueryParam = (name) ->
|
|
|
|
match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search)
|
|
|
|
if match then decodeURIComponent(match[1].replace(/\+/g, ' ')) else null
|
|
|
|
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
# Code from http://snipplr.com/view/29434/
|
|
|
|
# ----------------------------------------
|
|
|
|
setSelector = "#appslist"
|
|
|
|
|
2018-07-15 22:08:30 +02:00
|
|
|
# Function to write the sorted apps list to session (network errors ignored)
|
2017-09-18 21:10:01 +02:00
|
|
|
setOrder = ->
|
2017-09-18 22:40:01 +02:00
|
|
|
setKey '_appsListOrder', $(setSelector).sortable("toArray").join()
|
|
|
|
|
2017-09-19 19:01:19 +02:00
|
|
|
# Function used to remove an OIDC consent
|
2017-09-18 22:40:01 +02:00
|
|
|
removeOidcConsent = (partner) ->
|
2018-06-20 21:38:26 +02:00
|
|
|
#r = new RegExp "\b#{partner}\b,?", 'g'
|
|
|
|
#datas['oidcConsents'] = datas['oidcConsents'].replace(r,'').replace(/,$/,'')
|
|
|
|
#setKey '_oidcConnectedRP', datas['oidcConsents']
|
|
|
|
# # Success
|
|
|
|
# , () ->
|
|
|
|
# $("[partner='#{partner}']").hide()
|
|
|
|
# # Error
|
|
|
|
# , (j,s,e) ->
|
|
|
|
# alert "#{s} #{e}"
|
|
|
|
e = (j,s,e) ->
|
|
|
|
alert "#{s} #{e}"
|
2018-07-15 22:08:30 +02:00
|
|
|
delKey "_oidcConsents",partner
|
2017-09-19 19:01:19 +02:00
|
|
|
# Success
|
|
|
|
, () ->
|
2018-07-15 22:08:30 +02:00
|
|
|
$("[partner='#{partner}']").hide()
|
|
|
|
# Error
|
2018-06-20 21:38:26 +02:00
|
|
|
, e
|
2017-09-18 22:40:01 +02:00
|
|
|
|
2017-09-19 19:01:19 +02:00
|
|
|
# Function used by setOrder() and removeOidcConsent() to push new values
|
|
|
|
# For security reason, modification is rejected unless a valid token is given
|
|
|
|
setKey = (key,val,success,error) ->
|
|
|
|
# First request to get token
|
2016-04-18 22:23:38 +02:00
|
|
|
$.ajax
|
2017-09-18 22:40:01 +02:00
|
|
|
type: "GET"
|
|
|
|
url: datas['scriptname'] + '/mysession/?gettoken'
|
2016-04-18 22:23:38 +02:00
|
|
|
dataType: 'json'
|
2017-09-19 19:01:19 +02:00
|
|
|
error: error
|
|
|
|
# On success, value is set
|
2017-09-18 22:40:01 +02:00
|
|
|
success: (data) ->
|
|
|
|
d =
|
|
|
|
token: data.token
|
|
|
|
d[key] = val
|
|
|
|
$.ajax
|
|
|
|
type: "PUT"
|
|
|
|
url: datas['scriptname'] + '/mysession/persistent'
|
|
|
|
dataType: 'json'
|
|
|
|
data: d
|
2017-09-19 19:01:19 +02:00
|
|
|
success: success
|
|
|
|
error: error
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2018-07-17 18:15:17 +02:00
|
|
|
delKey = (key,sub,success,error) ->
|
2018-06-20 21:38:26 +02:00
|
|
|
$.ajax
|
|
|
|
type: "GET"
|
|
|
|
url: datas['scriptname'] + '/mysession/?gettoken'
|
|
|
|
dataType: 'json'
|
|
|
|
error: error
|
|
|
|
# On success, value is set
|
|
|
|
success: (data) ->
|
|
|
|
$.ajax
|
|
|
|
type: "DELETE"
|
2018-07-17 18:15:17 +02:00
|
|
|
url: "#{datas['scriptname']}/mysession/persistent/#{key}?sub=#{sub}&token=#{data.token}"
|
2018-06-20 21:38:26 +02:00
|
|
|
dataType: 'json'
|
|
|
|
success: success
|
|
|
|
error: error
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
# 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
|
2017-09-05 16:40:52 +02:00
|
|
|
if rebuild[itemID]
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
# select item id from current order
|
2017-09-05 16:40:52 +02:00
|
|
|
item = rebuild[itemID]
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
# 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) ->
|
2017-02-19 12:45:26 +01:00
|
|
|
if data.result? and data.result == 1
|
2017-01-19 12:33:11 +01:00
|
|
|
setTimeout ping, datas['pingInterval']
|
2016-04-18 22:23:38 +02:00
|
|
|
else
|
|
|
|
location.reload true
|
2017-02-19 12:45:26 +01:00
|
|
|
error: (j,t,e) ->
|
|
|
|
location.reload true
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2016-05-20 19:09:32 +02:00
|
|
|
window.ping = ping
|
|
|
|
|
2017-10-10 17:23:41 +02:00
|
|
|
# Functions to get/set a cookie value
|
2017-02-16 08:37:47 +01:00
|
|
|
getCookie = (cname) ->
|
|
|
|
name = cname + "="
|
|
|
|
ca = decodeURIComponent(document.cookie).split ';'
|
|
|
|
re = new RegExp('^ *'+cname+'=')
|
|
|
|
for c in ca
|
|
|
|
if c.match re
|
|
|
|
c = c.replace re, ''
|
|
|
|
return c
|
|
|
|
return ''
|
|
|
|
|
2021-09-14 22:36:36 +02:00
|
|
|
setCookie = (name, value, samesite, exdays) ->
|
2017-02-16 08:37:47 +01:00
|
|
|
d = new Date()
|
|
|
|
d.setTime d.getTime() + exdays*86400000
|
2021-09-14 22:36:36 +02:00
|
|
|
document.cookie = "#{name}=#{value}; expires=#{d.toUTCString()}; path=/; SameSite=#{samesite}"
|
2017-02-16 08:37:47 +01:00
|
|
|
|
2017-09-19 22:59:29 +02:00
|
|
|
# Function to change password using Ajax (instead of POST)
|
2017-10-10 17:23:41 +02:00
|
|
|
# NOT USED FOR NOW
|
2017-09-19 22:59:29 +02:00
|
|
|
#changePwd = (event) ->
|
2021-01-30 23:21:24 +01:00
|
|
|
# event.preventDefault()
|
2017-09-19 22:59:29 +02:00
|
|
|
# $.ajax
|
|
|
|
# type: 'POST'
|
|
|
|
# url: datas['scriptname']
|
|
|
|
# dataType: 'json'
|
|
|
|
# data:
|
|
|
|
# oldpassword: $('#oldpassword').val()
|
|
|
|
# newpassword: $('#newpassword').val()
|
|
|
|
# confirmpassword: $('#confirmpassword').val()
|
|
|
|
# success: (data) ->
|
|
|
|
# console.log "R", data
|
|
|
|
|
2016-04-18 22:23:38 +02:00
|
|
|
# Initialization
|
2017-01-19 12:33:11 +01:00
|
|
|
datas = {}
|
2020-04-29 23:45:25 +02:00
|
|
|
|
2019-09-15 22:15:34 +02:00
|
|
|
$(window).on 'load', () ->
|
2017-10-10 17:23:41 +02:00
|
|
|
# Get application/init variables
|
2017-01-19 12:33:11 +01:00
|
|
|
datas = getValues()
|
2020-03-27 19:03:56 +01:00
|
|
|
|
|
|
|
# Keep the currently selected tab
|
|
|
|
if "datas" of window && "choicetab" of window.datas
|
|
|
|
datas.choicetab = window.datas.choicetab;
|
|
|
|
|
2017-01-19 12:33:11 +01:00
|
|
|
# Export datas for other scripts
|
|
|
|
window.datas = datas
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
$("#appslist").sortable
|
|
|
|
axis: "y"
|
|
|
|
cursor: "move"
|
|
|
|
opacity: 0.5
|
|
|
|
revert: true
|
|
|
|
items: "> div.category"
|
|
|
|
update: ->
|
2017-09-18 21:10:01 +02:00
|
|
|
setOrder()
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
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
|
2020-03-11 11:46:14 +01:00
|
|
|
authMenuIndex = $('#authMenu a[href="#' + datas['displaytab'] + '"]').parent().index()
|
|
|
|
authMenuIndex = 0 if authMenuIndex < 0
|
|
|
|
authMenuTabs.tabs "option", "active", authMenuIndex
|
2016-04-18 22:23:38 +02:00
|
|
|
|
|
|
|
# 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
|
2019-07-31 18:30:16 +02:00
|
|
|
# If there are no auto-focused fields, focus on first visible input
|
|
|
|
if $("input[autofocus]").length == 0
|
|
|
|
$("input[type!=hidden]:first").focus();
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2017-10-10 17:23:41 +02:00
|
|
|
# Open links in new windows if required
|
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
|
2020-04-24 21:27:23 +02:00
|
|
|
action = $("#form").attr "action"
|
|
|
|
method = $("#form").attr "method"
|
|
|
|
console.log 'method=', method
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2020-04-24 21:27:23 +02:00
|
|
|
hiddenParams = ""
|
2020-04-25 11:41:08 +02:00
|
|
|
if $("#form input[type=hidden]")
|
|
|
|
console.log 'Parse hidden values'
|
|
|
|
$("#form input[type=hidden]").each (index) ->
|
|
|
|
console.log ' ->', $(this).attr("name"), $(this).val()
|
|
|
|
hiddenParams += "&" + $(this).attr("name") + "=" + $(this).val()
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2020-04-24 21:27:23 +02:00
|
|
|
back_url = ""
|
|
|
|
if action
|
|
|
|
console.log 'action=', action
|
|
|
|
if action.indexOf("?") != -1
|
|
|
|
action.substring(0, action.indexOf("?")) + "?"
|
|
|
|
else
|
|
|
|
back_url = action + "?"
|
|
|
|
back_url += hiddenParams
|
|
|
|
hiddenParams = ""
|
2016-04-18 22:23:38 +02:00
|
|
|
|
2020-04-25 11:41:08 +02:00
|
|
|
link = $("p.removeOther a").attr("href") + "&method=" + method + hiddenParams
|
|
|
|
link += "&url=" + btoa(back_url) if back_url
|
2016-04-18 22:23:38 +02:00
|
|
|
$("p.removeOther a").attr "href", link
|
|
|
|
|
2017-10-10 17:23:41 +02:00
|
|
|
# Language detection. Priority order:
|
2020-04-13 10:55:56 +02:00
|
|
|
# 0 - llnglanguage parameter
|
2017-10-10 17:23:41 +02:00
|
|
|
# 1 - cookie value
|
|
|
|
# 2 - first navigator.languages item that exists in window.availableLanguages
|
|
|
|
# 3 - first value of window.availableLanguages
|
2020-07-24 18:11:07 +02:00
|
|
|
if window.location.search
|
|
|
|
queryLang = getQueryParam('llnglanguage')
|
2020-04-13 12:02:15 +02:00
|
|
|
console.log 'Get lang from parameter' if queryLang
|
2020-07-24 18:11:07 +02:00
|
|
|
setCookieLang = getQueryParam('setCookieLang')
|
2020-04-13 12:02:15 +02:00
|
|
|
console.log 'Set lang cookie' if setCookieLang == 1
|
2020-04-13 10:55:56 +02:00
|
|
|
if !lang
|
|
|
|
lang = getCookie 'llnglanguage'
|
2020-04-13 11:42:59 +02:00
|
|
|
console.log 'Get lang from cookie' if lang && !queryLang
|
2017-02-16 08:37:47 +01:00
|
|
|
if !lang
|
|
|
|
if navigator
|
|
|
|
langs = []
|
|
|
|
langs2 = []
|
|
|
|
nlangs = [ navigator.language ]
|
|
|
|
if navigator.languages
|
|
|
|
nlangs = navigator.languages
|
2016-05-21 08:52:16 +02:00
|
|
|
for al in window.availableLanguages
|
2017-05-24 20:11:58 +02:00
|
|
|
langdiv += "<img class=\"langicon\" src=\"#{window.staticPrefix}common/#{al}.png\" title=\"#{al}\" alt=\"[#{al}]\"> "
|
2018-12-11 21:35:40 +01:00
|
|
|
for nl in nlangs
|
|
|
|
console.log 'Navigator lang', nl
|
|
|
|
for al in window.availableLanguages
|
|
|
|
console.log ' Available lang', al
|
2018-12-10 21:14:30 +01:00
|
|
|
re = new RegExp('^'+al+'-?')
|
|
|
|
if nl.match re
|
2018-12-11 21:35:40 +01:00
|
|
|
console.log ' Matching lang =', al
|
2017-02-16 08:37:47 +01:00
|
|
|
langs.push al
|
|
|
|
else if al.substring(0, 1) == nl.substring(0, 1)
|
|
|
|
langs2.push al
|
2017-05-05 08:50:38 +02:00
|
|
|
lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else window.availableLanguages[0]
|
2020-04-13 11:42:59 +02:00
|
|
|
console.log 'Get lang from navigator' if lang && !queryLang
|
2017-02-16 08:37:47 +01:00
|
|
|
else
|
2017-05-05 08:50:38 +02:00
|
|
|
lang = window.availableLanguages[0]
|
2020-04-13 11:42:59 +02:00
|
|
|
console.log 'Get lang from window' if lang && !queryLang
|
2017-05-05 08:50:38 +02:00
|
|
|
else if lang not in window.availableLanguages
|
|
|
|
lang = window.availableLanguages[0]
|
2020-04-16 12:25:39 +02:00
|
|
|
console.log 'Lang not available -> Get default lang' if !queryLang
|
2020-04-13 11:42:59 +02:00
|
|
|
if queryLang
|
2020-04-16 12:25:39 +02:00
|
|
|
if queryLang not in window.availableLanguages
|
|
|
|
console.log 'Lang not available -> Get default lang'
|
|
|
|
queryLang = window.availableLanguages[0]
|
2020-04-13 11:42:59 +02:00
|
|
|
console.log 'Selected lang ->', queryLang
|
2020-04-13 12:02:15 +02:00
|
|
|
if setCookieLang
|
2020-04-16 12:25:39 +02:00
|
|
|
console.log 'Set cookie lang ->', queryLang
|
2021-09-14 22:36:36 +02:00
|
|
|
setCookie 'llnglanguage', queryLang, datas['sameSite']
|
2020-04-13 11:42:59 +02:00
|
|
|
translatePage(queryLang)
|
|
|
|
else
|
|
|
|
console.log 'Selected lang ->', lang
|
2021-09-14 22:36:36 +02:00
|
|
|
setCookie 'llnglanguage', lang, datas['sameSite']
|
2020-04-13 11:42:59 +02:00
|
|
|
translatePage(lang)
|
2017-02-16 08:37:47 +01:00
|
|
|
|
|
|
|
# Build language icons
|
|
|
|
langdiv = ''
|
|
|
|
for al in window.availableLanguages
|
2017-05-24 20:11:58 +02:00
|
|
|
langdiv += "<img class=\"langicon\" src=\"#{window.staticPrefix}common/#{al}.png\" title=\"#{al}\" alt=\"[#{al}]\"> "
|
2017-02-16 08:37:47 +01:00
|
|
|
$('#languages').html langdiv
|
|
|
|
$('.langicon').on 'click', () ->
|
|
|
|
lang = $(this).attr 'title'
|
2021-09-14 22:36:36 +02:00
|
|
|
setCookie 'llnglanguage', lang, datas['sameSite']
|
2017-02-16 08:37:47 +01:00
|
|
|
translatePage lang
|
2017-01-19 12:33:11 +01:00
|
|
|
|
2020-08-21 16:35:33 +02:00
|
|
|
isAlphaNumeric = (chr) ->
|
|
|
|
code = chr.charCodeAt(0)
|
|
|
|
if code > 47 and code < 58 or code > 64 and code < 91 or code > 96 and code < 123
|
|
|
|
return true
|
|
|
|
false
|
|
|
|
|
|
|
|
# Password policy
|
|
|
|
checkpassword = (password) ->
|
|
|
|
result = true
|
|
|
|
if window.datas.ppolicy.minsize > 0
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( password.length >= window.datas.ppolicy.minsize, 'ppolicy-minsize-feedback' )
|
2020-08-21 16:35:33 +02:00
|
|
|
if window.datas.ppolicy.minupper > 0
|
|
|
|
upper = password.match(/[A-Z]/g)
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( upper and upper.length >= window.datas.ppolicy.minupper, 'ppolicy-minupper-feedback' )
|
2020-08-21 16:35:33 +02:00
|
|
|
if window.datas.ppolicy.minlower > 0
|
|
|
|
lower = password.match(/[a-z]/g)
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( lower and lower.length >= window.datas.ppolicy.minlower, 'ppolicy-minlower-feedback')
|
2020-08-21 16:35:33 +02:00
|
|
|
if window.datas.ppolicy.mindigit > 0
|
|
|
|
digit = password.match(/[0-9]/g)
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( digit and digit.length >= window.datas.ppolicy.mindigit, 'ppolicy-mindigit-feedback')
|
2020-08-21 16:35:33 +02:00
|
|
|
|
|
|
|
if window.datas.ppolicy.allowedspechar
|
|
|
|
nonwhitespechar = window.datas.ppolicy.allowedspechar.replace(/\s/g, '')
|
|
|
|
hasforbidden = false
|
|
|
|
i = 0
|
|
|
|
len = password.length
|
|
|
|
while i < len
|
|
|
|
if !isAlphaNumeric(password.charAt(i))
|
|
|
|
if nonwhitespechar.indexOf(password.charAt(i)) < 0
|
|
|
|
hasforbidden = true
|
|
|
|
i++
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( hasforbidden == false, 'ppolicy-allowedspechar-feedback' )
|
2020-08-21 16:35:33 +02:00
|
|
|
|
|
|
|
if window.datas.ppolicy.minspechar > 0 and window.datas.ppolicy.allowedspechar
|
|
|
|
numspechar = 0
|
|
|
|
nonwhitespechar = window.datas.ppolicy.allowedspechar.replace(/\s/g, '')
|
|
|
|
i = 0
|
|
|
|
while i < password.length
|
|
|
|
if nonwhitespechar.indexOf(password.charAt(i)) >= 0
|
|
|
|
numspechar++
|
|
|
|
i++
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( numspechar >= window.datas.ppolicy.minspechar, 'ppolicy-minspechar-feedback')
|
2020-08-29 22:12:09 +02:00
|
|
|
|
|
|
|
if window.datas.ppolicy.minspechar > 0 and !window.datas.ppolicy.allowedspechar
|
|
|
|
numspechar = 0
|
|
|
|
i = 0
|
|
|
|
while i < password.length
|
|
|
|
numspechar++ if !isAlphaNumeric(password.charAt(i))
|
|
|
|
i++
|
2022-02-01 17:09:15 +01:00
|
|
|
result = false if setDanger( numspechar >= window.datas.ppolicy.minspechar, 'ppolicy-minspechar-feedback')
|
2020-08-29 22:12:09 +02:00
|
|
|
|
2020-08-21 16:35:33 +02:00
|
|
|
if result
|
|
|
|
$('.ppolicy').removeClass('border-danger').addClass 'border-success'
|
2020-12-28 10:31:12 +01:00
|
|
|
$('#newpassword').get(0)?.setCustomValidity('')
|
2020-08-21 16:35:33 +02:00
|
|
|
else
|
|
|
|
$('.ppolicy').removeClass('border-success').addClass 'border-danger'
|
2020-12-28 10:31:12 +01:00
|
|
|
$('#newpassword').get(0)?.setCustomValidity(translate('PE28'))
|
2020-08-21 16:35:33 +02:00
|
|
|
return
|
|
|
|
|
2020-12-07 17:40:46 +01:00
|
|
|
if window.datas.ppolicy? and $('#newpassword').length
|
2020-08-21 16:35:33 +02:00
|
|
|
# Initialize display
|
|
|
|
checkpassword ''
|
|
|
|
|
|
|
|
$('#newpassword').keyup (e) ->
|
|
|
|
checkpassword e.target.value
|
|
|
|
return
|
|
|
|
|
2020-12-23 00:27:33 +01:00
|
|
|
# If generating password, disable policy check
|
|
|
|
togglecheckpassword = (e) ->
|
|
|
|
if e.target.checked
|
|
|
|
$('#newpassword').off('keyup')
|
2020-12-28 10:31:12 +01:00
|
|
|
$('#newpassword').get(0)?.setCustomValidity('')
|
2020-12-23 00:27:33 +01:00
|
|
|
# Restore check
|
|
|
|
else
|
|
|
|
$('#newpassword').keyup (e) ->
|
|
|
|
checkpassword e.target.value
|
|
|
|
return
|
|
|
|
checkpassword ''
|
|
|
|
|
2020-08-21 16:35:33 +02:00
|
|
|
checksamepass = () ->
|
2020-12-28 10:31:12 +01:00
|
|
|
if $('#confirmpassword').get(0)?.value == $('#newpassword').get(0)?.value
|
|
|
|
$('#confirmpassword').get(0)?.setCustomValidity('')
|
2020-08-21 16:35:33 +02:00
|
|
|
return true
|
|
|
|
else
|
2020-12-28 10:31:12 +01:00
|
|
|
$('#confirmpassword').get(0)?.setCustomValidity(translate('PE34'))
|
2020-08-21 16:35:33 +02:00
|
|
|
return false
|
|
|
|
|
|
|
|
$('#newpassword').change checksamepass
|
|
|
|
$('#confirmpassword').change checksamepass
|
2020-12-23 00:27:33 +01:00
|
|
|
if window.datas.ppolicy? and $('#newpassword').length
|
|
|
|
$('#reset').change togglecheckpassword
|
2020-08-21 16:35:33 +02:00
|
|
|
|
2021-07-08 23:55:03 +02:00
|
|
|
# Functions to show/hide display password button
|
2021-06-16 20:50:11 +02:00
|
|
|
if datas['enablePasswordDisplay']
|
2022-05-15 00:58:41 +02:00
|
|
|
field = ''
|
2021-07-08 23:55:03 +02:00
|
|
|
if datas['dontStorePassword']
|
|
|
|
$(".toggle-password").mousedown () ->
|
2022-05-16 13:38:23 +02:00
|
|
|
field = $(this).attr 'id'
|
|
|
|
field = field.replace /^toggle_/, ''
|
2022-05-15 12:03:57 +02:00
|
|
|
console.log 'Display', field
|
2021-07-08 23:55:03 +02:00
|
|
|
$(this).toggleClass("fa-eye fa-eye-slash")
|
2022-05-15 00:58:41 +02:00
|
|
|
$("input[name=#{field}]").attr('class', 'form-control')
|
2021-07-08 23:55:03 +02:00
|
|
|
$(".toggle-password").mouseup () ->
|
|
|
|
$(this).toggleClass("fa-eye fa-eye-slash")
|
2022-05-15 12:03:57 +02:00
|
|
|
$("input[name=#{field}]").attr('class', 'form-control key') if $("input[name=#{field}]").get(0).value
|
2021-07-08 23:55:03 +02:00
|
|
|
else
|
|
|
|
$(".toggle-password").mousedown () ->
|
2022-05-16 13:38:23 +02:00
|
|
|
field = $(this).attr 'id'
|
|
|
|
field = field.replace /^toggle_/, ''
|
2022-05-15 12:03:57 +02:00
|
|
|
console.log 'Display', field
|
2021-07-08 23:55:03 +02:00
|
|
|
$(this).toggleClass("fa-eye fa-eye-slash")
|
2022-05-15 00:58:41 +02:00
|
|
|
$("input[name=#{field}]").attr("type", "text")
|
2021-07-08 23:55:03 +02:00
|
|
|
$(".toggle-password").mouseup () ->
|
|
|
|
$(this).toggleClass("fa-eye fa-eye-slash")
|
2022-05-15 00:58:41 +02:00
|
|
|
$("input[name=#{field}]").attr("type", "password")
|
2021-06-16 20:50:11 +02:00
|
|
|
|
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
|
|
|
|
2017-09-18 22:40:01 +02:00
|
|
|
$('.oidcConsent').on 'click', () ->
|
|
|
|
removeOidcConsent $(this).attr 'partner'
|
2017-09-19 22:59:29 +02:00
|
|
|
|
2021-07-04 14:38:31 +02:00
|
|
|
# Functions to show/hide placeholder password inputs
|
|
|
|
$('#passwordfield').on 'input', () ->
|
2021-07-08 23:55:03 +02:00
|
|
|
if $('#passwordfield').get(0).value && datas['dontStorePassword']
|
2021-07-04 19:50:55 +02:00
|
|
|
$("#passwordfield").attr('class', 'form-control key')
|
|
|
|
else
|
|
|
|
$("#passwordfield").attr('class', 'form-control')
|
|
|
|
$('#oldpassword').on 'input', () ->
|
2021-07-08 23:55:03 +02:00
|
|
|
if $('#oldpassword').get(0).value && datas['dontStorePassword']
|
2021-07-04 19:50:55 +02:00
|
|
|
$("#oldpassword").attr('class', 'form-control key')
|
|
|
|
else
|
|
|
|
$("#oldpassword").attr('class', 'form-control')
|
|
|
|
$('#newpassword').on 'input', () ->
|
2021-07-08 23:55:03 +02:00
|
|
|
if $('#newpassword').get(0).value && datas['dontStorePassword']
|
2022-05-15 12:03:57 +02:00
|
|
|
$("#newpassword").attr('class', 'form-control key')
|
2021-07-04 19:50:55 +02:00
|
|
|
else
|
|
|
|
$("#newpassword").attr('class', 'form-control')
|
|
|
|
$('#confirmpassword').on 'input', () ->
|
2021-07-08 23:55:03 +02:00
|
|
|
if $('#confirmpassword').get(0).value && datas['dontStorePassword']
|
2022-05-15 12:03:57 +02:00
|
|
|
$("#confirmpassword").attr('class', 'form-control key')
|
2021-07-04 14:38:31 +02:00
|
|
|
else
|
2021-07-04 19:50:55 +02:00
|
|
|
$("#confirmpassword").attr('class', 'form-control')
|
2021-07-04 14:38:31 +02:00
|
|
|
|
2020-07-24 18:11:07 +02:00
|
|
|
#$('#formpass').on 'submit', changePwd
|
2020-12-23 22:38:58 +01:00
|
|
|
|
2021-08-12 22:36:23 +02:00
|
|
|
$('.clear-finduser-field').on 'click', () ->
|
|
|
|
$(this).parent().find(':input').each ->
|
|
|
|
console.log 'Clear search field ->', $(this).attr 'name'
|
|
|
|
$(this).val ''
|
2021-02-17 22:32:45 +01:00
|
|
|
|
2021-02-20 19:39:54 +01:00
|
|
|
$('#closefinduserform').on 'click', () ->
|
2021-02-17 22:32:45 +01:00
|
|
|
console.log 'Clear modal'
|
|
|
|
$('#finduserForm').trigger('reset')
|
|
|
|
|
2021-01-30 23:21:24 +01:00
|
|
|
$('#finduserbutton').on 'click', (event) ->
|
|
|
|
event.preventDefault()
|
2021-02-03 23:22:14 +01:00
|
|
|
document.body.style.cursor = 'progress'
|
2021-02-17 22:32:45 +01:00
|
|
|
str = $("#finduserForm").serialize()
|
2021-05-08 21:37:58 +02:00
|
|
|
console.log 'Send findUser request with parameters', str
|
2021-01-30 23:21:24 +01:00
|
|
|
$.ajax
|
|
|
|
type: "POST"
|
|
|
|
url: "#{portal}finduser"
|
|
|
|
dataType: 'json'
|
|
|
|
data: str
|
2021-01-31 00:13:07 +01:00
|
|
|
# On success, values are set
|
2021-01-30 23:21:24 +01:00
|
|
|
success: (data) ->
|
2021-02-03 23:22:14 +01:00
|
|
|
document.body.style.cursor = 'default'
|
2021-01-30 23:21:24 +01:00
|
|
|
user = data.user
|
2021-05-08 21:37:58 +02:00
|
|
|
console.log 'Suggested spoofId=', user
|
2021-08-12 21:06:24 +02:00
|
|
|
$("input[name=spoofId]").each ->
|
2021-09-06 19:55:42 +02:00
|
|
|
$(this).val user
|
2021-01-30 23:21:24 +01:00
|
|
|
$('#captcha').attr 'src', data.captcha if data.captcha
|
|
|
|
if data.token
|
2021-09-06 19:55:42 +02:00
|
|
|
$('#finduserToken').val data.token
|
|
|
|
$('#token').val data.token
|
2021-02-03 23:22:14 +01:00
|
|
|
error: (j, status, err) ->
|
|
|
|
document.body.style.cursor = 'default'
|
|
|
|
console.log 'Error', err if err
|
2021-01-30 23:21:24 +01:00
|
|
|
res = JSON.parse j.responseText if j
|
|
|
|
if res and res.error
|
2021-06-16 20:50:11 +02:00
|
|
|
console.log 'Returned error', res
|
2022-06-02 23:39:00 +02:00
|
|
|
|
|
|
|
$('#btn-back-to-top').on 'click', () ->
|
|
|
|
console.log 'Back to top'
|
|
|
|
document.body.scrollTop = 0
|
|
|
|
document.documentElement.scrollTop = 0
|
|
|
|
|
|
|
|
$(window).on 'scroll', () ->
|
|
|
|
if datas['scrollTop'] && (document.body.scrollTop > Math.abs(datas['scrollTop']) || document.documentElement.scrollTop > Math.abs(datas['scrollTop']))
|
|
|
|
$('#btn-back-to-top').css("display","block")
|
|
|
|
else
|
|
|
|
$('#btn-back-to-top').css("display","none")
|