More comments (#595)

This commit is contained in:
Xavier Guimard 2017-10-10 15:23:41 +00:00
parent 46364da414
commit c880479898
4 changed files with 27 additions and 8 deletions

View File

@ -3,12 +3,12 @@
$(document).ready ->
$.ajax portal + '?kerberos=1',
dataType: 'json'
# Called if browser can't find Kerberos ticket will display
# Called if browser can't find Kerberos ticket, will display
# PE_BADCREDENTIALS
statusCode:
401: () ->
$('#lform').submit()
# If request succeed, cookie is set, posting form to get redirection
# If request succeed cookie is set, posting form to get redirection
# or menu
success: (data) ->
$('#lform').submit()

View File

@ -1,5 +1,7 @@
values = {}
$(document).ready ->
# Import application/init variables
$("script[type='application/init']").each ->
try
tmp = JSON.parse $(this).text()
@ -7,8 +9,10 @@ $(document).ready ->
values[k] = tmp[k]
catch e
console.log 'Parsing error', e
# Initialize JS communication channel
window.addEventListener "message", receiveMessage, false
# Eval message response
receiveMessage (e) ->
message = e.data
client_id = decodeURIComponent message.split(' ')[0]

View File

@ -6,6 +6,13 @@ LemonLDAP::NG Portal jQuery scripts
translationFields = {}
# 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()
translatePage = (lang) ->
$.getJSON "#{window.staticPrefix}languages/#{lang}.json", (data) ->
translationFields = data
@ -23,12 +30,14 @@ translatePage = (lang) ->
d = new Date $(this).attr('localtime') * 1000
$(this).text d.toLocaleString()
# Translate a string
translate = (str) ->
return if translationFields[str] then translationFields[str] else str
window.translate = translate
# Initialization variables
# Initialization variables: read all <script type="application/init"> tags and
# return JSON parsing result. This is set in window.data variable
getValues = () ->
values = {}
$("script[type='application/init']").each ->
@ -41,8 +50,6 @@ getValues = () ->
console.log 'JSON', $(this).text()
values
# Set default values
# Code from http://snipplr.com/view/29434/
# ----------------------------------------
setSelector = "#appslist"
@ -151,6 +158,7 @@ ping = ->
window.ping = ping
# Functions to get/set a cookie value
getCookie = (cname) ->
name = cname + "="
ca = decodeURIComponent(document.cookie).split ';'
@ -167,7 +175,7 @@ setCookie = (name, value, exdays) ->
document.cookie = "#{name}=#{value}; expires=#{d.toUTCString()}; path=/"
# Function to change password using Ajax (instead of POST)
# TODO
# NOT USED FOR NOW
#changePwd = (event) ->
# event.preventDefault();
# $.ajax
@ -184,6 +192,7 @@ setCookie = (name, value, exdays) ->
# Initialization
datas = {}
$(document).ready ->
# Get application/init variables
datas = getValues()
# Export datas for other scripts
window.datas = datas
@ -230,7 +239,7 @@ $(document).ready ->
# Focus on first visible input
$("input[type!=hidden]:first").focus()
# Open links in new windows
# Open links in new windows if required
if datas['newwindow']
$('#appslist a').attr "target", "_blank"
@ -251,7 +260,10 @@ $(document).ready ->
link = $("p.removeOther a").attr("href") + "&method=" + method + "&url=" + btoa(back_url)
$("p.removeOther a").attr "href", link
# Language detection
# Language detection. Priority order:
# 1 - cookie value
# 2 - first navigator.languages item that exists in window.availableLanguages
# 3 - first value of window.availableLanguages
lang = getCookie 'llnglanguage'
if !lang
if navigator

View File

@ -17,6 +17,7 @@ displayError = (j, status, err) ->
console.log 'Returned error', res
setMsg res, 'warning'
# Registration function (launched by "register" button)
register = ->
# 1 get registration token
$.ajax
@ -53,6 +54,7 @@ register = ->
setMsg 'u2fRegistered', 'positive'
error: displayError
# Verification function (launched by "verify" button)
verify = ->
# 1 get challenge
$.ajax
@ -88,6 +90,7 @@ verify = ->
error: (j, status, err) ->
console.log 'error', err
# Register "click" events
$(document).ready ->
$('#u2fPermission').hide()
$('#register').on 'click', register