18 package org.turro.attach.zul.navigator;
20 import org.turro.action.Contacts;
21 import org.turro.attach.db.AttachPU;
22 import org.turro.attach.entity.Attachment;
23 import org.turro.attach.version.AttachVersionSet;
24 import org.turro.attach.zul.AttachmentUtil;
25 import org.turro.attach.zul.PreviewButton;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.util.DateFormats;
28 import org.turro.elephant.util.Messages;
29 import org.turro.i18n.I_;
30 import org.turro.plugin.contacts.IContact;
31 import org.turro.zkoss.label.LabelEditable;
32 import org.turro.zkoss.layout.GridLayout;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zul.*;
45 private boolean readOnly;
49 this.readOnly = readOnly;
50 setSclass(getSclass() +
" attachVersions");
55 private void addRows() {
60 Row blocked =
new Row();
61 rows.appendChild(blocked);
62 blocked.appendChild(
new Image(
"/_zul/images/locked.png"));
67 blocked.appendChild(
new Label(contact.
getName()));
71 final Row row =
new Row();
73 rows.appendChild(row);
74 if(!a.isValidated()) {
75 row.setSclass(
"draft");
78 A down =
new A(
null,
"/_zul/images/download.png");
79 down.addEventListener(Events.ON_CLICK,
new EventListener() {
81 public void onEvent(Event event)
throws Exception {
82 AttachmentUtil.download(a);
85 row.appendChild(down);
86 final Datebox dbox =
new Datebox(a.getModification());
87 dbox.setWidth(
"150px");
88 dbox.setFormat(DateFormats.getDefaultDateTimeFormat());
89 dbox.setInplace(
true);
90 dbox.setReadonly(!app.
isInRole(
"attach:date"));
91 dbox.addEventListener(Events.ON_CHANGE,
new EventListener() {
93 public void onEvent(Event event)
throws Exception {
94 a.setModification(dbox.getValue());
95 new AttachPU().saveObject(a);
98 row.appendChild(dbox);
99 PreviewButton ap =
new PreviewButton(a);
101 final Checkbox validated =
new Checkbox();
102 validated.setChecked(a.isValidated());
103 validated.setDisabled(!app.
isInRole(
"attach:validate"));
104 validated.addEventListener(Events.ON_CHECK,
new EventListener() {
106 public void onEvent(Event event)
throws Exception {
107 a.setValidated(validated.isChecked());
108 new AttachPU().saveObject(a);
109 if(!a.isValidated()) {
110 row.setSclass(
"draft");
116 row.appendChild(validated);
117 row.appendChild(
new Label(
new org.turro.formatter.BytesFormatter(a.getFileSize()).toString()));
118 IContact contact = Contacts.getEmpty();
119 if(contact !=
null) {
121 row.appendChild(
new Label(contact.getName()));
123 row.appendChild(
new Space());
126 final LabelEditable comment =
new LabelEditable(a.getComment(),
"/_zul/images/comment.png");
127 comment.setWidth(
"100%");
128 comment.setEditorCols(-1);
129 comment.addEventListener(Events.ON_CHANGE,
new EventListener() {
131 public void onEvent(Event event)
throws Exception {
132 a.setComment(comment.getLabel());
133 new AttachPU().saveObject(a);
136 row.appendChild(comment);
137 comment.afterCompose();
139 row.appendChild(
new Label(a.getComment()));
141 if(a.getId() != avs.first().getId() && !readOnly) {
143 delete.setWidth(
"30px");
144 delete.setImage(
"/_zul/images/edit-delete.png");
145 delete.setTooltiptext(I_.get(
"Delete"));
146 delete.addEventListener(Events.ON_CLICK,
new EventListener() {
148 public void onEvent(Event event)
throws Exception {
149 Messages.confirmDeletion().show(() -> {
150 if(a.getPath().startsWith(
"/Trash")) {
151 if(app.isInRole(
"attach:delete")) {
152 new AttachPU().deleteObject(a);
155 a.setPath(
"/Trash" + a.getPath());
156 new AttachPU().saveObject(a);
162 row.appendChild(
delete);
164 row.appendChild(
new Space());
AttachVersionGrid(AttachVersionSet avs, boolean readOnly)
boolean isInRole(String role)
static Application getApplication()
void setColumns(int columns)
Rows getRows(boolean create)