dont crash with bad url

pull/1/head
Ondřej Hruška 7 years ago
parent a96b522ca8
commit c8305dea1a
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 102
      js/appcommon.js

@ -90,60 +90,64 @@ $.ready(function () {
e.preventDefault() e.preventDefault()
}) })
do { try {
let msgAt, box do {
// populate the form errors box from GET arg ?err=... let msgAt, box
// (a way to pass errors back from server via redirect) // populate the form errors box from GET arg ?err=...
msgAt = window.location.search.indexOf('err=') // (a way to pass errors back from server via redirect)
if (msgAt !== -1 && qs('.Box.errors')) { msgAt = window.location.search.indexOf('err=')
let errs = decodeURIComponent(window.location.search.substr(msgAt + 4)).split(',') if (msgAt !== -1 && qs('.Box.errors')) {
let humanReadableErrors = [] let errs = decodeURIComponent(window.location.search.substr(msgAt + 4)).split(',')
errs.forEach(function (er) { let humanReadableErrors = []
let lbls = qsa('label[for="' + er + '"]') errs.forEach(function (er) {
if (lbls) { let lbls = qsa('label[for="' + er + '"]')
for (let i = 0; i < lbls.length; i++) { if (lbls) {
let lbl = lbls[i] for (let i = 0; i < lbls.length; i++) {
lbl.classList.add('error') let lbl = lbls[i]
if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')) lbl.classList.add('error')
if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''))
}
} else {
humanReadableErrors.push(er)
} }
} else { })
humanReadableErrors.push(er)
} qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ')
}) qs('.Box.errors').classList.remove('hidden')
break
qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ') }
qs('.Box.errors').classList.remove('hidden')
break
}
let fademsgbox = function (box, time) { let fademsgbox = function (box, time) {
box.classList.remove('hidden') box.classList.remove('hidden')
setTimeout(() => {
box.classList.add('hiding')
setTimeout(() => { setTimeout(() => {
box.classList.add('hidden') box.classList.add('hiding')
}, 1000) setTimeout(() => {
}, time) box.classList.add('hidden')
} }, 1000)
}, time)
}
msgAt = window.location.search.indexOf('errmsg=') msgAt = window.location.search.indexOf('errmsg=')
box = qs('.Box.errmessage') box = qs('.Box.errmessage')
if (msgAt !== -1 && box) { if (msgAt !== -1 && box) {
let msg = decodeURIComponent(window.location.search.substr(msgAt + 7)) let msg = decodeURIComponent(window.location.search.substr(msgAt + 7))
box.innerHTML = msg box.innerHTML = msg
fademsgbox(box, 3000) fademsgbox(box, 3000)
break break
} }
msgAt = window.location.search.indexOf('msg=') msgAt = window.location.search.indexOf('msg=')
box = qs('.Box.message') box = qs('.Box.message')
if (msgAt !== -1 && box) { if (msgAt !== -1 && box) {
let msg = decodeURIComponent(window.location.search.substr(msgAt + 4)) let msg = decodeURIComponent(window.location.search.substr(msgAt + 4))
box.innerHTML = msg box.innerHTML = msg
fademsgbox(box, 2000) fademsgbox(box, 2000)
break break
} }
} while (0) } while (0)
} catch (e) {
console.error(e)
}
modal.init() modal.init()
notify.init() notify.init()

Loading…
Cancel
Save