18 package org.turro.publication.zul.ctrl;
20 import java.util.List;
21 import org.turro.string.Strings;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.i18n.I_;
25 import org.turro.jpa.Dao;
26 import org.turro.jpa.grid.RendererOnDemand;
27 import org.turro.publication.db.PublicationPU;
28 import org.turro.publication.entity.Publication;
29 import org.turro.publication.entity.PublicationCategory;
30 import org.turro.publication.zul.menu.PublicationMenu;
31 import org.turro.tags.Tags;
32 import org.turro.zkoss.grid.PagingGrid;
33 import org.turro.zkoss.label.LabelExtended;
34 import org.zkoss.zk.ui.Component;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.event.Events;
38 import org.zkoss.zul.*;
54 addRows(idContact, accepted, category, text);
57 private void addColumns() {
58 Columns cols =
new Columns();
59 cols.setSizable(
true);
60 cols.setMenupopup(
"auto");
63 Column col =
new Column(
I_.
get(
"Date"),
null,
"200px");
64 cols.appendChild(col);
66 col =
new Column(
I_.
get(
"Author"),
null,
"250px");
67 cols.appendChild(col);
69 col =
new Column(
I_.
get(
"Title"));
70 cols.appendChild(col);
73 private void addRows(String idContact,
boolean accepted, PublicationCategory category, String text) {
75 setRowRenderer(
new RendererOnDemand<Publication, Long>(() ->
new PublicationPU()) {
77 protected void renderRow(Row row,
final Publication publication) {
78 fillRow(row, publication);
82 List<Long> list = getPublicationIds(idContact, accepted, category, text);
83 setModel(
new ListModelList<Long>(list));
89 private void fillRow(Row row,
final Publication publication) {
92 LabelExtended lext =
new LabelExtended();
93 lext.setDate(publication.getDate());
94 lext.setSclass(
"ldate");
95 row.appendChild(lext);
97 Label author =
new Label(
98 publication.getAuthor() +
" (" +
99 publication.getContactAuthor().getName() +
101 author.setSclass(
"lauthor");
102 row.appendChild(author);
104 Vbox vbox =
new Vbox();
105 Label title =
new Label(
106 Strings.isBlank(publication.getUnescapedTitle()) ?
107 I_.get(
"No description!") :
108 publication.getUnescapedTitle());
109 if(app.
isInRole(
"publication:edit")) {
110 title.addEventListener(Events.ON_CLICK,
new EventListener() {
112 public void onEvent(Event event)
throws Exception {
113 PublicationMenu.showPublication(publication.getId());
116 title.setStyle(
"cursor:pointer");
118 title.setSclass(
"ltitle");
119 vbox.appendChild(title);
121 lext =
new LabelExtended();
122 lext.setStyle(
"color:#444;font-size:11px;");
124 publication.getPublicationCategory().getName() +
126 publication.getPublicationGroup().getName()
129 vbox.appendChild(lext);
131 vbox.appendChild((Component) Tags.getControl(publication));
133 row.appendChild(vbox);
136 private List<Long> getPublicationIds(String idContact,
boolean accepted, PublicationCategory category, String text) {
137 Dao dao =
new PublicationPU();
143 wc.
addClause(
"select publication from Publication publication");
144 wc.
addClause(
"where publication.accepted = :accepted");
146 if(category !=
null) {
147 wc.
addClause(
"and publication.publicationCategory = :category");
150 if(idContact !=
null) {
151 wc.
addClause(
"and publication.idContact = :idContact");
154 if(!Strings.isBlank(text)) {
155 text =
"*" + text +
"*";
156 wc.
addClause(
"and (publication.title like :text1");
158 wc.
addClause(
"or publication.summary like :text2)");
161 wc.
addClause(
"order by publication.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 void convertUrls()
static WhereClause createPublicationCriteria(String idContact, boolean accepted, PublicationCategory category, String text)
void setValues(String idContact, boolean accepted, PublicationCategory category, String text)
void setRowCount(int rows)