BrightSide Workbench Full Report + Source Code
PendingCommentGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zul.commentit;
20 
21 import org.turro.command.CommandUtil;
22 import org.turro.commentit.CommentItUtil;
23 import org.turro.contacts.CommentIt;
24 import org.turro.contacts.db.ContactsPU;
25 import org.turro.elephant.context.Application;
26 import org.turro.elephant.util.Messages;
27 import org.turro.html.HTMLEntities;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.turro.zkoss.label.LabelExtended;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.EventListener;
33 import org.zkoss.zk.ui.event.Events;
34 import org.zkoss.zk.ui.ext.AfterCompose;
35 import org.zkoss.zul.Button;
36 import org.zkoss.zul.Column;
37 import org.zkoss.zul.Columns;
38 import org.zkoss.zul.Hlayout;
39 import org.zkoss.zul.Label;
40 import org.zkoss.zul.Row;
41 import org.zkoss.zul.Rows;
42 
47 public class PendingCommentGrid extends PagingGrid implements AfterCompose {
48 
49  private Rows rows;
50  private Application app = Application.getApplication();
51 
52  public PendingCommentGrid() {
53  addColumns();
54  }
55 
56  @Override
57  public void afterCompose() {
58  addRows();
59  }
60 
61  private void addColumns() {
62  Columns cols = new Columns();
63  cols.setSizable(true);
64  cols.setMenupopup("auto");
65  appendChild(cols);
66 
67  Column col = new Column(I_.get("Date"), null, "200px");
68  cols.appendChild(col);
69 
70  col = new Column(I_.get("Author"), null, "250px");
71  cols.appendChild(col);
72 
73  col = new Column(I_.get("Comment"));
74  cols.appendChild(col);
75 
76  col = new Column(I_.get("Entity"));
77  cols.appendChild(col);
78 
79  col = new Column("", null, "250px");
80  cols.appendChild(col);
81  }
82 
83  private void addRows() {
84  if(rows == null) {
85  rows = new Rows();
86  appendChild(rows);
87  } else {
88  rows.getChildren().clear();
89  }
90 
91  for(final CommentIt ci : CommentItUtil.pending()) {
92  final Row row = new Row();
93  row.setValign("top");
94  rows.appendChild(row);
95 
96  LabelExtended lext = new LabelExtended();
97  lext.setDate(ci.getDateCreation());
98  lext.setSclass("ldate");
99  row.appendChild(lext);
100 
101  Label author = new Label(
102  ci.getName() + " (" +
103  ci.getEmail() +
104  ") " +
105  " " + ci.getWeb() + " " +
106  ci.getAuthor_ip());
107  author.setSclass("lauthor");
108  row.appendChild(author);
109 
110  Label body = new Label(HTMLEntities.unescape(ci.getBody()));
111  body.setSclass("lbody");
112  row.appendChild(body);
113 
114  row.appendChild(CommandUtil.getLinkOrSpace(ci.getPath()));
115 
116  if(app.isInRole("publication:accept")) {
117  Hlayout hbox = new Hlayout();
118  Button confirm = new Button(I_.get("Accept"));
119  confirm.addEventListener(Events.ON_CLICK, new EventListener() {
120  @Override
121  public void onEvent(Event event) throws Exception {
122  Messages.confirmAcceptation().show(() -> {
123  CommentItUtil.acceptComment(ci);
124  row.detach();
125  });
126  }
127  });
128  hbox.appendChild(confirm);
129  Button delete = new Button(I_.get("Delete"));
130  delete.addEventListener(Events.ON_CLICK, new EventListener() {
131  @Override
132  public void onEvent(Event event) throws Exception {
133  Messages.confirmDeletion().show(() -> {
134  new ContactsPU().deleteObject(ci);
135  row.detach();
136  });
137  }
138  });
139  hbox.appendChild(delete);
140  row.appendChild(hbox);
141  }
142  }
143  }
144 
145 }
static String get(String msg)
Definition: I_.java:41