preparing to add actions to contacts on route
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>0.6.13</version>
|
<version>0.6.14</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -203,6 +203,10 @@ function stream(ev){
|
|||||||
addMessage(data);
|
addMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submitForm(formId){
|
||||||
|
return request($('#'+formId).serialize());
|
||||||
|
}
|
||||||
|
|
||||||
function swapTiling(ev){
|
function swapTiling(ev){
|
||||||
var vertical = getCookie("tiling") == 'v';
|
var vertical = getCookie("tiling") == 'v';
|
||||||
document.cookie = "tiling="+(vertical?'h':'v');
|
document.cookie = "tiling="+(vertical?'h':'v');
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import de.srsoftware.web4rail.moving.Train;
|
|||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.Contact;
|
import de.srsoftware.web4rail.tiles.Contact;
|
||||||
import de.srsoftware.web4rail.tiles.Shadow;
|
import de.srsoftware.web4rail.tiles.Shadow;
|
||||||
@@ -65,6 +67,21 @@ public class Route implements Constants{
|
|||||||
private static final String TRIGGER = "trigger";
|
private static final String TRIGGER = "trigger";
|
||||||
private static final String ACTIONS = "actions";
|
private static final String ACTIONS = "actions";
|
||||||
private static final String CONTACT = "contact";
|
private static final String CONTACT = "contact";
|
||||||
|
private static final String TYPE = "type";
|
||||||
|
|
||||||
|
private Tag actionTypeForm(Contact contact) {
|
||||||
|
String formId ="add-action-to-contact-"+contact.id();
|
||||||
|
Tag typeForm = new Form().id(formId);
|
||||||
|
new Input(REALM, REALM_ROUTE).hideIn(typeForm);
|
||||||
|
new Input(ID,id()).hideIn(typeForm);
|
||||||
|
new Input(ACTION,ACTION_ADD_ACTION).hideIn(typeForm);
|
||||||
|
new Input(CONTACT,contact.id()).hideIn(typeForm);
|
||||||
|
Select select = new Select(TYPE);
|
||||||
|
List<Class<? extends Action>> classes = List.of(SpeedReduction.class);
|
||||||
|
for (Class<? extends Action> clazz : classes) select.addOption(clazz.getSimpleName());
|
||||||
|
select.addTo(new Label("Action type:")).addTo(typeForm);
|
||||||
|
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route wurde von Zug betreten
|
* Route wurde von Zug betreten
|
||||||
@@ -108,9 +125,17 @@ public class Route implements Constants{
|
|||||||
Window win = new Window("add-action-form", t("Add action to contact on route"));
|
Window win = new Window("add-action-form", t("Add action to contact on route"));
|
||||||
new Tag("div").content("Route: "+this).addTo(win);
|
new Tag("div").content("Route: "+this).addTo(win);
|
||||||
new Tag("div").content("Contact: "+contact).addTo(win);
|
new Tag("div").content("Contact: "+contact).addTo(win);
|
||||||
|
|
||||||
|
String type = params.get(TYPE);
|
||||||
|
if (type == null) return (actionTypeForm(contact).addTo(win));
|
||||||
|
switch (type) {
|
||||||
|
case "SpeedReduction":
|
||||||
|
return SpeedReduction.propForm(params);
|
||||||
|
}
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBasicPropertiesTo(Window win) {
|
private void addBasicPropertiesTo(Window win) {
|
||||||
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
||||||
Tag list = new Tag("ul");
|
Tag list = new Tag("ul");
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package de.srsoftware.web4rail.actions;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.web4rail.Application;
|
import de.srsoftware.web4rail.Application;
|
||||||
import de.srsoftware.web4rail.Plan;
|
import de.srsoftware.web4rail.Plan;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
|
||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
private static final String TYPE = "type";
|
private static final String TYPE = "type";
|
||||||
@@ -40,6 +42,10 @@ public abstract class Action {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object propForm(HashMap<String, String> params) {
|
||||||
|
return new Window("action-props", "Action properties");
|
||||||
|
}
|
||||||
|
|
||||||
protected String t(String tex,Object...fills) {
|
protected String t(String tex,Object...fills) {
|
||||||
return Translation.get(Application.class, tex, fills);
|
return Translation.get(Application.class, tex, fills);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class Button extends Tag {
|
|||||||
|
|
||||||
public Button(String text,String action) {
|
public Button(String text,String action) {
|
||||||
super("button");
|
super("button");
|
||||||
|
attr("type","button");
|
||||||
attr("onclick",action).content(text);
|
attr("onclick",action).content(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ public class Select extends Tag {
|
|||||||
super("select");
|
super("select");
|
||||||
attr("name",name);
|
attr("name",name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Tag addOption(Object value) {
|
||||||
|
return addOption(value, value);
|
||||||
|
}
|
||||||
|
|
||||||
public Tag addOption(Object value, Object text) {
|
public Tag addOption(Object value, Object text) {
|
||||||
Tag option = new Tag("option").attr("value", value.toString()).content(text.toString());
|
Tag option = new Tag("option").attr("value", value.toString()).content(text.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user