working on action management
This commit is contained in:
@@ -135,6 +135,8 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
case "SetSignalsToStop":
|
||||
add(new SetSignalsToStop());
|
||||
break;
|
||||
case "SpeedReduction":
|
||||
return SpeedReduction.propForm(this,params);
|
||||
case "TurnTrain":
|
||||
add(new TurnTrain());
|
||||
break;
|
||||
@@ -163,4 +165,8 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
select.addTo(new Label("Action type:")).addTo(typeForm);
|
||||
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm).addTo(win);
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,16 @@ import java.util.HashMap;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
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 Action{
|
||||
|
||||
public static final String MAX_SPEED = "max_speed";
|
||||
private int maxSpeed;
|
||||
private int maxSpeed = -1;
|
||||
|
||||
public SpeedReduction(int kmh) {
|
||||
super();
|
||||
@@ -39,7 +37,7 @@ public class SpeedReduction extends Action{
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Window propForm(HashMap<String, String> params, Route route, Contact contact) {
|
||||
public static Object propForm(ActionList actionList, HashMap<String, String> params) {
|
||||
String error = null;
|
||||
String ms = params.get(MAX_SPEED);
|
||||
if (ms == null) {
|
||||
@@ -49,25 +47,22 @@ public class SpeedReduction extends Action{
|
||||
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(s));
|
||||
contact.plan().stream("Action added!");
|
||||
return route.properties();
|
||||
actionList.add(new SpeedReduction(s));
|
||||
return t("Action added!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
error = t("Not a valid number!");
|
||||
}
|
||||
}
|
||||
Window win = Action.propForm(params);
|
||||
String formId = "add-action-to-contact-"+contact.id();
|
||||
String formId = "edit-speedreduction";
|
||||
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(REALM, REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,actionList.id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_ADD).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);
|
||||
//if (error != null) new Tag("div").content(error).addTo(form);
|
||||
new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(form).addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user