preparing to add actions to contacts on route

This commit is contained in:
Stephan Richter
2020-10-28 18:53:27 +01:00
parent 27d5b91b18
commit 648bc708ea
6 changed files with 42 additions and 2 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>0.6.13</version>
<version>0.6.14</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

View File

@@ -203,6 +203,10 @@ function stream(ev){
addMessage(data);
}
function submitForm(formId){
return request($('#'+formId).serialize());
}
function swapTiling(ev){
var vertical = getCookie("tiling") == 'v';
document.cookie = "tiling="+(vertical?'h':'v');

View File

@@ -32,6 +32,8 @@ import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Form;
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.Contact;
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 ACTIONS = "actions";
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
@@ -108,6 +125,14 @@ public class Route implements Constants{
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("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;
}

View File

@@ -2,12 +2,14 @@ package de.srsoftware.web4rail.actions;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import org.json.JSONObject;
import de.keawe.tools.translations.Translation;
import de.srsoftware.web4rail.Application;
import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Window;
public abstract class Action {
private static final String TYPE = "type";
@@ -40,6 +42,10 @@ public abstract class Action {
return null;
}
public static Object propForm(HashMap<String, String> params) {
return new Window("action-props", "Action properties");
}
protected String t(String tex,Object...fills) {
return Translation.get(Application.class, tex, fills);
}

View File

@@ -16,6 +16,7 @@ public class Button extends Tag {
public Button(String text,String action) {
super("button");
attr("type","button");
attr("onclick",action).content(text);
}

View File

@@ -10,6 +10,10 @@ public class Select extends Tag {
attr("name",name);
}
public Tag addOption(Object value) {
return addOption(value, value);
}
public Tag addOption(Object value, Object text) {
Tag option = new Tag("option").attr("value", value.toString()).content(text.toString());
option.addTo(this);