allow using "?" in ID as a placeholder for next available number

This commit is contained in:
jomo 2022-08-11 02:51:11 +02:00
parent 196269aa38
commit ade2219469
2 changed files with 14 additions and 3 deletions

View file

@ -65,8 +65,8 @@ function knownTypes() {
}
function save() {
item = {
id: document.getElementById('id').value || null,
const item = {
id: document.getElementById('id').value || '',
is_in: document.getElementById('is_in').value || null,
coords_bl: document.getElementById('coords_bl').value || null,
coords_tr: document.getElementById('coords_tr').value || null,
@ -77,6 +77,17 @@ function save() {
hidden: document.getElementById('hidden').checked,
}
if (item.id.includes('?')) {
let n = 1;
while (true) {
const candidate = item.id.replace('?', n++);
if (!Object.keys(items).includes(candidate)) {
item.id = candidate;
break;
}
}
}
if (items[item.id]) {
if (!id || (id && id != item.id)) {
alert(`ID ${item.id} exists. Please chose a different ID or edit the existing ${item.id} item!`);