added notifications
This commit is contained in:
@@ -50,3 +50,13 @@ svg text{
|
||||
.menu .tile .list .tile{
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#messages{
|
||||
display: none;
|
||||
position: fixed;
|
||||
bottom: 5px;
|
||||
right: 5px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
background: yellow;
|
||||
}
|
||||
@@ -5,21 +5,30 @@ const SVG = 'svg';
|
||||
var selected = null;
|
||||
var mode = null;
|
||||
|
||||
function addMessage(txt){
|
||||
$('#messages').html(txt).show().delay(1000).fadeOut();
|
||||
}
|
||||
|
||||
function addTile(tile,x,y){
|
||||
console.log("addTile:",tile.id,x,y);
|
||||
function addTile(x,y){
|
||||
console.log("addTile:",selected.id,x,y);
|
||||
x = Math.floor(x/SQUARE);
|
||||
y = Math.floor(y/SQUARE);
|
||||
$.ajax({
|
||||
url : 'plan',
|
||||
method: 'POST',
|
||||
data : {mode:mode,tile:tile.id,x:x,y:y}
|
||||
});
|
||||
data : {mode:mode,tile:selected.id,x:x,y:y},
|
||||
success: function(resp){
|
||||
var id = 'tile-'+x+'-'+y;
|
||||
$('#'+id).remove();
|
||||
var tile = $(tile).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
|
||||
console.log(tile);
|
||||
console.log("x: ",x);
|
||||
var tile = $(selected).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
|
||||
|
||||
$(BODY).append(tile);
|
||||
|
||||
addMessage(resp);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function bodyClick(ev){
|
||||
@@ -28,7 +37,7 @@ function bodyClick(ev){
|
||||
case undefined:
|
||||
case null: return;
|
||||
case ADD:
|
||||
return addTile(selected,ev.clientX,ev.clientY);
|
||||
return addTile(ev.clientX,ev.clientY);
|
||||
}
|
||||
console.log(ev.clientX,ev.clientY);
|
||||
}
|
||||
|
||||
@@ -106,12 +106,20 @@ public class Application {
|
||||
}
|
||||
|
||||
private static void send(HttpExchange client, Page response) throws IOException {
|
||||
client.getResponseHeaders().set("content-type", "text/plain");
|
||||
StringBuffer html = response.html();
|
||||
byte[] html = response.html().toString().getBytes(UTF8);
|
||||
client.getResponseHeaders().add("content-type", "text/html");
|
||||
client.sendResponseHeaders(200, html.length());
|
||||
client.sendResponseHeaders(200, html.length);
|
||||
OutputStream os = client.getResponseBody();
|
||||
os.write(html.toString().getBytes(UTF8));
|
||||
os.write(html);
|
||||
os.close();
|
||||
}
|
||||
|
||||
private static void send(HttpExchange client, String response) throws IOException {
|
||||
byte[] html = response.getBytes(UTF8);
|
||||
client.getResponseHeaders().add("content-type", "text/plain");
|
||||
client.sendResponseHeaders(200, html.length);
|
||||
OutputStream os = client.getResponseBody();
|
||||
os.write(html);
|
||||
os.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,11 @@ public class Plan {
|
||||
page.append("\t\t"+tile.html()+"\n");
|
||||
}
|
||||
}
|
||||
page.append(menu());
|
||||
return page;
|
||||
return page.append(menu()).append(messages());
|
||||
}
|
||||
|
||||
private Tag messages() {
|
||||
return new Tag("div").id("messages").content("");
|
||||
}
|
||||
|
||||
private Tag menu() throws IOException {
|
||||
@@ -84,8 +87,7 @@ public class Plan {
|
||||
return menu;
|
||||
}
|
||||
|
||||
public Page process(HashMap<String, String> params) {
|
||||
Page page = new Page();
|
||||
public String process(HashMap<String, String> params) {
|
||||
try {
|
||||
String mode = params.get(MODE);
|
||||
|
||||
@@ -93,13 +95,13 @@ public class Plan {
|
||||
switch (mode) {
|
||||
case MODE_ADD:
|
||||
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y));
|
||||
return page.append(t("Added {}",tile.getClass().getSimpleName()));
|
||||
return t("Added {}",tile.getClass().getSimpleName());
|
||||
default:
|
||||
LOG.warn("Unknown mode: {}",mode);
|
||||
}
|
||||
return page.append("unknown "+MODE+": "+mode);
|
||||
return t("unknown mode: {}",mode);
|
||||
} catch (Exception e) {
|
||||
return page.append(e.getMessage());
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user