18 package org.turro.agreements;
20 import java.util.List;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.apache.commons.mail.EmailException;
24 import org.turro.action.MailSenders;
25 import org.turro.command.Command;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.context.IConstructor;
29 import org.turro.elephant.db.ElephantPU;
30 import org.turro.elephant.entities.db.Agreement;
31 import org.turro.elephant.entities.db.AgreementSignature;
32 import org.turro.elephant.util.Messages;
33 import org.turro.i18n.I_;
34 import org.turro.jpa.Dao;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.zkoss.dialog.SelectionDialog;
37 import org.turro.zkoss.text.WikiEditor;
38 import org.zkoss.zk.ui.Component;
39 import org.zkoss.zk.ui.select.SelectorComposer;
40 import org.zkoss.zk.ui.select.annotation.Listen;
41 import org.zkoss.zk.ui.select.annotation.Wire;
42 import org.zkoss.zul.Checkbox;
43 import org.zkoss.zul.Label;
44 import org.zkoss.zul.Textbox;
61 private Label declined;
64 private Label notsigned;
67 private Textbox title;
70 private Checkbox toNotify;
73 private Checkbox toAccess;
76 private Checkbox toAction;
79 private Checkbox peremptory;
82 private Textbox action;
87 @Listen(
"onClick = #signatures")
89 if (agreement !=
null) {
95 @Listen(
"onClick = #reminders")
100 }
catch (Exception ex) {
106 @Listen(
"onClick = #save")
108 getDao().saveObject(agreement);
111 @Listen(
"onClick = #delete")
119 @Listen(
"onChange = #title")
121 checkAgreement().
setTitle(title.getValue());
125 @Listen(
"onChange = #action")
127 checkAgreement().
setAction(action.getValue());
131 @Listen(
"onChange = #agreeWiki")
138 @Listen(
"onSelect = #agreeCombo")
141 if (agreement !=
null) {
142 List<AgreementSignature> signatures = agreement.
getSignatures();
143 agreed.setValue(
"" + signatures.stream().filter((as) -> (as.isSigned() && as.isAgreed())).count());
144 declined.setValue(
"" + signatures.stream().filter((as) -> (as.isSigned() && !as.isAgreed())).count());
145 notsigned.setValue(
"" + signatures.stream().filter((as) -> (!as.isSigned())).count());
148 declined.setValue(
"");
149 notsigned.setValue(
"");
154 @Listen(
"onCheck = #toNotify; onCheck = #toAccess; onCheck = #toAction; onCheck = #peremptory")
163 private void updateControls() {
164 if (agreement !=
null) {
165 title.setReadonly(
false);
166 title.setValue(agreement.
getTitle());
167 toNotify.setDisabled(
false);
169 toAccess.setDisabled(
false);
171 toAction.setDisabled(
false);
173 peremptory.setDisabled(
false);
180 title.setReadonly(
true);
181 title.setValue(
null);
182 toNotify.setDisabled(
true);
183 toNotify.setChecked(
false);
184 toAccess.setDisabled(
true);
185 toAccess.setChecked(
false);
186 toAction.setDisabled(
true);
187 toAction.setChecked(
false);
188 peremptory.setDisabled(
true);
189 peremptory.setChecked(
false);
190 action.setReadonly(
true);
191 action.setValue(
null);
197 private Agreement checkAgreement() {
198 if (agreement ==
null) {
199 agreement =
new Agreement();
205 private void sendNotSigned() throws EmailException, Exception {
206 IConstructor constructor = Application.getApplication().getConstructor();
208 if (!as.isSigned()) {
209 IContact contact = as.getContact();
210 if (contact.isWebUser()) {
211 MailSenders.getPool()
212 .setRoot(
"/agreements")
214 .put(
"signature", as)
215 .put(
"acceptUrl", AgreementAction.createURL(constructor, as, contact,
true))
216 .put(
"declineUrl", AgreementAction.createURL(constructor, as, contact,
false))
217 .sendTemplate(
"requiredSignature", as.getAgreement().getTitle() +
" : " + ElephantContext.getSiteName());
226 private Dao getDao() {
228 _dao =
new ElephantPU();
final void onSignatures()
static boolean deleteAgreement(Agreement agreement)
static String logMsg(String msg)
void setAction(String action)
boolean isRequiredToNotify()
void setRequiredToAction(boolean requiredToAction)
void setWiki(String wiki)
void setText(String text)
boolean isRequiredToAction()
void setAppliesTo(String appliesTo)
boolean isRequiredToAccess()
void setRequiredToNotify(boolean requiredToNotify)
void setRequiredToAccess(boolean requiredToAccess)
List< AgreementSignature > getSignatures()
void setTitle(String title)
void setPeremptory(boolean peremptory)
static Messages confirmProcess()
static String get(String msg)
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
void setReadonly(boolean value)
void setValue(String value)