Improve domain fetch api
This commit is contained in:
@ -28,18 +28,49 @@ function createLoginWindow() {
|
||||
<button type="submit">Login</button>
|
||||
</form>`;
|
||||
|
||||
win.getElementsByTagName('form')[0].addEventListener("submit", function (evt) {
|
||||
win.getElementsByTagName("form")[0].addEventListener("submit", (evt) => {
|
||||
evt.preventDefault();
|
||||
let form = evt.target;
|
||||
for (let e of form) e.disabled = true;
|
||||
|
||||
for (let d of form.getElementsByTagName("div")) {
|
||||
form.removeChild(d);
|
||||
}
|
||||
|
||||
usimp.lookup(form.domain.value)
|
||||
.then(res => res.json()
|
||||
.then(data => console.log(data))
|
||||
.catch(reason => console.error(reason)))
|
||||
.catch(reason => console.error(reason));
|
||||
.then(res => {
|
||||
if (res.ok) {
|
||||
res.json()
|
||||
.then(data => console.log(data))
|
||||
.catch(reason => console.error(reason))
|
||||
} else {
|
||||
document.getElementsByName("domain")[0].setAttribute("invalid", "invalid");
|
||||
let div = document.createElement("div");
|
||||
div.classList.add("error");
|
||||
div.innerText = "Invalid USIMP domain";
|
||||
form.appendChild(div);
|
||||
}
|
||||
})
|
||||
.catch(reason => {
|
||||
document.getElementsByName("domain")[0].setAttribute("invalid", "invalid");
|
||||
let div = document.createElement("div");
|
||||
div.classList.add("error");
|
||||
div.innerText = "Invalid USIMP domain";
|
||||
form.appendChild(div);
|
||||
})
|
||||
.finally(() => {
|
||||
for (let e of form) e.disabled = false;
|
||||
});
|
||||
});
|
||||
|
||||
while (windows.lastChild) windows.removeChild(windows.lastChild);
|
||||
windows.appendChild(win);
|
||||
|
||||
document.getElementsByName("domain")[0].addEventListener("input", (evt) => {
|
||||
evt.target.removeAttribute("invalid");
|
||||
});
|
||||
|
||||
document.getElementsByName("account")[0].focus();
|
||||
}
|
||||
|
||||
function handleHash(hash) {
|
||||
@ -64,7 +95,7 @@ function handleUrl(url) {
|
||||
handleHash(new URL(url).hash);
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", function () {
|
||||
window.addEventListener("DOMContentLoaded", (evt) => {
|
||||
main = document.getElementsByTagName("main")[0];
|
||||
windows = document.getElementById("windows");
|
||||
|
||||
@ -74,6 +105,6 @@ window.addEventListener("DOMContentLoaded", function () {
|
||||
handleUrl(document.URL)
|
||||
});
|
||||
|
||||
window.addEventListener("hashchange", function (evt) {
|
||||
window.addEventListener("hashchange", (evt) => {
|
||||
handleUrl(evt.newURL);
|
||||
});
|
||||
|
Reference in New Issue
Block a user