19 package org.turro.dossier.offer;
21 import java.util.Collections;
22 import java.util.Date;
23 import java.util.List;
24 import org.turro.action.Contacts;
25 import org.turro.action.MailSenders;
26 import org.turro.action.PushSenders;
27 import org.turro.auth.Authentication;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.entity.Dossier;
30 import org.turro.dossier.entity.DossierOffer;
31 import org.turro.elephant.util.Messages;
32 import org.turro.entities.Entities;
33 import org.turro.entities.IElephantEntity;
34 import org.turro.file.Document;
35 import org.turro.file.FileWrapper;
36 import org.turro.file.Folder;
37 import org.turro.i18n.I_;
38 import org.turro.jpa.Dao;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.sql.SqlClause;
41 import org.turro.string.Strings;
42 import org.turro.upload.Medias;
43 import org.turro.visual.DossierVisualElement;
44 import org.turro.visual.DossierVisualElements;
45 import org.turro.zkoss.dialog.DialogField;
46 import org.turro.zkoss.dialog.Dialogs;
47 import org.zkoss.bind.BindUtils;
48 import org.zkoss.bind.annotation.BindingParam;
49 import org.zkoss.bind.annotation.Command;
50 import org.zkoss.bind.annotation.ExecutionArgParam;
51 import org.zkoss.bind.annotation.Init;
52 import org.zkoss.bind.annotation.NotifyChange;
53 import org.zkoss.util.media.Media;
54 import org.zkoss.zk.ui.Executions;
65 private List<DossierOffer> model;
68 public void init(@ExecutionArgParam(
"dossierId") String dossierId) {
69 if(Strings.isBlank(dossierId)) {
70 dossierId = Executions.getCurrent().getParameter(
"dossierId");
72 this.dossier = getDao().find(
Dossier.class, Long.valueOf(dossierId));
76 @NotifyChange(
"model")
78 public
void upload(@BindingParam("offer")
DossierOffer offer, @BindingParam("medias") Media medias[]) {
80 Folder folder = offer.getFolder();
81 for(Media media : medias) {
86 .
addContact(offer.getDossier().getDefaultResponsible())
87 .addContact(offer.getBidder())
90 .
addContact(offer.getDossier().getDefaultResponsible())
91 .addContact(offer.getBidder())
92 .silentSendTemplate(iee,
"newdocs",
I_.
get(
"New documents"));
97 public
void download(@BindingParam("document") Document document) {
101 @Command(
"deleteDoc")
102 public
void deleteDoc(@BindingParam("document") Document document) {
105 BindUtils.postNotifyChange(
null,
null,
OffersVM.this,
"model");
112 offer.getFolder().
remove();
114 BindUtils.postNotifyChange(
null,
null,
OffersVM.this,
"model");
120 if(!canCreate)
return;
126 String description = dialogs.getValue(
"Description", String.class);
127 if(!Strings.isBlank(description)) {
128 DossierOffer offer = new DossierOffer();
129 offer.setDossier(dossier);
130 offer.setCreation(new Date());
131 offer.setDescription(description);
132 offer.setBidderId(contact.getId());
133 offer = getDao().saveEntity(offer);
134 BindUtils.postNotifyChange(null, null, OffersVM.this,
"model");
135 IElephantEntity iee = Entities.getController(dossier);
136 PushSenders.getPool()
137 .addContact(offer.getDossier().getDefaultResponsible())
138 .addContact(offer.getBidder())
139 .send(I_.get(
"Offer"), I_.get(
"New offer"), iee.getEntityUrl());
140 MailSenders.getPool().setRoot(
"/offers")
141 .addContact(offer.getDossier().getDefaultResponsible())
142 .addContact(offer.getBidder())
143 .silentSendTemplate(iee,
"new", I_.get(
"New offer"));
150 @NotifyChange(
"model")
154 .
add(
I_.
get(
"This action will accept the offer and send a notification.")).
show(() -> {
155 offer.setAccepted(
true);
156 offer.setDeclined(
false);
157 getDao().saveObject(offer);
160 .
addContact(offer.getDossier().getDefaultResponsible())
161 .addContact(offer.getBidder())
164 .
addContact(offer.getDossier().getDefaultResponsible())
165 .addContact(offer.getBidder())
166 .silentSendTemplate(iee,
"accepted",
I_.
get(
"Accepted"));
170 @NotifyChange(
"model")
174 .
add(
I_.
get(
"This action will decline the offer and send a notification.")).
show(() -> {
175 offer.setAccepted(
false);
176 offer.setDeclined(
true);
177 getDao().saveObject(offer);
180 .
addContact(offer.getDossier().getDefaultResponsible())
181 .addContact(offer.getBidder())
184 .
addContact(offer.getDossier().getDefaultResponsible())
185 .addContact(offer.getBidder())
186 .silentSendTemplate(iee,
"declined",
I_.
get(
"Declined"));
191 if(prepareValues()) {
192 model = SqlClause.select(
"p")
193 .from(
"DossierOffer p")
194 .where().equal(
"p.dossier", dossier)
196 .and().equal(
"p.bidderId", contact.
getId())
200 if(!model.isEmpty()) canCreate =
false;
203 return Collections.EMPTY_LIST;
226 private boolean canAll, canCreate, canShow, canAddWorking, canAddFinal;
228 private boolean prepareValues() {
236 return canAll || canShow || canCreate;
245 private Dao getDao() {
247 _dao =
new DossierPU();
static IMailSender getPool()
static IPushSender getPool()
static IContact getIContact()
void deleteDoc(@BindingParam("document") Document document)
boolean canDelete(DossierOffer offer)
void upload(@BindingParam("offer") DossierOffer offer, @BindingParam("medias") Media medias[])
void accept(@BindingParam("offer") DossierOffer offer)
boolean canAccept(DossierOffer offer)
List< DossierOffer > getModel()
boolean canUpload(DossierOffer offer)
void decline(@BindingParam("offer") DossierOffer offer)
void init(@ExecutionArgParam("dossierId") String dossierId)
void delete(@BindingParam("offer") DossierOffer offer)
void download(@BindingParam("document") Document document)
static Messages confirmDeletion()
static Messages confirmProcess()
static Messages confirmAcceptation()
Messages add(String word)
static IElephantEntity getController(String path)
static String get(String msg)
void deleteObject(Object obj)
boolean canCreateOffer(Dossier dossier, IContact contact)
boolean canShowOffer(Issue issue, IContact contact)
boolean canAddFinalOffer(Dossier dossier, IContact contact)
boolean canAddWorkingOffer(Dossier dossier, IContact contact)
static DossierVisualElements load()
DialogField lines(int lines)
static DialogField field(String label)
Dialogs width(String width)
Dialogs height(String height)
Dialogs onOk(Consumer< Dialogs > onOk)
static Dialogs title(String title)
Dialogs addField(DialogField field)
IMailSender setRoot(String root)