overhauled storing and loading code for routes, actions and conditions
This commit is contained in:
@@ -52,6 +52,15 @@ public abstract class Condition implements Constants {
|
||||
return new JSONObject().put(TYPE, getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public static Condition load(JSONObject json) {
|
||||
String type = json.getString(TYPE);
|
||||
switch (type) {
|
||||
case "TrainSelect":
|
||||
return TrainSelect.load(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tag link(String tagClass,String context) {
|
||||
String json = new JSONObject(Map.of(REALM,REALM_CONDITION,ID,id,ACTION,ACTION_PROPS,CONTEXT,context)).toString().replace("\"", "'");
|
||||
return new Tag(tagClass).clazz("link").attr("onclick","request("+json+")").content(toString());
|
||||
|
||||
@@ -27,6 +27,11 @@ public class TrainSelect extends Condition {
|
||||
return super.json().put(REALM_TRAIN, train.id);
|
||||
}
|
||||
|
||||
public static TrainSelect load(JSONObject json) {
|
||||
int trainId = json.getInt(REALM_TRAIN);
|
||||
return new TrainSelect().train(Train.get(trainId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(HashMap<String, String> params) {
|
||||
Window win = new Window("condition-props", t("Properties of {}",getClass().getSimpleName()));
|
||||
@@ -46,6 +51,12 @@ public class TrainSelect extends Condition {
|
||||
if (train == null) return super.toString();
|
||||
return t("Train = {}",train);
|
||||
}
|
||||
|
||||
private TrainSelect train(Train train) {
|
||||
this.train = train;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
|
||||
Reference in New Issue
Block a user