mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-25 16:53: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>
|
||||
<h1><a href="../">in?</a></h1>
|
||||
<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...">
|
||||
|
||||
<label for="is_in">Is in</label>
|
||||
|
|
|
@ -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!`);
|
||||
|
|
Loading…
Reference in a new issue