more refactoring
This commit is contained in:
@@ -2,68 +2,29 @@ package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.conditions.Condition;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.conditions.ConditionList;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ConditionalAction extends ActionList {
|
||||
|
||||
private static final String CONDITIONS = "conditions";
|
||||
private static final String ACTIONS = "actions";
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private ConditionList conditions = new ConditionList();
|
||||
|
||||
public ConditionalAction(BaseClass parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private StringBuffer conditions() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i<conditions.size(); i++) {
|
||||
if (i>0) sb.append(t(" and "));
|
||||
sb.append(conditions.get(i).toString());
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
private Fieldset conditionForm() {
|
||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||
|
||||
new Tag("p").content(t("Actions will only fire, if all conditions are fullfilled.")).addTo(fieldset);
|
||||
if (!conditions.isEmpty()) {
|
||||
Tag list = new Tag("ul");
|
||||
for (Condition condition : conditions) {
|
||||
Tag li = link("span", condition+NBSP,Map.of()).addTo(new Tag("li"));
|
||||
HashMap<String,Object> props = new HashMap<String, Object>(Map.of(REALM,REALM_CONDITION,ID,condition.id(),ACTION,ACTION_DROP,CONTEXT, REALM_ACTIONS+":"+id()));
|
||||
new Button(t("delete"), props).addTo(li).addTo(list);
|
||||
}
|
||||
list.addTo(fieldset);
|
||||
}
|
||||
|
||||
Form form = new Form("action-prop-form-"+id);
|
||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
|
||||
Condition.selector().addTo(form);
|
||||
|
||||
new Button(t("Add condition"),form).addTo(form);
|
||||
button(t("Back")).addTo(form).addTo(fieldset);
|
||||
return fieldset;
|
||||
conditions.parent(this);
|
||||
}
|
||||
|
||||
public boolean equals(ConditionalAction other) {
|
||||
return (conditions()+":"+actions).equals(other.conditions()+":"+other.actions);
|
||||
return (conditions+":"+actions).equals(other.conditions+":"+other.actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,10 +64,7 @@ public class ConditionalAction extends ActionList {
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(conditionForm());
|
||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||
list().addTo(fieldset);
|
||||
postForm.add(fieldset);
|
||||
preForm.add(conditions.list());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
|
||||
}
|
||||
@@ -118,8 +76,8 @@ public class ConditionalAction extends ActionList {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (conditions.isEmpty()) return t("[Click here to add condition]");
|
||||
return t("if ({}):",conditions());
|
||||
if (conditions.isEmpty()) return "["+t("Click here to add conditions")+"]";
|
||||
return t("if ({}):",conditions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user