implemented deleting of tiles, saving of plan

This commit is contained in:
Stephan Richter
2020-09-13 00:18:25 +02:00
parent 1a3a14762a
commit 6f7e225604
7 changed files with 84 additions and 26 deletions

View File

@@ -60,6 +60,8 @@ svg text{
.menu > div > .list > *{
position: relative;
border: 1px solid black;
height: 30px;
float: left;
}
@@ -71,4 +73,8 @@ svg text{
padding: 5px;
border-radius: 5px;
background: yellow;
}
#Eraser polygon{
stroke: red;
}

View File

@@ -1,7 +1,9 @@
const ADD = 1;
const ADD = 'add';
const SQUARE = 30;
const BODY = 'body';
const SVG = 'svg';
const PLAN = 'plan';
const POST = 'POST';
var selected = null;
var mode = null;
@@ -14,17 +16,14 @@ function addTile(x,y){
x = Math.floor(x/SQUARE);
y = Math.floor(y/SQUARE);
$.ajax({
url : 'plan',
method: 'POST',
data : {mode:mode,tile:selected.id,x:x,y:y},
url : PLAN,
method: POST,
data : {action:mode,tile:selected.id,x:x,y:y},
success: function(resp){
var id = 'tile-'+x+'-'+y;
$('#'+id).remove();
console.log("x: ",x);
var tile = $(selected).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
$(BODY).append(tile);
if (selected.id != 'Eraser') $(BODY).append(tile);
addMessage(resp);
}
});
@@ -52,7 +51,7 @@ function closeMenu(ev){
}
function enableAdding(ev){
console.log('enableAdding:',ev);
// console.log('enableAdding:',ev);
if (selected != null) $(selected).css('border','');
selected = ev.target;
while (selected != null && selected.nodeName != SVG) selected = selected.parentNode;
@@ -66,9 +65,20 @@ function enableAdding(ev){
return false; // otherwise body.click would also be triggered
}
function savePlan(ev){
$.ajax({
url : PLAN,
method : POST,
data : {action:'save',name:'default'},
success: function(resp){ addMessage(resp);}
});
return false;
}
window.onload = function () {
var isDragging = false;
$('.menu > div').click(closeMenu);
$('.menu .addtile .list svg').click(enableAdding);
$(BODY).click(bodyClick);
$('#save').click(savePlan);
}

4
resources/svg/Eraser.svg Normal file
View File

@@ -0,0 +1,4 @@
<svg width="100" height="100" viewbox="0 0 100 100">
<polygon points="5,0 100,95 95,100 0,5" />
<polygon points="0,95 95,0 100,5 5,100" />
</svg>

After

Width:  |  Height:  |  Size: 147 B

View File

@@ -1 +1,5 @@
Added {} : {} hinzugefügt
Actions : Aktionen
Added {} : {} hinzugefügt
Add tile : Kachel hinzufügen
Save plan : Plan speichern
Unknown action\: {} : Unbekannte Aktion: {}