updating actions

This commit is contained in:
Stephan Richter
2020-12-03 00:03:10 +01:00
parent a7f252de7f
commit 0c2d2eaa8e
30 changed files with 298 additions and 368 deletions

View File

@@ -1,49 +1,32 @@
package de.srsoftware.web4rail.actions;
import java.util.HashMap;
import java.util.List;
import org.json.JSONObject;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Fieldset;
import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Input;
import de.srsoftware.web4rail.tags.Label;
public class DelayedAction extends Action {
public DelayedAction(Context parent) {
super(parent);
}
private static final String ACTIONS = "actions";
public static final String DELAY = "delay";
private static final int DEFAULT_DELAY = 1000;
private int delay = DEFAULT_DELAY;
private ActionList actions = new ActionList();
private Tag actionsForm(HashMap<String, String> params) {
Fieldset fieldset = new Fieldset(t("Actions"));
actions.addTo(fieldset, params.get(CONTEXT));
return fieldset;
}
public ActionList children() {
return actions;
}
private Tag delayForm(HashMap<String, String> params) {
Fieldset fieldset = new Fieldset(t("Delay"));
Form form = new Form("action-prop-form-"+id);
new Input(REALM,REALM_ACTIONS).hideIn(form);
new Input(ID,params.get(ID)).hideIn(form);
new Input(ACTION,ACTION_UPDATE).hideIn(form);
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
new Input(DELAY,delay).numeric().addTo(new Label(t("Delay")+NBSP)).content(NBSP+"ms").addTo(form);
return new Button(t("Apply"),form).addTo(form).addTo(fieldset);
}
public boolean equals(DelayedAction other) {
return (delay+":"+actions).equals(other.delay+":"+other.actions);
}
@@ -68,23 +51,23 @@ public class DelayedAction extends Action {
public JSONObject json() {
JSONObject json = super.json();
json.put(DELAY, delay);
json.put(ACTIONS, actions.json());
json.put(ACTIONS, actions.jsonArray());
return json;
}
public DelayedAction load(JSONObject json) {
super.load(json);
delay = json.getInt(DELAY);
if (json.has(ACTIONS)) actions = ActionList.load(json.getJSONArray(ACTIONS));
if (json.has(ACTIONS)) actions = new ActionList().load(json.getJSONArray(ACTIONS));
return this;
}
@Override
public Window properties(HashMap<String, String> params) {
Window win = super.properties(params);
delayForm(params).addTo(win);
actionsForm(params).addTo(win);
return win;
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
formInputs.add(t("Delay"),new Input(DELAY,delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
postForm.add(actions.list());
return super.properties(preForm, formInputs, postForm);
}
@Override
@@ -100,7 +83,7 @@ public class DelayedAction extends Action {
if (ms < 0) throw new NumberFormatException(t("Delay must not be less than zero!"));
delay = ms;
} catch (NumberFormatException nfe) {
Window props = properties(params);
Window props = properties();
props.children().insertElementAt(new Tag("div").content(nfe.getMessage()), 2);
return props;
}