19 package org.turro.jobboard;
21 import java.util.HashMap;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.string.Strings;
25 import org.turro.url.UrlCompose;
26 import org.apache.commons.mail.EmailException;
27 import org.turro.action.IAgreements;
28 import org.turro.action.MailSenders;
29 import org.turro.action.Plugins;
30 import org.turro.auth.Authentication;
31 import org.turro.collections.KeyValueMap;
32 import org.turro.contacts.BusinessCombobox;
33 import org.turro.contacts.CoworkerCombobox;
34 import org.turro.elephant.TemplateControl;
35 import org.turro.elephant.context.Application;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.context.IConstructor;
38 import org.turro.elephant.util.Messages;
39 import org.turro.entities.Entities;
40 import org.turro.i18n.I_;
41 import org.turro.jpa.Dao;
42 import org.turro.marker.MarkerHelper;
43 import org.turro.plugin.contacts.IContact;
44 import org.turro.students.db.StudentsPU;
45 import org.turro.students.entities.PracticalWork;
46 import org.turro.students.entities.PracticalWorkRole;
47 import org.turro.zkoss.input.ExpressionInput;
48 import org.turro.zkoss.text.WikiEditor;
49 import org.zkoss.zk.ui.select.annotation.Listen;
50 import org.zkoss.zk.ui.select.annotation.Wire;
51 import org.zkoss.zk.ui.util.Clients;
52 import org.zkoss.zul.Button;
53 import org.zkoss.zul.Checkbox;
54 import org.zkoss.zul.Datebox;
55 import org.zkoss.zul.Textbox;
64 private String contextPath;
66 @Wire(
"#title")
private Textbox title;
71 @Wire(
"#zipcode")
private Textbox zipCode;
72 @Wire(
"#relurl")
private Textbox relatedUrl;
73 @Wire(
"#start")
private Datebox start;
74 @Wire(
"#end")
private Datebox end;
77 @Wire(
"#immediate")
private Checkbox immediate;
79 @Wire(
"#publish")
private Button publish;
80 @Wire(
"#delete")
private Button
delete;
82 @Listen(
"onChange=#title")
84 practicalWork.
setTitle(title.getValue());
87 @Listen(
"onSelect=#business")
93 role.setObjectValue(practicalWork.
getRole());
95 if(immediate.isDisabled()) immediate.setChecked(
false);
98 @Listen(
"onSelect=#responsible")
103 @Listen(
"onChange=#type")
108 @Listen(
"onChange=#zipcode")
113 @Listen(
"onChange=#relurl")
115 String relUrl = relatedUrl.getValue();
116 if(!Strings.isBlank(relUrl)) {
117 if(relUrl.contains(
"@")) {
118 practicalWork.
setRelatedURL(UrlCompose.fillMailGaps(relUrl));
128 @Listen(
"onChange=#start")
133 @Listen(
"onChange=#end")
138 @Listen(
"onChange=#hours")
144 @Listen(
"onChange=#price")
150 @Listen(
"onCheck=#immediate")
155 @Listen(
"onChange=#text")
160 @Listen(
"onClick=#sendTest")
163 HashMap args =
new HashMap();
164 args.put(
"practicalWork", practicalWork);
166 args.put(
"notifier",
this);
167 if(practicalWork.
getId() !=
null) {
173 .addByEntity(practicalWork,
null)
174 .setRoot(
"/practicalworks")
176 .sendTemplate(
"practicalwork-test", composeSubject(practicalWork));
177 Clients.showNotification(
I_.
get(
"Test sent"));
178 }
catch (EmailException ex) {
182 Clients.showNotification(
I_.
get(
"Fill required fields"));
186 @Listen(
"onClick=#save")
190 practicalWork = wrapper.
save();
194 Clients.showNotification(
I_.
get(
"Fill required fields"));
198 @Listen(
"onClick=#cancel")
200 if(practicalWork.
getId() !=
null) {
208 @Listen(
"onClick=#publish")
214 HashMap args =
new HashMap();
215 args.put(
"practicalWork", practicalWork);
217 args.put(
"notifier",
this);
218 if(practicalWork.
getId() > 0) {
224 .addByEntity(practicalWork,
null)
225 .setRoot(
"/practicalworks")
227 .sendTemplate(
"practicalwork-published", composeSubject(practicalWork));
228 }
catch (EmailException ex) {
238 @Listen(
"onClick=#delete")
240 if(practicalWork.
getId() !=
null) {
254 this.contextPath = contextPath;
258 this.practicalWork = practicalWork;
262 checkPracticalWork();
263 return practicalWork;
271 if(!agreements.
canAct(
"practicalwork-new")) {
274 checkPracticalWork();
288 return "{liveref:" + redir +
"}";
291 private void checkPracticalWork() {
293 if(practicalWork ==
null) {
294 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"item")) {
295 Long pwId = kvm.get(Long.class,
"item");
300 practicalWork =
new PracticalWork();
301 practicalWork.
setRole(PracticalWorkRole.PRACTICALWORK_SUPPLY);
304 if(practicalWork ==
null) {
305 Application.getApplication().sendRedirect(contextPath);
309 private void initComponents() {
310 business.
setAllowSelf(PracticalWorkContext.getAllowSingle());
311 responsible.
setAllowSelf(PracticalWorkContext.getAllowSingle());
312 business.
setContact(Authentication.getIContact());
314 if(practicalWork.
getId() !=
null) {
315 title.setValue(practicalWork.
getTitle());
318 role.setObjectValue(practicalWork.
getRole());
333 boolean all = Application.getApplication().isInRole(
"contact:all");
335 publish.setLabel(I_.get(
"Unpublish"));
337 publish.setLabel(I_.get(
"Publish"));
339 delete.setDisabled(practicalWork.
getId() ==
null || !(all ||
343 private String composeSubject(PracticalWork practicalWork) {
344 return "[" + I_.byKey(practicalWork.getRole().toString()) +
"]" +
345 " " + I_.get(practicalWork.getType()) +
346 ": " + practicalWork.getTitle();
353 private Dao getDao() {
355 _dao =
new StudentsPU();
static IMailSender getPool()
static< T > T loadImplementation(Class< T > jclass)
static IContact getIContact()
abstract void sendRedirect(String uri)
static Application getApplication()
static String logMsg(String msg)
static Messages confirmDeletion()
Messages add(String word)
static IElephantEntity getController(String path)
static String get(String msg)
String createRef(IConstructor constructor, String redir)
void setContextPath(String contextPath)
void setResponse(PracticalWork practicalWork)
String createRef(IConstructor constructor, PracticalWork practicalWork, IContact contact)
PracticalWork getPracticalWork()
static KeyValueMap getObfuscatedParameters()
static String setObfuscatedRightNowPars(String parameters)
void setStartDate(Date startDate)
void setPrice(double price)
void setEndDate(Date endDate)
void setRole(PracticalWorkRole role)
boolean isInBusiness(IContact worker)
IContact getIResponsible()
void setTitle(String title)
void setRelatedURL(String relatedURL)
void setIContact(IContact contact)
void setType(String type)
PracticalWorkRole getRole()
void setImmediate(boolean immediate)
void setZipCode(String zipCode)
void setHours(double hours)
void setWiki(String wiki)
void setIResponsible(IContact responsible)
void setPublished(boolean published)
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)