add errmessage

pull/1/head
Ondřej Hruška 7 years ago
parent 172e1e0b19
commit a96b522ca8
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 82
      js/appcommon.js
  2. 1
      pages/_head.php
  3. 5
      sass/form/_form_layout.scss

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

@ -33,5 +33,6 @@ if (strpos($_GET['BODYCLASS'], 'cfg') !== false) {
</div> </div>
<div class="Box message hidden"></div> <div class="Box message hidden"></div>
<div class="Box errmessage hidden"></div>
<?php endif; ?> <?php endif; ?>

@ -22,6 +22,11 @@ form { @include naked(); }
} }
} }
.Box.errmessage {
@extend .Box.message;
color: crimson;
}
.Row { .Row {
vertical-align: middle; vertical-align: middle;
margin: 12px auto; margin: 12px auto;

Loading…
Cancel
Save