19 package org.turro.contacts.form;
21 import java.awt.image.RenderedImage;
23 import java.io.IOException;
24 import java.util.Collection;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.stream.Collectors;
30 import org.turro.action.Actions;
31 import org.turro.action.Contacts;
32 import org.turro.action.Plugins;
33 import org.turro.activity.ParticipationCatchers;
34 import org.turro.command.Command;
35 import org.turro.command.Context;
36 import org.turro.contacts.Contact;
37 import org.turro.contacts.db.ContactsPU;
38 import org.turro.contacts.profile.EditProfileControl;
39 import org.turro.contacts.social.SocialGroupValue;
40 import org.turro.contacts.social.SocialGroupedListbox;
41 import org.turro.contacts.zul.fields.FieldValueGrid;
42 import org.turro.contacts.zul.menu.ContactMenu;
43 import org.turro.elephant.context.Application;
44 import org.turro.elephant.context.ElephantContext;
45 import org.turro.elephant.db.WhereClause;
46 import org.turro.elephant.zkoss.ModalWindow;
47 import org.turro.file.util.FileAttach;
48 import org.turro.i18n.I_;
49 import org.turro.jpa.Dao;
50 import org.turro.jpa.composer.EntityComposer;
51 import org.turro.jpa.entity.DaoEntity;
52 import org.turro.mail.sender.MailPool;
53 import org.turro.plugin.IPlugin;
54 import org.turro.plugin.contacts.IContact;
55 import org.turro.security.SocialGroups;
56 import org.turro.tags.Tags;
57 import org.turro.upload.Medias;
58 import org.turro.util.IdGenerator;
59 import org.turro.zkoss.locale.Currencies;
60 import org.turro.zkoss.locale.CurrencyListbox;
61 import org.turro.zkoss.locale.LocaleListbox;
62 import org.turro.zul.frame.Framework;
63 import org.turro.zul.frame.ScrollTabpanel;
64 import org.zkoss.image.AImage;
65 import org.zkoss.lang.Strings;
66 import org.zkoss.util.media.Media;
67 import org.zkoss.zk.ui.Component;
68 import org.zkoss.zk.ui.event.SelectEvent;
69 import org.zkoss.zk.ui.event.UploadEvent;
70 import org.zkoss.zk.ui.select.annotation.Listen;
71 import org.zkoss.zk.ui.select.annotation.Wire;
72 import org.zkoss.zk.ui.util.Clients;
73 import org.zkoss.zul.Image;
74 import org.zkoss.zul.Listitem;
75 import org.zkoss.zul.Tab;
76 import org.zkoss.zul.Tabpanels;
77 import org.zkoss.zul.Tabs;
86 private boolean isNew =
false;
91 @Wire(
"#detail #face")
private Image face;
92 @Wire(
"#detail #qrcode")
private Image qrcode;
93 @Wire(
"#contabs")
private Tabs contabs;
94 @Wire(
"#conpanels")
private Tabpanels conpanels;
96 @Listen(
"onSelect = #detail #localebox")
103 @Listen(
"onSelect = #detail #socialgroups")
105 if(event.getReference() instanceof Listitem) {
106 Collection<SocialGroupValue> sgs = socialgroups.
getSelected();
109 new HashSet<>(sgs.stream().map(sgv -> sgv.getKey()).collect(Collectors.toList())),
114 @Listen(
"onUpload = #detail #uploadface")
115 public
void onEvent(UploadEvent t) throws Exception {
117 if(!newFile.getParentFile().exists()) {
118 newFile.getParentFile().mkdirs();
120 Media media = t.getMedia();
124 if(newFile.exists()) {
126 face.setContent(
new AImage(newFile.getAbsolutePath()));
127 }
catch (IOException ex) {
135 @Listen(
"onClick = #subscriptions")
140 @Listen(
"onClick = #organigram")
145 @Listen(
"onClick = #welcome")
153 Clients.showNotification(
I_.
get(
"Welcome was sent..."));
193 public Object execute(Context context) {
207 if(isNew &&
entity !=
null) {
216 isNew = Strings.isBlank(
entity.getId());
219 String faceFile = fileAttach.
getPublicFile(
"/profile/face.png",
false);
220 if(!Strings.isBlank(faceFile)) {
221 face.setSrc(faceFile +
"?" + IdGenerator.generate());
227 qrcode.setContent((RenderedImage) vcard.
getData(
"qrcode"));
229 for(String tabKey : getTabKeys()) {
230 Tab tab =
new Tab(
I_.
get(tabKey));
231 contabs.appendChild(tab);
234 conpanels.appendChild(panel);
245 return !
entity.isEmpty() && (Strings.isBlank(
entity.getId())) || super.shouldBeSaved();
258 private List<String> getTabKeys() {
259 List names = getTagNames();
260 if(names.isEmpty())
return names;
263 wc.
addClause(
"select distinct fieldDef.tabKey");
264 wc.
addClause(
"from FieldDef as fieldDef");
265 wc.
addClause(
"where fieldDef.tagDiscriminator in (:tags)");
266 wc.
addClause(
"order by fieldDef.tabKey");
268 return (List<String>) dao.getResultList(wc);
271 private List<String> getTagNames() {
272 return Tags.
getTags(
entity).stream().map(t -> t.getTagName()).collect(Collectors.toList());
static String createAction(String email, String redir)
static< T > T loadImplementation(Class< T > jclass)
static void onChange(Object entity)
boolean isInRole(String role)
static Application getApplication()
static String getRealPath(String path)
static String getSiteName()
static String getServerUrl(String scheme)
void addClause(String clause)
void addNamedValue(String name, Object value)
String getPublicFile(String file)
static String get(String msg)
IMailSender addContact(IContact contact)
static void absoluteSyndicate(List< Contact > contacts, Set< String > socialGroupIds, Dao dao)
static void checkInheritance(List< Contact > contacts, Dao dao)
static Currency getDefault()
void setObjectValue(Currency value)
static Framework getCurrent()
void setSelectedLabel(String text)
void setSelectedTooltiptext(String text)
IMailSender put(Object key, Object value)
void silentSendTemplate(String template, String subject)
IMailSender setRoot(String root)
static final String CONNECTOR_EMAIL
Object getData(String id)
void setData(String id, Object data)