outposts: load token async

This commit is contained in:
Jens Langhammer 2020-10-04 00:29:18 +02:00
parent 189b0ec324
commit d3a96ac7aa
2 changed files with 12 additions and 1 deletions

View File

@ -24,7 +24,7 @@
<label class="pf-c-form__label" for="help-text-simple-form-name">
<span class="pf-c-form__label-text">PASSBOOK_TOKEN</span>
</label>
<input class="pf-c-form-control" readonly type="text" value="{{ outpost.token.token_uuid.hex }}" />
<input class="pf-c-form-control" data-pb-fetch-key="pk" data-pb-fetch-fill="{% url 'passbook_api:token-detail' identifier=outpost.token_identifier %}" readonly type="text" value="" />
</div>
<h3>{% trans 'If your passbook Instance is using a self-signed certificate, set this value.' %}</h3>
<div class="pf-c-form__group">

View File

@ -7,6 +7,7 @@ document.querySelectorAll("button.pf-c-dropdown__toggle").forEach((b) => {
});
});
// Search clearing
document.querySelectorAll("input[type=search]").forEach((si) => {
si.addEventListener("search", (e) => {
if (si.value === "") {
@ -15,6 +16,16 @@ document.querySelectorAll("input[type=search]").forEach((si) => {
});
});
// Fetch from data-attributes
document.querySelectorAll("[data-pb-fetch-fill]").forEach((el) => {
const url = el.dataset.pbFetchFill;
const key = el.dataset.pbFetchKey;
fetch(url).then(r => r.json()).then(r => {
el.textContent = r[key];
el.value = r[key];
});
});
// Modal
document.querySelectorAll("[data-target='modal']").forEach((m) => {
m.addEventListener("click", (e) => {