19 package org.turro.contacts.profile;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Date;
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.string.Strings;
31 import org.apache.commons.mail.EmailException;
32 import org.turro.action.Actions;
33 import org.turro.action.Contacts;
34 import org.turro.action.PushSenders;
35 import org.turro.collections.KeyValueMap;
36 import org.turro.contacts.Comment;
37 import org.turro.contacts.Contact;
38 import org.turro.contacts.comment.AboutWrapper;
39 import org.turro.contacts.db.ContactsPU;
40 import org.turro.contacts.form.ContactWrapper;
41 import org.turro.elephant.TemplateControl;
42 import org.turro.elephant.context.Application;
43 import org.turro.elephant.context.ElephantContext;
44 import org.turro.elephant.entities.db.Skill;
45 import org.turro.elephant.entities.db.SkillType;
46 import org.turro.elephant.security.IUser;
47 import org.turro.file.util.FileAttach;
48 import org.turro.i18n.I_;
49 import org.turro.mail.sender.MailPool;
50 import org.turro.plugin.contacts.IContact;
51 import org.turro.security.SecurityGroup;
52 import org.turro.skills.SkillRoot;
53 import org.turro.skills.Skills;
54 import org.turro.skills.SkillsChosenbox;
55 import org.turro.upload.Medias;
56 import org.turro.util.IdGenerator;
57 import org.zkoss.image.AImage;
58 import org.zkoss.util.media.Media;
59 import org.zkoss.zk.ui.event.Event;
60 import org.zkoss.zk.ui.event.Events;
61 import org.zkoss.zk.ui.event.InputEvent;
62 import org.zkoss.zk.ui.event.UploadEvent;
63 import org.zkoss.zk.ui.select.annotation.Listen;
64 import org.zkoss.zk.ui.select.annotation.Wire;
65 import org.zkoss.zul.Image;
66 import org.zkoss.zul.Tab;
67 import org.zkoss.zul.Tabpanel;
68 import org.zkoss.zul.Tabpanels;
69 import org.zkoss.zul.Tabs;
70 import org.zkoss.zul.Textbox;
80 private List<String> langs;
81 private List<AboutWrapper> model;
83 @Wire(
"#name")
private Textbox name;
84 @Wire(
"#web")
private Textbox web;
85 @Wire(
"#trade")
private Textbox trade;
86 @Wire(
"#face")
private Image face;
87 @Wire(
"#tabs")
private Tabs tabs;
88 @Wire(
"#tabpanels")
private Tabpanels tabpanels;
93 @Listen(
"onChange=#web")
98 @Listen(
"onChange=#trade")
103 @Listen(
"onUpload = #uploadface")
104 public
void onEvent(UploadEvent t) throws Exception {
107 if(!newFile.getParentFile().exists()) {
108 newFile.getParentFile().mkdirs();
110 Media media = t.getMedia();
114 if(newFile.exists()) {
116 face.setContent(
new AImage(newFile.getAbsolutePath()));
117 }
catch (IOException ex) {
125 @Listen(
"onSelect=#sector")
129 .stream().map(s -> s.getFor(entityPath)).collect(Collectors.toSet()),
133 @Listen(
"onSelect=#specialty")
137 .stream().map(s -> s.getFor(entityPath)).collect(Collectors.toSet()),
141 @Listen(
"onSearch=#sector")
143 String value =
event.getValue();
145 if(!Strings.isBlank(value)) {
155 @Listen(
"onSearch=#specialty")
157 String value =
event.getValue();
159 if(!Strings.isBlank(value)) {
169 @Listen(
"onClick=#save")
175 if(wrapper.isNewComment() && !wrapper.isEmpty()) {
189 @Listen(
"onClick=#cancel")
204 langs =
new ArrayList<>();
211 private String chooseLabel(String lang) {
212 if(
"#".equals(lang)) {
213 return I_.
get(
"Default");
222 model =
new ArrayList<>();
224 boolean done =
false;
226 if(comment.getComment().startsWith(
"#cv" + lang)) {
227 AboutWrapper wrapper = new AboutWrapper(lang, chooseLabel(lang), comment);
239 Tab tab =
new Tab(a.getLangLabel());
240 tabs.appendChild(tab);
241 Tabpanel tabpanel =
new Tabpanel();
242 tabpanels.appendChild(tabpanel);
243 Textbox about =
new Textbox();
244 about.setMultiline(
true);
246 about.setTabbable(
true);
247 about.setStyle(
"-moz-tab-size:4;-o-tab-size:4;tab-size:4;width:100%;height:100%;");
248 about.setValue(a.getCommentString());
249 about.addEventListener(Events.ON_CHANGE, (Event event) -> {
250 a.setCommentString(about.getValue());
252 tabpanel.appendChild(about);
260 if(kvm !=
null && kvm.containsKey(
"contact")) {
266 private void initComponents() {
267 if(contact !=
null && contact.isValid()) {
268 name.setValue(contact.getName());
269 name.setReadonly(
true);
270 web.setValue(contact.getConnector(
Profile.WEB));
273 String faceFile = fileAttach.
getPublicFile(
"/profile/face.png",
false);
274 if(!Strings.isBlank(faceFile)) {
275 face.setSrc(faceFile +
"?" + IdGenerator.generate());
279 sector.setObjectValues(Skills.getSkillsAsRootFrom(entityPath, SkillType.SKILL_SECTOR));
280 specialty.setObjectValues(Skills.getSkillsAsRootFrom(entityPath, SkillType.SKILL_SPECIALTY));
282 Application.getApplication().navigateBack();
286 private void sendNotification(Contact c) {
288 FileAttach fileAttach =
new FileAttach(ContactsPU.getObjectPath(c));
289 String faceFile = fileAttach.getPublicFile(
"/profile/face.png",
false);
292 .addBySyndication(SecurityGroup.CONTACTS_ADMIN)
296 .put(
"face", faceFile)
297 .sendTemplate(
"change-notification",
298 I_.get(
"Modified") +
": " + I_.get(
"About"));
299 }
catch (EmailException ex) {
300 Logger.getLogger(EditCProfileControl.class.getName()).log(Level.SEVERE,
null, ex);
302 PushSenders.getPool()
304 .addBySyndication(SecurityGroup.CONTACTS_ADMIN)
305 .send(I_.get(
"Modified") +
": " + I_.get(
"About"), c.getName());
static KeyValueMap getRightNowAction(IConstructor constructor)
IConstructor getConstructor()
abstract void navigateBack()
static Application getApplication()
static String getRealPath(String path)
static String getSiteLocales()
void setSkill(String skill)
void setType(SkillType type)
void setEntityPath(String entityPath)
String getPublicFile(String file)
static String byKey(String key)
static String get(String msg)
void addToModel(SkillRoot value)
Set< SkillRoot > getObjectValues()
static void setSkillsFor(String entityPath, Set< Skill > skills, SkillType... types)
static void addSkillFor(String entityPath, Skill skill)
static final String CONNECTOR_TRADE