19 package org.turro.contacts.mydata;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.string.Strings;
28 import org.apache.commons.io.input.ReaderInputStream;
29 import org.turro.auth.Authentication;
30 import org.turro.contacts.db.ContactsPU;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.elephant.util.Images;
33 import org.turro.i18n.I_;
34 import org.turro.zkoss.layout.GridLayout;
35 import org.zkoss.util.media.Media;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zk.ui.event.UploadEvent;
40 import org.zkoss.zk.ui.util.Clients;
41 import org.zkoss.zk.ui.util.GenericForwardComposer;
42 import org.zkoss.zul.Button;
43 import org.zkoss.zul.Hlayout;
44 import org.zkoss.zul.Image;
45 import org.zkoss.zul.Space;
46 import org.zkoss.zul.Textbox;
63 Clients.showNotification(
I_.
get(
"Saved"));
64 }
catch (IOException ex) {
76 private void fillGrid() {
79 if(!Strings.isBlank(item.getLabel())) {
84 if(item.getType().equals(MyDataItemType.MYDATA_IMAGE)) {
85 Hlayout hbox =
new Hlayout();
86 Button upload =
new Button(I_.get(
"Upload"));
87 upload.setUpload(
"true,maxsize=300");
88 String image =
"/_internal/files" + ContactsPU.getObjectPath(
89 Authentication.getIContact().getContact()) + item.getValue();
90 File newFile =
new File(ElephantContext.getRealPath(image));
91 upload.addEventListener(Events.ON_UPLOAD,
new EventListener<UploadEvent>() {
93 public void onEvent(UploadEvent t) throws Exception {
94 if(!newFile.getParentFile().exists()) {
95 newFile.getParentFile().mkdirs();
97 try (FileOutputStream fos = new FileOutputStream(newFile)) {
98 Media media = t.getMedia();
99 if(media.inMemory()) {
100 fos.write(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
102 byte[] buffer = new byte[102400];
103 InputStream is = media.isBinary() ? media.getStreamData() : new ReaderInputStream(media.getReaderData());
105 while((r = is.read(buffer)) != -1) {
106 fos.write(buffer, 0, r);
113 if(newFile.exists()) {
114 Image itmp =
new Image(image);
115 itmp.setStyle(
"max-width:300px;max-heght:300px;");
116 hbox.appendChild(itmp);
118 hbox.appendChild(upload);
120 }
else if(item.getType().equals(MyDataItemType.MYDATA_PASSWORD)) {
121 Textbox input =
new Textbox();
122 if(!Strings.isBlank(item.getName())) {
123 input.setName(item.getName());
125 input.setType(
"password");
126 if(item.getCols() == 0) {
129 input.setCols(item.getCols());
132 item.setInput(input);
135 Textbox input =
new Textbox();
136 if(!Strings.isBlank(item.getName())) {
137 input.setName(item.getName());
139 if(item.getCols() == 0) {
142 input.setCols(item.getCols());
144 input.setValue(item.getValue());
145 input.setReadonly(item.isReadonly());
146 item.setInput(input);
149 if(item.isRequired()) {
150 myDataForm.
addComponent(
new Image(Images.getImage(
"required")));
static IContact getIContact()
static void reauthenticate()
static String logMsg(String msg)
static String get(String msg)
GridLayout addComponent(HtmlBasedComponent comp)
GridLayout addCaption(String label)