19 package org.turro.contacts.profile;
22 import java.io.IOException;
23 import java.util.Date;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.apache.commons.mail.EmailException;
27 import org.turro.action.Actions;
28 import org.turro.action.Contacts;
29 import org.turro.action.MailSenders;
30 import org.turro.action.PushSenders;
31 import org.turro.auth.Authentication;
32 import org.turro.collections.KeyValueMap;
33 import org.turro.contacts.Contact;
34 import org.turro.contacts.JobBoard;
35 import org.turro.contacts.db.ContactsPU;
36 import org.turro.contacts.form.ContactWrapper;
37 import org.turro.elephant.TemplateControl;
38 import org.turro.elephant.context.Application;
39 import org.turro.elephant.context.ElephantContext;
40 import org.turro.file.util.FileAttach;
41 import org.turro.i18n.I_;
42 import org.turro.plugin.contacts.IContact;
43 import org.turro.security.SecurityGroup;
44 import org.turro.upload.Medias;
45 import org.turro.util.IdGenerator;
46 import org.zkoss.image.AImage;
47 import org.zkoss.lang.Strings;
48 import org.zkoss.util.media.Media;
49 import org.zkoss.zk.ui.event.UploadEvent;
50 import org.zkoss.zk.ui.select.annotation.Listen;
51 import org.zkoss.zk.ui.select.annotation.Wire;
52 import org.zkoss.zul.Checkbox;
53 import org.zkoss.zul.Div;
54 import org.zkoss.zul.Image;
55 import org.zkoss.zul.Listbox;
56 import org.zkoss.zul.Listitem;
57 import org.zkoss.zul.Textbox;
68 @Wire(
"#name")
private Textbox name;
69 @Wire(
"#phone")
private Textbox phone;
70 @Wire(
"#web")
private Textbox web;
71 @Wire(
"#network")
private Textbox network;
72 @Wire(
"#face")
private Image face;
74 @Wire(
"#studentForm")
private Div studentForm;
75 @Wire(
"#available")
private Checkbox available;
76 @Wire(
"#online")
private Checkbox online;
77 @Wire(
"#zipCode")
private Textbox zipCode;
78 @Wire(
"#commute")
private Listbox commute;
80 @Listen(
"onChange=#name")
82 contact.
setName(name.getValue());
85 @Listen(
"onChange=#phone")
90 @Listen(
"onChange=#web")
95 @Listen(
"onChange=#network")
100 @Listen(
"onUpload = #uploadface")
101 public
void onEvent(UploadEvent t) throws Exception {
104 if(!newFile.getParentFile().exists()) {
105 newFile.getParentFile().mkdirs();
107 Media media = t.getMedia();
111 if(newFile.exists()) {
113 face.setContent(
new AImage(newFile.getAbsolutePath()));
114 }
catch (IOException ex) {
122 @Listen(
"onClick=#save")
126 if(available.isChecked()) {
136 Listitem li = commute.getSelectedItem();
137 if(li !=
null) board.
setCommuting(Integer.valueOf(li.getValue()));
148 @Listen(
"onClick=#cancel")
165 if(kvm !=
null && kvm.containsKey(
"contact")) {
173 private void initComponents() {
174 if(contact !=
null && contact.
isWebUser()) {
175 name.setValue(contact.
getName());
181 String faceFile = fileAttach.
getPublicFile(
"/profile/face.png",
false);
182 if(!Strings.isBlank(faceFile)) {
183 face.setSrc(faceFile +
"?" + IdGenerator.generate());
186 studentForm.setVisible(
true);
189 available.setChecked(
true);
190 online.setChecked(board.
isOnline());
192 for(Listitem li : commute.getItems()) {
194 commute.setSelectedItem(li);
199 studentForm.setVisible(
false);
202 Application.getApplication().sendRedirect(path);
206 private void sendNotification(Contact c) {
208 MailSenders.getPool()
210 .addBySyndication(SecurityGroup.CONTACTS_ADMIN)
212 .put(
"profile",
new Profile(c))
213 .sendTemplate(
"change-notification",
214 I_.get(
"Modified") +
": " + I_.get(
"Profile"));
215 }
catch (EmailException ex) {
216 Logger.getLogger(EditProfileControl.class.getName()).log(Level.SEVERE,
null, ex);
218 PushSenders.getPool()
220 .addBySyndication(SecurityGroup.CONTACTS_ADMIN)
221 .send(I_.get(
"Modified") +
": " + I_.get(
"Profile"), c.getName());
static KeyValueMap getRightNowAction(IConstructor constructor)
static IContact getIContact()
static String getAttribute(String attribute)
IConstructor getConstructor()
abstract void sendRedirect(String uri)
static Application getApplication()
static String getRealPath(String path)
String getPublicFile(String file)