19 package org.turro.newsletter;
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.action.queue.NotificationCategory;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.Dao;
28 import org.turro.jpa.grid.RendererOnDemand;
29 import org.turro.publication.db.PublicationPU;
30 import org.turro.publication.entity.Newsletter;
31 import org.turro.publication.zul.menu.PublicationMenu;
32 import org.turro.tags.Tags;
33 import org.turro.zkoss.grid.PagingGrid;
34 import org.turro.zkoss.label.LabelExtended;
35 import org.zkoss.zk.ui.Component;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zul.Column;
40 import org.zkoss.zul.Columns;
41 import org.zkoss.zul.Label;
42 import org.zkoss.zul.ListModelList;
43 import org.zkoss.zul.Row;
44 import org.zkoss.zul.Vlayout;
59 addRows(accepted, category, text);
62 private void addColumns() {
63 Columns cols =
new Columns();
64 cols.setSizable(
true);
65 cols.setMenupopup(
"auto");
68 Column col =
new Column(
I_.
get(
"Date"),
null,
"200px");
69 cols.appendChild(col);
71 col =
new Column(
I_.
get(
"Title"));
72 cols.appendChild(col);
75 private void addRows(
boolean accepted, NotificationCategory category, String text) {
77 setRowRenderer(
new RendererOnDemand<Newsletter, Long>(() ->
new PublicationPU()) {
79 protected void renderRow(Row row,
final Newsletter newsletter) {
80 fillRow(row, newsletter);
84 List<Long> list = getNewsletterIds(accepted, category, text);
85 setModel(
new ListModelList<Long>(list));
91 private void fillRow(Row row,
final Newsletter newsletter) {
94 LabelExtended lext =
new LabelExtended();
95 lext.setDate(newsletter.getDate());
96 lext.setSclass(
"ldate");
97 row.appendChild(lext);
99 Vlayout vbox =
new Vlayout();
100 Label title =
new Label(
101 Strings.isBlank(newsletter.getUnescapedTitle()) ?
102 I_.get(
"No description!") :
103 newsletter.getUnescapedTitle());
104 if(app.
isInRole(
"publication:edit")) {
105 title.addEventListener(Events.ON_CLICK,
new EventListener() {
107 public void onEvent(Event event)
throws Exception {
108 PublicationMenu.showNewsletter(newsletter.getId());
111 title.setStyle(
"cursor:pointer");
113 title.setSclass(
"ltitle");
114 vbox.appendChild(title);
116 lext =
new LabelExtended();
117 lext.setStyle(
"color:#444;font-size:11px;");
118 lext.setValue(I_.get(newsletter.getCategory().getCategory()));
120 vbox.appendChild(lext);
127 vbox.appendChild((Component) Tags.getControl(newsletter));
129 row.appendChild(vbox);
132 private List<Long> getNewsletterIds(
boolean accepted, NotificationCategory category, String text) {
133 Dao dao =
new PublicationPU();
139 wc.
addClause(
"select newsletter from Newsletter newsletter");
140 wc.
addClause(
"where newsletter.accepted = :accepted");
142 if(category !=
null) {
143 wc.
addClause(
"and newsletter.idCategory = :category");
146 if(!Strings.isBlank(text)) {
147 text =
"*" + text +
"*";
148 wc.
addClause(
"and newsletter.title like :text1");
152 wc.
addClause(
"order by newsletter.date DESC");
boolean isInRole(String role)
static Application getApplication()
void addClause(String clause)
void addNamedValue(String name, Object value)
static String get(String msg)
static WhereClause createNewsletterCriteria(boolean accepted, NotificationCategory category, String text)
void setValues(boolean accepted, NotificationCategory category, String text)
void setRowCount(int rows)