mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2025-06-09 05:25:09 +02:00
set item coords via map, closes #3
This commit is contained in:
parent
4bf4f754c9
commit
5aa8b8a37f
5 changed files with 2341 additions and 6 deletions
|
@ -34,6 +34,8 @@ function fillForm() {
|
|||
document.getElementById('content').value = item.content;
|
||||
document.getElementById('note').value = item.note;
|
||||
document.getElementById('hidden').checked = item.hidden;
|
||||
|
||||
coordsToMap(item.coords_bl, item.coords_tr);
|
||||
}
|
||||
|
||||
const saveBtn = document.getElementById('save');
|
||||
|
@ -101,3 +103,43 @@ function del() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
let clicks = {x: [], y: []};
|
||||
function mapClick(e) {
|
||||
let x = Math.floor(31 / e.target.width * e.layerX);
|
||||
let y = Math.floor(10 / e.target.height * e.layerY);
|
||||
|
||||
let humanPos = (x, y) => {
|
||||
return `${String.fromCharCode(65 + 8 - y)}${x}`;
|
||||
};
|
||||
|
||||
if (x > 0 && x < 31 && y > 0 && y < 9) {
|
||||
if (clicks.x.length > 1) {
|
||||
clicks.x = [x];
|
||||
clicks.y = [y];
|
||||
} else {
|
||||
clicks.x.push(x);
|
||||
clicks.y.push(y);
|
||||
}
|
||||
|
||||
if (clicks.x.length > 1) {
|
||||
clicks.x.sort((a,b) => a-b);
|
||||
clicks.y.sort((a,b) => a-b);
|
||||
renderMap(clicks.x, clicks.y);
|
||||
|
||||
let coords_bl = humanPos(clicks.x[0], clicks.y[1]);
|
||||
let coords_tr = humanPos(clicks.x[1], clicks.y[0]);
|
||||
|
||||
document.getElementById('coords_bl').value = coords_bl;
|
||||
document.getElementById('coords_tr').value = coords_tr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function formCoordsToMap() {
|
||||
const coords_bl = document.getElementById('coords_bl').value || '';
|
||||
const coords_tr = document.getElementById('coords_tr').value || '';
|
||||
if (coords_bl.length > 1 && coords_tr.length > 1) {
|
||||
coordsToMap(coords_bl, coords_tr);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue