implemented renaming of routes
This commit is contained in:
@@ -75,6 +75,7 @@ public class Plan {
|
||||
private static final String DIRECTION = "direction";
|
||||
private static final String ACTION_ROUTE = "openRoute";
|
||||
private static final String ID = "id";
|
||||
private static final String ROUTE = "route";
|
||||
|
||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||
private HashSet<Block> blocks = new HashSet<Block>();
|
||||
@@ -296,14 +297,18 @@ public class Plan {
|
||||
return route.properties();
|
||||
}
|
||||
|
||||
private Page update(HashMap<String, String> params) throws IOException {
|
||||
return update(Integer.parseInt(params.get("x")),Integer.parseInt(params.get("y")),params);
|
||||
private Object update(HashMap<String, String> params) throws IOException {
|
||||
if (params.containsKey(ROUTE)) {
|
||||
Route route = routes.get(params.get(ROUTE));
|
||||
if (route == null) return t("Unknown route: {}",params.get(ROUTE));
|
||||
route.update(params);
|
||||
} else update(Integer.parseInt(params.get("x")),Integer.parseInt(params.get("y")),params);
|
||||
return this.html();
|
||||
}
|
||||
|
||||
private Page update(int x,int y, HashMap<String, String> params) throws IOException {
|
||||
private void update(int x,int y, HashMap<String, String> params) throws IOException {
|
||||
Tile tile = get(x,y);
|
||||
if (tile != null) set(x,y,tile.update(params));
|
||||
return this.html();
|
||||
}
|
||||
|
||||
private Tag propMenu(String x, String y) {
|
||||
|
||||
@@ -5,9 +5,13 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
import de.srsoftware.web4rail.tiles.Shadow;
|
||||
@@ -17,7 +21,8 @@ import de.srsoftware.web4rail.tiles.Turnout;
|
||||
import de.srsoftware.web4rail.tiles.Turnout.State;
|
||||
|
||||
public class Route {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Route.class);
|
||||
private static final String NAME = "name";
|
||||
private Vector<Tile> path;
|
||||
private Vector<Signal> signals;
|
||||
private Vector<Contact> contacts;
|
||||
@@ -99,9 +104,25 @@ public class Route {
|
||||
Plan.addLink(turnout, turnout+": "+entry.getValue(), list);
|
||||
}
|
||||
list.addTo(win);
|
||||
|
||||
Tag form = propForm();
|
||||
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
||||
form.addTo(win);
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
public Tag propForm() {
|
||||
Form form = new Form();
|
||||
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
||||
new Tag("input").attr("type", "hidden").attr("name","route").attr("value", id()).addTo(form);
|
||||
|
||||
Tag label = new Tag("label").content(t("name:"));
|
||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||
label.addTo(form);
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
public Route start(Block block) {
|
||||
contacts = new Vector<Contact>();
|
||||
@@ -130,4 +151,9 @@ public class Route {
|
||||
Tile lastTile = path.lastElement();
|
||||
if (lastTile instanceof Turnout) turnouts.put((Turnout) lastTile,state);
|
||||
}
|
||||
|
||||
public void update(HashMap<String, String> params) {
|
||||
LOG.debug("update({})",params);
|
||||
if (params.containsKey(NAME)) name = params.get(NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class Tile {
|
||||
new Tag("h4").content(t("Routes using this tile:")).addTo(form);
|
||||
Tag routeList = new Tag("ul");
|
||||
for (Route route : routes) {
|
||||
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.id()).addTo(routeList);
|
||||
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.name()).addTo(routeList);
|
||||
}
|
||||
routeList.addTo(form);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user