Browse Source

added notifications

lookup-tables
Stephan Richter 5 years ago
parent
commit
c216a762f0
  1. 10
      resources/css/style.css
  2. 23
      resources/js/plan.js
  3. 16
      src/main/java/de/srsoftware/web4rail/Application.java
  4. 16
      src/main/java/de/srsoftware/web4rail/Plan.java

10
resources/css/style.css

@ -50,3 +50,13 @@ svg text{
.menu .tile .list .tile{ .menu .tile .list .tile{
position: relative; position: relative;
} }
#messages{
display: none;
position: fixed;
bottom: 5px;
right: 5px;
padding: 5px;
border-radius: 5px;
background: yellow;
}

23
resources/js/plan.js

@ -5,21 +5,30 @@ const SVG = 'svg';
var selected = null; var selected = null;
var mode = null; var mode = null;
function addMessage(txt){
$('#messages').html(txt).show().delay(1000).fadeOut();
}
function addTile(tile,x,y){ function addTile(x,y){
console.log("addTile:",tile.id,x,y); console.log("addTile:",selected.id,x,y);
x = Math.floor(x/SQUARE); x = Math.floor(x/SQUARE);
y = Math.floor(y/SQUARE); y = Math.floor(y/SQUARE);
$.ajax({ $.ajax({
url : 'plan', url : 'plan',
method: 'POST', 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; var id = 'tile-'+x+'-'+y;
$('#'+id).remove(); $('#'+id).remove();
var tile = $(tile).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id); console.log("x: ",x);
console.log(tile); var tile = $(selected).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
$(BODY).append(tile); $(BODY).append(tile);
addMessage(resp);
}
});
} }
function bodyClick(ev){ function bodyClick(ev){
@ -28,7 +37,7 @@ function bodyClick(ev){
case undefined: case undefined:
case null: return; case null: return;
case ADD: case ADD:
return addTile(selected,ev.clientX,ev.clientY); return addTile(ev.clientX,ev.clientY);
} }
console.log(ev.clientX,ev.clientY); console.log(ev.clientX,ev.clientY);
} }

16
src/main/java/de/srsoftware/web4rail/Application.java

@ -106,12 +106,20 @@ public class Application {
} }
private static void send(HttpExchange client, Page response) throws IOException { private static void send(HttpExchange client, Page response) throws IOException {
client.getResponseHeaders().set("content-type", "text/plain"); byte[] html = response.html().toString().getBytes(UTF8);
StringBuffer html = response.html();
client.getResponseHeaders().add("content-type", "text/html"); client.getResponseHeaders().add("content-type", "text/html");
client.sendResponseHeaders(200, html.length()); client.sendResponseHeaders(200, html.length);
OutputStream os = client.getResponseBody(); 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(); os.close();
} }

16
src/main/java/de/srsoftware/web4rail/Plan.java

@ -59,8 +59,11 @@ public class Plan {
page.append("\t\t"+tile.html()+"\n"); page.append("\t\t"+tile.html()+"\n");
} }
} }
page.append(menu()); return page.append(menu()).append(messages());
return page; }
private Tag messages() {
return new Tag("div").id("messages").content("");
} }
private Tag menu() throws IOException { private Tag menu() throws IOException {
@ -84,8 +87,7 @@ public class Plan {
return menu; return menu;
} }
public Page process(HashMap<String, String> params) { public String process(HashMap<String, String> params) {
Page page = new Page();
try { try {
String mode = params.get(MODE); String mode = params.get(MODE);
@ -93,13 +95,13 @@ public class Plan {
switch (mode) { switch (mode) {
case MODE_ADD: case MODE_ADD:
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y)); 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: default:
LOG.warn("Unknown mode: {}",mode); LOG.warn("Unknown mode: {}",mode);
} }
return page.append("unknown "+MODE+": "+mode); return t("unknown mode: {}",mode);
} catch (Exception e) { } catch (Exception e) {
return page.append(e.getMessage()); return e.getMessage();
} }
} }

Loading…
Cancel
Save