19 package org.turro.web.funnel.model;
21 import java.util.List;
22 import org.turro.elephant.db.ElephantPU;
23 import org.turro.elephant.entities.web.WebGoal;
24 import org.turro.elephant.util.Messages;
25 import org.turro.elephant.util.Toasts;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.Dao;
28 import org.turro.sql.SqlClause;
29 import org.turro.util.Cached;
30 import org.turro.zkoss.dialog.DialogField;
31 import org.turro.zkoss.dialog.Dialogs;
32 import org.zkoss.bind.BindUtils;
33 import org.zkoss.bind.annotation.NotifyChange;
34 import org.zkoss.zk.ui.Executions;
35 import org.zkoss.zul.Textbox;
48 this.selected = selected;
50 "selected",
"showForm",
"nextsModel");
54 return selected !=
null;
63 String goalAction = dialogs.<Textbox>getEditor(
"GoalAction").getValue();
64 if(notInModel(goalAction)) {
71 "model",
"selected",
"showForm");
73 Toasts.
message(
"GoalActions should not include spaces or punctuation characters.").
show();
83 @NotifyChange({
"model",
"selected",
"showForm"})
85 model.stream().filter(wi -> wi.isEmpty() && !wi.isNew())
86 .forEach(wi -> dao.get().deleteEntity(wi));
87 model.removeIf(wi -> wi.isEmpty());
88 model.forEach(wi -> wi.compose());
89 dao.get().saveEntities(model);
90 Executions.getCurrent().sendRedirect(
"");
93 public void delete() {
95 dao.get().deleteObject(selected);
96 Executions.getCurrent().sendRedirect(
"");
102 private boolean notInModel(String actionGoal) {
103 return !
getModel().stream().anyMatch(wg -> wg.getGoalAction().equals(actionGoal));
110 private List<WebGoal> model;
114 model = SqlClause.select(
"wg").from(
"WebGoal wg")
115 .orderBy(
"ordering, goalAction")
124 private final Cached<Dao> dao = Cached.instance(() ->
new ElephantPU());
void setGoalAction(String goalAction)
static Messages confirmDeletion()
Messages add(String word)
static Toasts message(String message)
static String get(String msg)
List< WebGoal > getModel()
void setSelected(WebGoal selected)
static DialogField field(String label)
Dialogs width(String width)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
static Dialogs title(String title)
Dialogs addField(DialogField field)