member authentication
Αυτό το commit περιλαμβάνεται σε:
γονέας
d99bc70b80
commit
f88174521d
2 αρχεία άλλαξαν με 139 προσθήκες και 2 διαγραφές
|
@ -11,11 +11,19 @@ build:
|
||||||
<!-- htmx -->
|
<!-- htmx -->
|
||||||
<script src="/static/js/htmx.min.js"></script>
|
<script src="/static/js/htmx.min.js"></script>
|
||||||
<script src="/static/js/ext/json-enc.js"></script>
|
<script src="/static/js/ext/json-enc.js"></script>
|
||||||
|
<script src="/static/js/ext/response-targets.js"></script>
|
||||||
|
|
||||||
|
<div id="subscriptionAlert"></div>
|
||||||
|
<div role="alert" hx-get="/api/auth/status?display=inline" hx-trigger="load" hx-ext="response-targets" hx-target="#subscriptionAlert" hx-target-401="this" hx-swap="outerHTML">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div hx-get="/api/member/status" hx-trigger="load" hx-swap="outerHTML">
|
||||||
|
</div>
|
||||||
|
|
||||||
<form id="subscriptionform" hx-post="/api/sendSubscriptionEmail" hx-ext='json-enc'>
|
<form id="subscriptionform" hx-post="/api/sendSubscriptionEmail" hx-ext='json-enc'>
|
||||||
<p> Παρακαλούμε συμπληρώστε την παρακάτω φόρμα, για να ενημερωθείτε για τυχόν Ταμειακές Εκκρεμότητες σας, μέσω e-mail</p>
|
<p> Παρακαλούμε συμπληρώστε την παρακάτω φόρμα, για να λάβετε περισσότερες πληροφορίες σχετικά με τις Ταμειακές Εκκρεμότητες σας, μέσω e-mail</p>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<label class="form-label">Πληκτολογήστε το email σας (όπως το είχατε δώσει κατά την εγγραφή σας)</label>
|
<label class="form-label">Πληκτρολογήστε το email σας (όπως το είχατε δώσει κατά την εγγραφή σας)</label>
|
||||||
<input type="email" name="email" class="form-control" placeholder="username@hellug.gr">
|
<input type="email" name="email" class="form-control" placeholder="username@hellug.gr">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
129
static/static/js/ext/response-targets.js
Κανονικό αρχείο
129
static/static/js/ext/response-targets.js
Κανονικό αρχείο
|
@ -0,0 +1,129 @@
|
||||||
|
(function() {
|
||||||
|
/** @type {import("../htmx").HtmxInternalApi} */
|
||||||
|
var api
|
||||||
|
|
||||||
|
var attrPrefix = 'hx-target-'
|
||||||
|
|
||||||
|
// IE11 doesn't support string.startsWith
|
||||||
|
function startsWith(str, prefix) {
|
||||||
|
return str.substring(0, prefix.length) === prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {HTMLElement} elt
|
||||||
|
* @param {number} respCode
|
||||||
|
* @returns {HTMLElement | null}
|
||||||
|
*/
|
||||||
|
function getRespCodeTarget(elt, respCodeNumber) {
|
||||||
|
if (!elt || !respCodeNumber) return null
|
||||||
|
|
||||||
|
var respCode = respCodeNumber.toString()
|
||||||
|
|
||||||
|
// '*' is the original syntax, as the obvious character for a wildcard.
|
||||||
|
// The 'x' alternative was added for maximum compatibility with HTML
|
||||||
|
// templating engines, due to ambiguity around which characters are
|
||||||
|
// supported in HTML attributes.
|
||||||
|
//
|
||||||
|
// Start with the most specific possible attribute and generalize from
|
||||||
|
// there.
|
||||||
|
var attrPossibilities = [
|
||||||
|
respCode,
|
||||||
|
|
||||||
|
respCode.substr(0, 2) + '*',
|
||||||
|
respCode.substr(0, 2) + 'x',
|
||||||
|
|
||||||
|
respCode.substr(0, 1) + '*',
|
||||||
|
respCode.substr(0, 1) + 'x',
|
||||||
|
respCode.substr(0, 1) + '**',
|
||||||
|
respCode.substr(0, 1) + 'xx',
|
||||||
|
|
||||||
|
'*',
|
||||||
|
'x',
|
||||||
|
'***',
|
||||||
|
'xxx'
|
||||||
|
]
|
||||||
|
if (startsWith(respCode, '4') || startsWith(respCode, '5')) {
|
||||||
|
attrPossibilities.push('error')
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < attrPossibilities.length; i++) {
|
||||||
|
var attr = attrPrefix + attrPossibilities[i]
|
||||||
|
var attrValue = api.getClosestAttributeValue(elt, attr)
|
||||||
|
if (attrValue) {
|
||||||
|
if (attrValue === 'this') {
|
||||||
|
return api.findThisElement(elt, attr)
|
||||||
|
} else {
|
||||||
|
return api.querySelectorExt(elt, attrValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param {Event} evt */
|
||||||
|
function handleErrorFlag(evt) {
|
||||||
|
if (evt.detail.isError) {
|
||||||
|
if (htmx.config.responseTargetUnsetsError) {
|
||||||
|
evt.detail.isError = false
|
||||||
|
}
|
||||||
|
} else if (htmx.config.responseTargetSetsError) {
|
||||||
|
evt.detail.isError = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
htmx.defineExtension('response-targets', {
|
||||||
|
|
||||||
|
/** @param {import("../htmx").HtmxInternalApi} apiRef */
|
||||||
|
init: function(apiRef) {
|
||||||
|
api = apiRef
|
||||||
|
|
||||||
|
if (htmx.config.responseTargetUnsetsError === undefined) {
|
||||||
|
htmx.config.responseTargetUnsetsError = true
|
||||||
|
}
|
||||||
|
if (htmx.config.responseTargetSetsError === undefined) {
|
||||||
|
htmx.config.responseTargetSetsError = false
|
||||||
|
}
|
||||||
|
if (htmx.config.responseTargetPrefersExisting === undefined) {
|
||||||
|
htmx.config.responseTargetPrefersExisting = false
|
||||||
|
}
|
||||||
|
if (htmx.config.responseTargetPrefersRetargetHeader === undefined) {
|
||||||
|
htmx.config.responseTargetPrefersRetargetHeader = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
* @param {Event} evt
|
||||||
|
*/
|
||||||
|
onEvent: function(name, evt) {
|
||||||
|
if (name === 'htmx:beforeSwap' &&
|
||||||
|
evt.detail.xhr &&
|
||||||
|
evt.detail.xhr.status !== 200) {
|
||||||
|
if (evt.detail.target) {
|
||||||
|
if (htmx.config.responseTargetPrefersExisting) {
|
||||||
|
evt.detail.shouldSwap = true
|
||||||
|
handleErrorFlag(evt)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (htmx.config.responseTargetPrefersRetargetHeader &&
|
||||||
|
evt.detail.xhr.getAllResponseHeaders().match(/HX-Retarget:/i)) {
|
||||||
|
evt.detail.shouldSwap = true
|
||||||
|
handleErrorFlag(evt)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!evt.detail.requestConfig) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
var target = getRespCodeTarget(evt.detail.requestConfig.elt, evt.detail.xhr.status)
|
||||||
|
if (target) {
|
||||||
|
handleErrorFlag(evt)
|
||||||
|
evt.detail.shouldSwap = true
|
||||||
|
evt.detail.target = target
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})()
|
Φόρτωση…
Προσθήκη πίνακα
Προσθήκη υπερσυνδέσμου
Παράθεση σε νέο ζήτημα