19 package org.turro.contacts.service;
22 import java.io.IOException;
23 import java.util.HashMap;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.string.Strings;
27 import org.turro.url.UrlCompose;
28 import org.apache.commons.mail.EmailException;
29 import org.turro.action.IAgreements;
30 import org.turro.action.MailSenders;
31 import org.turro.action.Plugins;
32 import org.turro.auth.Authentication;
33 import org.turro.collections.KeyValueMap;
34 import org.turro.contacts.BusinessCombobox;
35 import org.turro.contacts.ContactService;
36 import org.turro.contacts.ContactServiceRole;
37 import org.turro.contacts.CoworkerCombobox;
38 import org.turro.contacts.db.ContactsPU;
39 import org.turro.elephant.TemplateControl;
40 import org.turro.elephant.calendar.Periodicity;
41 import org.turro.elephant.context.Application;
42 import org.turro.elephant.context.ElephantContext;
43 import org.turro.elephant.context.IConstructor;
44 import org.turro.elephant.util.Messages;
45 import org.turro.entities.Entities;
46 import org.turro.file.util.FileAttach;
47 import org.turro.i18n.I_;
48 import org.turro.jpa.Dao;
49 import org.turro.marker.MarkerHelper;
50 import org.turro.plugin.contacts.IContact;
51 import org.turro.upload.Medias;
52 import org.turro.zkoss.input.ExpressionInput;
53 import org.turro.zkoss.input.PeriodicityListbox;
54 import org.turro.zkoss.text.WikiEditor;
55 import org.zkoss.image.AImage;
56 import org.zkoss.util.media.Media;
57 import org.zkoss.zk.ui.event.UploadEvent;
58 import org.zkoss.zk.ui.select.annotation.Listen;
59 import org.zkoss.zk.ui.select.annotation.Wire;
60 import org.zkoss.zk.ui.util.Clients;
61 import org.zkoss.zul.Button;
62 import org.zkoss.zul.Datebox;
63 import org.zkoss.zul.Image;
64 import org.zkoss.zul.Textbox;
73 private String contextPath;
75 @Wire(
"#title")
private Textbox title;
81 @Wire(
"#relurl")
private Textbox relatedUrl;
82 @Wire(
"#start")
private Datebox start;
83 @Wire(
"#end")
private Datebox end;
87 @Wire(
"#image")
private Image image;
89 @Wire(
"#publish")
private Button publish;
90 @Wire(
"#delete")
private Button
delete;
92 @Listen(
"onChange=#title")
97 @Listen(
"onSelect=#business")
104 @Listen(
"onSelect=#responsible")
109 @Listen(
"onSelect=#role")
111 service.
setRole(role.getObjectValue());
114 @Listen(
"onChange=#type")
119 @Listen(
"onChange=#thematic")
124 @Listen(
"onChange=#relurl")
126 String relUrl = relatedUrl.getValue();
127 if(!Strings.isBlank(relUrl)) {
128 if(relUrl.contains(
"@")) {
139 @Listen(
"onChange=#start")
144 @Listen(
"onChange=#end")
149 @Listen(
"onChange=#price")
155 @Listen(
"onChange=#tax")
161 @Listen(
"onSelect=#periodicity")
166 @Listen(
"onUpload=#upload")
170 if(!newFile.getParentFile().exists()) {
171 newFile.getParentFile().mkdirs();
173 Media media =
event.getMedia();
177 if(newFile.exists()) {
179 image.setContent(
new AImage(newFile.getAbsolutePath()));
180 }
catch (IOException ex) {
188 @Listen(
"onChange=#text")
194 @Listen(
"onClick=#sendTest")
197 HashMap args =
new HashMap();
198 args.put(
"service", service);
200 args.put(
"notifier",
this);
201 if(!Strings.isBlank(service.
getId())) {
203 args.put(
"face", fileAttach.
getPublicFile(
"/profile/face.png",
false));
209 .addByEntity(service,
null)
210 .setRoot(
"/services")
212 .sendTemplate(
"service-test", composeSubject(service));
213 Clients.showNotification(
I_.
get(
"Test sent"));
214 }
catch (EmailException ex) {
218 Clients.showNotification(
I_.
get(
"Fill required fields"));
222 @Listen(
"onClick=#save")
227 service = wrapper.
save();
231 Clients.showNotification(
I_.
get(
"Fill required fields"));
235 @Listen(
"onClick=#cancel")
237 if(!Strings.isBlank(service.
getId())) {
245 @Listen(
"onClick=#publish")
249 HashMap args =
new HashMap();
250 args.put(
"service", service);
252 args.put(
"notifier",
this);
253 if(!Strings.isBlank(service.
getId())) {
255 args.put(
"face", fileAttach.
getPublicFile(
"/profile/face.png",
false));
261 .addByEntity(service,
null)
262 .setRoot(
"/services")
264 .sendTemplate(
"service-marketplace", composeSubject(service));
265 }
catch (EmailException ex) {
274 @Listen(
"onClick=#delete")
276 if(!Strings.isBlank(service.
getId())) {
285 @Listen(
"onClick=#delimg")
287 if(!Strings.isBlank(service.
getId())) {
291 if(newFile.exists()) {
304 this.contextPath = contextPath;
308 this.service = service;
317 return I_.
format(
"Image will be converted to %dx%d", 900, 450);
325 if(!agreements.
canAct(
"marketplace-new")) {
342 return "{liveref:" + redir +
"}";
345 private void checkService() {
347 if(service ==
null) {
348 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"item")) {
349 String serviceId = kvm.get(
"item");
350 if(!Strings.isBlank(serviceId)) {
354 service =
new ContactService();
355 service.
setRole(ContactServiceRole.SERVICE_SUPPLY);
359 if(service ==
null) {
360 Application.getApplication().sendRedirect(contextPath);
364 private void initComponents() {
366 responsible.
setAllowSelf(ServiceContext.getAllowSingle());
367 business.
setContact(Authentication.getIContact());
369 if(!Strings.isBlank(service.
getId())) {
373 role.setObjectValue(service.
getRole());
391 boolean all = Application.getApplication().isInRole(
"contact:all");
392 publish.setDisabled(service.
getTimesSent() >= 1 && !all);
393 delete.setDisabled(Strings.isBlank(service.
getId()) || !(all ||
397 private String composeSubject(ContactService service) {
398 return "[" + I_.byKey(service.getRole().toString()) +
"]" +
399 " " + I_.byKey(service.getType()) +
400 ": " + service.getTitle();
407 private Dao getDao() {
409 _dao =
new ContactsPU();
static IMailSender getPool()
static< T > T loadImplementation(Class< T > jclass)
static IContact getIContact()
abstract void sendRedirect(String uri)
static Application getApplication()
static String getRealPath(String path)
static String logMsg(String msg)
static Messages confirmDeletion()
Messages add(String word)
static IElephantEntity getController(String path)
String getPublicFile(String file)
static String format(String msg, Object... arguments)
static String get(String msg)
static KeyValueMap getObfuscatedParameters()
static String setObfuscatedRightNowPars(String parameters)
void setImageFolder(String folder)
void setValue(String value)
void setFileFolder(String folder)
void setReadOnlyRepository(boolean readOnlyRepository)
void setContact(IContact contact)
String getPendingActURL(String action)
boolean canAct(String action)