implemented adding and removal of action to contact on route.
This commit is contained in:
@@ -42,11 +42,11 @@ public abstract class Action {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object propForm(HashMap<String, String> params) {
|
||||
public static Window propForm(HashMap<String, String> params) {
|
||||
return new Window("action-props", "Action properties");
|
||||
}
|
||||
|
||||
protected String t(String tex,Object...fills) {
|
||||
protected static String t(String tex,Object...fills) {
|
||||
return Translation.get(Application.class, tex, fills);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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.tiles.Contact;
|
||||
|
||||
public class SpeedReduction extends RouteAction {
|
||||
public class SpeedReduction extends RouteAction implements Constants{
|
||||
|
||||
static final String MAX_SPEED = "max_speed";
|
||||
public static final String MAX_SPEED = "max_speed";
|
||||
private int maxSpeed;
|
||||
|
||||
public SpeedReduction(int routeId, int kmh) {
|
||||
@@ -28,6 +38,39 @@ public class SpeedReduction extends RouteAction {
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Window propForm(HashMap<String, String> params, Route route, Contact contact) {
|
||||
String error = null;
|
||||
String ms = params.get(MAX_SPEED);
|
||||
if (ms == null) {
|
||||
ms = ""+128;
|
||||
} else {
|
||||
try {
|
||||
int s = Integer.parseInt(ms);
|
||||
if (s<0) error = t("Speed must not be less than zero!");
|
||||
if (error == null) {
|
||||
route.addAction(contact.trigger(),new SpeedReduction(route.id(), s));
|
||||
contact.plan().stream("Action added!");
|
||||
return null;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
error = t("Not a valid number!");
|
||||
}
|
||||
}
|
||||
Window win = Action.propForm(params);
|
||||
String formId = "add-action-to-contact-"+contact.id();
|
||||
Tag form = new Form(formId);
|
||||
new Tag("div").content(t("Add Action {} to contact {} on route {}:",SpeedReduction.class.getSimpleName(),contact,route)).addTo(win);
|
||||
new Input(REALM, REALM_ROUTE).hideIn(form);
|
||||
new Input(ID,route.id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_ADD_ACTION).hideIn(form);
|
||||
new Input(CONTACT,contact.id()).hideIn(form);
|
||||
new Input(TYPE,SpeedReduction.class.getSimpleName()).hideIn(form);
|
||||
new Input(MAX_SPEED, ms).addTo(new Label("new speed")).addTo(form);
|
||||
if (error != null) new Tag("div").content(error).addTo(form);
|
||||
new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(form).addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t("Reduce speed to {} km/h",maxSpeed);
|
||||
|
||||
Reference in New Issue
Block a user