mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-29 10:13:59 +01:00
allow using "?" in ID as a placeholder for next available number
This commit is contained in:
parent
196269aa38
commit
ade2219469
2 changed files with 14 additions and 3 deletions
|
@ -10,7 +10,7 @@
|
||||||
<body>
|
<body>
|
||||||
<h1><a href="../">in?</a></h1>
|
<h1><a href="../">in?</a></h1>
|
||||||
<form id="form">
|
<form id="form">
|
||||||
<label for="id">ID</label>
|
<label for="id">ID</label> (use ? as placeholder for next available number)
|
||||||
<input id="id" type="text" placeholder="loading...">
|
<input id="id" type="text" placeholder="loading...">
|
||||||
|
|
||||||
<label for="is_in">Is in</label>
|
<label for="is_in">Is in</label>
|
||||||
|
|
|
@ -65,8 +65,8 @@ function knownTypes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
item = {
|
const item = {
|
||||||
id: document.getElementById('id').value || null,
|
id: document.getElementById('id').value || '',
|
||||||
is_in: document.getElementById('is_in').value || null,
|
is_in: document.getElementById('is_in').value || null,
|
||||||
coords_bl: document.getElementById('coords_bl').value || null,
|
coords_bl: document.getElementById('coords_bl').value || null,
|
||||||
coords_tr: document.getElementById('coords_tr').value || null,
|
coords_tr: document.getElementById('coords_tr').value || null,
|
||||||
|
@ -77,6 +77,17 @@ function save() {
|
||||||
hidden: document.getElementById('hidden').checked,
|
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 (items[item.id]) {
|
||||||
if (!id || (id && id != 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!`);
|
alert(`ID ${item.id} exists. Please chose a different ID or edit the existing ${item.id} item!`);
|
||||||
|
|
Loading…
Reference in a new issue