fixed actions boken by function mapping implementation
This commit is contained in:
@@ -1,5 +1,49 @@
|
||||
package de.srsoftware.web4rail.functions;
|
||||
|
||||
public class CustomFunction extends Function {
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.web4rail.Params;
|
||||
import de.srsoftware.web4rail.devices.Decoder;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class CustomFunction extends Function {
|
||||
private String customName = super.name();
|
||||
|
||||
@Override
|
||||
public Fieldset form(Decoder decoder) {
|
||||
Fieldset fieldset = super.form(decoder);
|
||||
String prefix = "functions/"+id()+"/";
|
||||
new Input(prefix+NAME, customName)
|
||||
.addTo(new Label(t("Name")))
|
||||
.addTo(fieldset);
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
json.put(NAME, customName);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomFunction load(JSONObject json) {
|
||||
super.load(json);
|
||||
if (json.has(NAME)) customName = json.getString(NAME);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object update(Params params) {
|
||||
String newName = params.getString(NAME);
|
||||
if (isSet(newName) && !newName.isEmpty()) customName = newName;
|
||||
return super.update(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
public abstract class Function extends BaseClass{
|
||||
|
||||
public static final String NEW = "new_function";
|
||||
public static final String SELECTOR = "selected_fun";
|
||||
private static final String PACKAGE = Function.class.getPackageName();
|
||||
private static final String INDEX = "index";
|
||||
static final String FORWARD = "forward";
|
||||
@@ -93,15 +93,21 @@ public abstract class Function extends BaseClass{
|
||||
return t(type());
|
||||
}
|
||||
|
||||
public static Tag selector() {
|
||||
Select selector = new Select(NEW);
|
||||
selector.addOption("", t("Select function"));
|
||||
public static Select selector() {
|
||||
return selector(null);
|
||||
}
|
||||
|
||||
public static Select selector(String preselect) {
|
||||
Select selector = new Select(SELECTOR);
|
||||
selector.addOption("", "["+t("Select function")+"]");
|
||||
|
||||
for (Class<? extends Function> fun : List.of(HeadLight.class,TailLight.class,InteriorLight.class,Coupler.class,CustomFunction.class)) {
|
||||
String className = fun.getSimpleName();
|
||||
selector.addOption(className,t(className));
|
||||
String name = t(className);
|
||||
Tag option = selector.addOption(className,name);
|
||||
if (name.equals(t(preselect))) option.attr("selected", "selected");
|
||||
}
|
||||
|
||||
selector.children().sort((c1,c2) -> c1.children().toString().compareToIgnoreCase(c2.children().toString()));
|
||||
return selector;
|
||||
}
|
||||
|
||||
@@ -115,7 +121,7 @@ public abstract class Function extends BaseClass{
|
||||
return name()+"("+decoderFunction+"="+enabled+")";
|
||||
}
|
||||
|
||||
private String type() {
|
||||
protected String type() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user