19 package org.turro.students.www;
21 import java.util.Date;
22 import org.turro.string.Strings;
23 import org.turro.auth.Authentication;
24 import org.turro.collections.KeyValueMap;
25 import org.turro.elephant.TemplateControl;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.IConstructor;
28 import org.turro.entities.Entities;
29 import org.turro.entities.EntityCombobox;
30 import org.turro.entities.EntityRole;
31 import org.turro.entities.IElephantEntity;
32 import org.turro.jpa.Dao;
33 import org.turro.marker.MarkerHelper;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.students.ChallengeContext;
36 import org.turro.students.db.StudentsPU;
37 import org.turro.students.entities.Challenge;
38 import org.turro.students.mail.ChallengeChangedNotification;
39 import org.turro.students.mail.NewChallengeNotification;
40 import org.turro.students.wrappers.ChallengeWrapper;
41 import org.turro.zkoss.text.WikiEditor;
42 import org.zkoss.zk.ui.select.annotation.Listen;
43 import org.zkoss.zk.ui.select.annotation.Wire;
44 import org.zkoss.zul.Datebox;
45 import org.zkoss.zul.Textbox;
54 private String contextPath;
57 @Wire(
"#question")
private Textbox question;
58 @Wire(
"#deadline")
private Datebox deadline;
61 @Listen(
"onChange=#question")
66 @Listen(
"onChange=#text")
71 @Listen(
"onChange=#deadline")
76 @Listen(
"onClick=#save")
81 boolean isNew = challenge.
getId() ==
null;
82 challenge = dw.
save();
93 @Listen(
"onClick=#cancel")
95 if(challenge.
getId() !=
null && challenge.
getId() > 0) {
108 this.contextPath = contextPath;
112 this.challenge = challenge;
127 private void checkChallenge() {
129 if(challenge ==
null) {
130 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"item")) {
131 Long challengeId = kvm.get(Long.class,
"item");
132 if(challengeId > 0) {
133 challenge = getDao().find(
Challenge.class, challengeId);
137 if(challenge ==
null) {
138 if(kvm !=
null && !kvm.isEmpty() && kvm.containsKey(
"entityPath")) {
139 IContact contact = Authentication.getIContact();
140 challenge =
new Challenge();
146 IContact contact = Authentication.getIContact();
147 challenge =
new Challenge();
154 private void initComponents() {
155 KeyValueMap kvm =
new KeyValueMap();
156 IConstructor constructor = Application.getApplication().getConstructor();
157 entity.
setRoot(ChallengeContext.getAllowedRoots(constructor));
158 String dossierCategories = ChallengeContext.getDossierCategories(constructor);
159 if(!Strings.isBlank(dossierCategories)) {
160 kvm.put(
"dossier-categories", dossierCategories);
164 if(challenge.
getId() !=
null && challenge.
getId() > 0) {
165 IContact contact = Authentication.getIContact();
166 IElephantEntity iee = Entities.getController(challenge.
getEntityPath());
167 if(contact.isAdmin() || iee.hasRelatedRole(EntityRole.CHALLENGER, contact)) {
174 Application.getApplication().sendRedirect(contextPath);
187 private Dao getDao() {
189 _dao =
new StudentsPU();
abstract void sendRedirect(String uri)
static Application getApplication()
void setParameters(KeyValueMap kvm)
void setRoot(String root)
void setEntityPath(String entityPath)
static KeyValueMap getObfuscatedParameters()
static String setObfuscatedRightNowPars(String parameters)
void setContact(IContact contact)
void setQuestion(String question)
void setDeadline(Date deadline)
void setWikiText(String wikiText)
void setCreation(Date creation)
void setEntityPath(String entityPath)
void setChallenge(Challenge challenge)
void setContextPath(String contextPath)
void setImageFolder(String folder)
void setValue(String value)
void setFileFolder(String folder)
void setReadOnlyRepository(boolean readOnlyRepository)