18 package org.turro.attach.zul.navigator;
21 import org.turro.action.Plugins;
22 import org.turro.attach.db.AttachPU;
23 import org.turro.attach.entity.Attachment;
24 import org.turro.attach.version.AttachVersionSet;
25 import org.turro.attach.version.AttachmentData;
26 import org.turro.attach.zul.AttachmentUtil;
27 import org.turro.attach.zul.PreviewButton;
28 import org.turro.auth.Authentication;
29 import org.turro.command.Command;
30 import org.turro.command.Context;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.util.DateFormats;
34 import org.turro.elephant.util.Messages;
35 import org.turro.i18n.I_;
36 import org.turro.log.ILogButton;
37 import org.turro.log.SystemLogger;
38 import org.turro.plugin.acceptance.IAcceptanceCtrl;
39 import org.turro.tags.Tags;
40 import org.turro.wd.entities.AttachWd;
41 import org.turro.mail.recipients.SendAttachments;
42 import org.turro.zkoss.dialog.InputDialog;
43 import org.turro.zkoss.dialog.InputField;
44 import org.turro.zkoss.label.LabelTypes;
45 import org.zkoss.zk.ui.Component;
46 import org.zkoss.zk.ui.event.Event;
47 import org.zkoss.zk.ui.event.EventListener;
48 import org.zkoss.zk.ui.event.Events;
49 import org.zkoss.zul.*;
58 private final boolean readOnly;
60 private Detail detail;
64 this.readOnly = readOnly;
65 attachment = avs.first();
67 setStyle(
"cursor:pointer");
75 private void loadData() {
76 getChildren().clear();
83 Hlayout hbox =
new Hlayout();
85 A a =
new A(attachment.
getFileName(), getMimeImage(attachment));
87 a.addEventListener(Events.ON_CLICK,
new EventListener() {
89 public void onEvent(Event event)
throws Exception {
90 detail.setOpen(!detail.isOpen());
96 Image locked =
new Image(
"/_zul/images/locked.png");
97 locked.setWidth(
"20px");
98 hbox.appendChild(locked);
100 PreviewButton preview =
new PreviewButton(attachment);
101 preview.setWidth(
"20px");
102 hbox.appendChild(preview);
103 PublishedButton published =
new PublishedButton(attachment);
104 published.setWidth(
"20px");
105 hbox.appendChild(published);
107 appendChild(getSizeComponent());
108 appendChild(
new Label(DateFormats.format(attachment.
getModification(),
false)));
111 private String getMimeImage(Attachment attachment) {
112 if(!
new File(ElephantContext.getRealPath(
"/_internal/system/mime/" + attachment.getFileExtension() +
".png")).exists()) {
113 return "/_internal/system/mime/empty.png";
115 return "/_internal/system/mime/" + attachment.getFileExtension() +
".png";
119 private boolean _listenerAttached =
false;
120 private boolean _onOpenTriggered =
false;
122 private void addDetail() {
123 detail =
new Detail();
126 detail.addEventListener(Events.ON_OPEN,
new EventListener() {
128 public void onEvent(Event event)
throws Exception {
129 _onOpenTriggered =
true;
134 if(!_listenerAttached) {
135 addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
137 public void onEvent(Event event) throws Exception {
138 if(_onOpenTriggered) {
139 _onOpenTriggered = false;
142 detail.setOpen(!detail.isOpen());
146 _listenerAttached =
true;
150 private void fillDetail() {
151 if(detail.getChildren().isEmpty()) {
152 final Application app = Application.getApplication();
154 Vbox vbox =
new Vbox();
155 vbox.setSclass(
"detailBox");
156 vbox.setStyle(
"background-image:url('" +
157 ElephantContext.getCurrent().getContextPath() +
158 "/_zul/images/bg/sunken.png')");
159 detail.appendChild(vbox);
160 Hlayout buttons =
new Hlayout();
161 buttons.setSclass(
"z-valign-middle");
162 vbox.appendChild(buttons);
163 if(app.isInRole(
"attach:edit") && !readOnly) {
164 Toolbarbutton edit =
new Toolbarbutton();
165 edit.setImage(
"/_zul/images/properties.png");
166 edit.setTooltiptext(I_.get(
"Properties"));
167 edit.addEventListener(Events.ON_CLICK,
new EventListener() {
169 public void onEvent(Event event)
throws Exception {
170 InputDialog.getInput(
172 I_.get(
"Attachment") +
" " + attachment.getId(),
174 new InputField(
"Name", attachment.getFileName(), null, 0),
175 new InputField(
"Requires acceptance", attachment.isRequiresAcceptance(), null, 0),
176 new InputField(
"Watermark", attachment.isWatermark(), null, 0)
179 public Object execute(Context context) {
180 InputField[] fields = (InputField[]) context.get(
"fields");
181 if(fields.length > 0) {
182 for(InputField f : fields) {
183 if(
"Name".equals(f.getLabel())) {
184 attachment.setFileName((String) f.getValue());
185 }
else if(
"Requires acceptance".equals(f.getLabel())) {
186 attachment.setRequiresAcceptance((Boolean) f.getValue());
187 }
else if(
"Watermark".equals(f.getLabel())) {
188 attachment.setWatermark((Boolean) f.getValue());
191 for(Attachment a : avs) {
192 a.setFileName(attachment.getFileName());
193 a.setRequiresAcceptance(attachment.isRequiresAcceptance());
194 a.setWatermark(attachment.isWatermark());
195 a =
new AttachPU().saveObject(a);
204 buttons.appendChild(edit);
205 buttons.appendChild(
new Space());
207 Toolbarbutton download =
new Toolbarbutton();
208 download.setImage(
"/_zul/images/download.png");
209 download.setTooltiptext(I_.get(
"Download"));
210 download.addEventListener(Events.ON_CLICK,
new EventListener() {
212 public void onEvent(Event event)
throws Exception {
213 AttachmentUtil.download(attachment);
216 buttons.appendChild(download);
217 Toolbarbutton downlock =
new Toolbarbutton();
218 downlock.setImage(
"/_zul/images/download-locking.png");
219 downlock.setTooltiptext(I_.get(
"Download for editing"));
220 downlock.setDisabled(attachment.isLocked());
221 downlock.addEventListener(Events.ON_CLICK,
new EventListener() {
223 public void onEvent(Event event)
throws Exception {
224 AttachmentUtil.download(attachment);
225 attachment.setLocked(
true);
226 attachment.setLocker(Authentication.getIContact().getId());
227 attachment =
new AttachPU().saveObject(attachment);
231 buttons.appendChild(downlock);
232 Toolbarbutton send =
new Toolbarbutton();
233 send.setImage(
"/_zul/images/mail_send.png");
234 send.setTooltiptext(I_.get(
"Send notification"));
235 send.addEventListener(Events.ON_CLICK,
new EventListener() {
237 public void onEvent(Event event)
throws Exception {
238 SendAttachments sa =
new SendAttachments(I_.get(
"Attachment")) {
240 protected void fillAttachment(File attachment, Object entity) {
241 AttachWd.writeToFile((Attachment) entity, attachment);
244 sa.addAttachment(attachment, AttachPU.getObjectPath(attachment), attachment.getFileName());
245 sa.sendAttachments(
null);
248 buttons.appendChild(send);
249 buttons.appendChild(
new Space());
250 Toolbarbutton copy =
new Toolbarbutton();
251 copy.setImage(
"/_zul/images/edit-copy.png");
252 copy.setTooltiptext(I_.get(
"Copy"));
253 copy.addEventListener(Events.ON_CLICK,
new EventListener() {
255 public void onEvent(Event event)
throws Exception {
256 AttachmentUtil.copyAttachment(avs);
259 buttons.appendChild(copy);
261 Toolbarbutton cut =
new Toolbarbutton();
262 cut.setImage(
"/_zul/images/edit-cut.png");
263 cut.setTooltiptext(I_.get(
"Cut"));
264 cut.addEventListener(Events.ON_CLICK,
new EventListener() {
266 public void onEvent(Event event)
throws Exception {
267 AttachmentUtil.cutAttachment(attachment.getFileName(), avs);
270 buttons.appendChild(cut);
273 Toolbarbutton
delete =
new Toolbarbutton();
274 delete.setImage(
"/_zul/images/edit-delete.png");
275 delete.setTooltiptext(I_.get(
"Delete"));
276 delete.addEventListener(Events.ON_CLICK,
new EventListener() {
278 public void onEvent(Event event)
throws Exception {
279 Messages.confirmDeletion().show(() -> {
280 for(Attachment a : avs) {
281 if(a.getPath().startsWith(
"/Trash")) {
282 if(app.isInRole(
"attach:delete")) {
283 new AttachPU().deleteObject(a);
286 a.setPath(
"/Trash" + a.getPath());
287 new AttachPU().saveObject(a);
290 AttachmentRow.this.detach();
294 buttons.appendChild(
delete);
296 buttons.appendChild(
new Space());
297 ILogButton log = SystemLogger.getButton(
null, attachment);
298 buttons.appendChild((Component) log);
299 IAcceptanceCtrl accept = Plugins.loadImplementation(IAcceptanceCtrl.class);
300 accept.setEntity(attachment);
301 buttons.appendChild((Component) accept);
302 buttons.appendChild(
new Space());
308 buttons.appendChild((Component) Tags.getControl(attachment));
309 vbox.appendChild(
new Separator());
310 vbox.appendChild(LabelTypes.getCaptionLabel(I_.get(
"Versions")));
311 AttachVersionGrid avg =
new AttachVersionGrid(avs, readOnly);
313 vbox.appendChild(avg);
317 private Component getSizeComponent() {
318 AttachmentData fd = avs.getData();
319 Vlayout vbox =
new Vlayout();
320 vbox.setSpacing(
"0px");
321 vbox.setStyle(
"text-align:right");
322 vbox.appendChild(
new Label(
new org.turro.formatter.BytesFormatter(fd.getSize()).toString()));
323 if(fd.getSize() != fd.getVersionedSize()) {
324 vbox.appendChild(LabelTypes.getTinyLabel(
new org.turro.formatter.BytesFormatter(fd.getVersionedSize()).toString()));
AttachmentRow(AttachVersionSet avs, boolean readOnly)
AttachVersionSet getAttachmentSet()