fetch items from server before locally checking available IDs
This commit is contained in:
parent
ade2219469
commit
6b7c741658
1 changed files with 37 additions and 31 deletions
|
@ -3,12 +3,16 @@ const id = new URLSearchParams(window.location.search).get('id');
|
||||||
|
|
||||||
document.onreadystatechange = function() {
|
document.onreadystatechange = function() {
|
||||||
if (document.readyState === 'interactive') {
|
if (document.readyState === 'interactive') {
|
||||||
|
fetchItems(fillForm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchItems(cb) {
|
||||||
fetch('/api/items').then(r => r.json()).then((data) => {
|
fetch('/api/items').then(r => r.json()).then((data) => {
|
||||||
items = data;
|
items = data;
|
||||||
fillForm();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function fillForm() {
|
function fillForm() {
|
||||||
const item = items[id];
|
const item = items[id];
|
||||||
|
@ -77,6 +81,7 @@ function save() {
|
||||||
hidden: document.getElementById('hidden').checked,
|
hidden: document.getElementById('hidden').checked,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchItems(() => {
|
||||||
if (item.id.includes('?')) {
|
if (item.id.includes('?')) {
|
||||||
let n = 1;
|
let n = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -111,6 +116,7 @@ function save() {
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
alert(`Error:\n${error}`);
|
alert(`Error:\n${error}`);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function del() {
|
function del() {
|
||||||
|
|
Loading…
Reference in a new issue