19 package org.turro.crm.zul.sale;
21 import java.util.Date;
22 import java.util.HashSet;
24 import org.amic.util.date.CheckDate;
25 import org.turro.string.Strings;
26 import org.turro.calendar.CalendarEventCallback;
27 import org.turro.calendar.CalendarView;
28 import org.turro.contacts.util.AddressListbox;
29 import org.turro.contacts.util.AttendeesList;
30 import org.turro.crm.db.CrmPU;
31 import org.turro.crm.entity.ProspectType;
32 import org.turro.crm.entity.SaleAction;
33 import org.turro.crm.entity.SaleProspect;
34 import org.turro.crm.entity.TouchPoint;
35 import org.turro.crm.zul.touch.TouchPointListbox;
36 import org.turro.crm.zul.touch.TouchPointRadiogroup;
37 import org.turro.crm.zul.vendor.VendorProspectListbox;
38 import org.turro.elephant.context.Application;
39 import org.turro.elephant.util.Messages;
40 import org.turro.jpa.entity.EntityCollections;
41 import org.turro.util.CompareUtil;
42 import org.zkoss.zk.ui.Component;
43 import org.zkoss.zk.ui.Executions;
44 import org.zkoss.zk.ui.WrongValueException;
45 import org.zkoss.zk.ui.event.InputEvent;
46 import org.zkoss.zk.ui.util.Clients;
47 import org.zkoss.zk.ui.util.GenericForwardComposer;
48 import org.zkoss.zul.A;
49 import org.zkoss.zul.Button;
50 import org.zkoss.zul.Cell;
51 import org.zkoss.zul.Datebox;
52 import org.zkoss.zul.Image;
53 import org.zkoss.zul.Radiogroup;
54 import org.zkoss.zul.Row;
55 import org.zkoss.zul.Textbox;
65 private Datebox fromDate, toDate;
66 private Image fromWatch;
67 private Textbox comment;
71 private Cell touchpointcell;
74 private HashSet<TouchPoint> touchPoints =
new HashSet<TouchPoint>();
76 private Radiogroup status;
77 private Button saveButton, cancelButton, delButton;
80 private Date lastDate;
83 public void onChanging
$comment(InputEvent evt) {
84 updateButtons(
true, evt.getValue());
112 toDate.setValue(CheckDate.addDayDifference(lastDate, fromDate.getValue(), toDate.getValue()));
131 public void onCreate(Date from, Date to) {
132 fromDate.setValue(from);
138 public void onUpdate(Date from, Date to) {
139 fromDate.setValue(from);
145 public String getPath() {
165 saleAction.
setStatus(status.getSelectedIndex());
168 boolean reload = saleAction.
getId() == 0;
169 saleAction =
new CrmPU().saveObject(saleAction);
173 updateButtons(
false);
180 updateButtons(
false);
187 new CrmPU().executeUpdate(
"delete from SaleAction as sa where sa = ?",
new Object[] { saleAction });
194 super.doAfterCompose(comp);
195 saleAction = (
SaleAction) Executions.getCurrent().getAttribute(
"saleAction");
196 if(saleAction ==
null) {
197 saleProspect = (
SaleProspect) Executions.getCurrent().getAttribute(
"saleProspect");
198 if(saleProspect !=
null) {
199 Date from = (Date) Executions.getCurrent().getAttribute(
"from"),
200 to = (Date) Executions.getCurrent().getAttribute(
"to");
202 if(from !=
null && to !=
null) {
213 grid = ((
SaleActionGrid) Executions.getCurrent().getAttribute(
"grid"));
217 row = ((Row) Executions.getCurrent().getAttribute(
"row"));
222 private void updateDates() throws WrongValueException {
223 if(CompareUtil.compare(fromDate.getValue(), toDate.getValue()) > 0) {
224 toDate.setValue(fromDate.getValue());
226 fromWatch.setVisible(fromDate.getValue().before(
new Date()) && status.getSelectedIndex() == 0);
227 lastDate = fromDate.getValue();
230 private void updateControls() {
231 fromDate.setDisabled(status.getSelectedIndex() != 0);
232 toDate.setDisabled(status.getSelectedIndex() != 0);
233 comment.setDisabled(status.getSelectedIndex() != 0);
234 vendor.
setDisabled(status.getSelectedIndex() != 0);
235 attendees.
setReadOnly(status.getSelectedIndex() != 0);
239 touchpoint.
setDisabled(status.getSelectedIndex() != 0);
240 touchpointend.
setDisabled(status.getSelectedIndex() != 0);
241 address.
setDisabled(status.getSelectedIndex() != 0);
244 private void updateButtons(
boolean visible) {
245 updateButtons(visible,
null);
248 private void updateButtons(
boolean visible, String value) {
249 saveButton.setVisible(visible && inputIsValid(value));
250 cancelButton.setVisible(visible);
251 delButton.setVisible(saleAction.
getId() > 0 && Application.getApplication().isInRole(
"sale-action:delete"));
254 private void initControls() throws WrongValueException {
267 touchpointcell.setVisible(
false);
268 touchpoint.setVisible(
false);
269 touchpointend.setVisible(
false);
271 touchpoint.setCheckmark(
true);
272 touchpoint.setMultiple(
true);
282 status.setSelectedIndex(saleAction.
getStatus());
283 if(saleAction.
getId() > 0) {
284 fromDate.setInplace(
true);
285 toDate.setInplace(
true);
286 comment.setInplace(
true);
288 comment.setFocus(
true);
289 Clients.scrollIntoView(status.getParent());
293 updateButtons(
false);
296 private boolean inputIsValid(String value) {
297 return fromDate.getValue() !=
null &&
298 toDate.getValue() !=
null &&
299 (!Strings.isBlank(value) || !Strings.isBlank(comment.getValue())) &&
static void showCalendar(CalendarEventCallback eventCreateCallback)
static String getObjectPath(Object object)
void setActionType(Set< String > actionType)
void setStatus(int status)
TouchPoint getEndingTouchPoint()
void setEndingTouchPoint(TouchPoint tp)
void setAttendees(Set< String > attendees)
VendorProspect getVendorProspect()
Set< TouchPoint > getProcessTouchPoints()
void setVendorProspect(VendorProspect vendorProspect)
Set< String > getAttendees()
void setComment(String comment)
void setFinalDate(Date finalDate)
void setProcessTouchPoints(Set< TouchPoint > stp)
void setActionDate(Date actionDate)
Set< TouchPoint > getTouchPoints()
void setTouchPoints(Set< TouchPoint > touchPoints)
void setAddress(Address address)
Set< String > getActionType()
Set< String > getAttendees()
SaleActionSet getSaleActions()
Set< SaleAction > getSaleActions()
SaleProspect getSaleProspect()
void setTypes(HashSet< String > types)
Collection< String > getCollection()
void onClick $delButton()
void onSelect $touchpoint()
void doAfterCompose(Component comp)
void onChange $fromDate()
void onCheck $touchpointend()
void onChange $attendees()
void onChanging $comment(InputEvent evt)
void onClick $saveButton()
void onClick $cancelButton()
void setSaleProspect(SaleProspect saleProspect)
void setSelectSelf(boolean selectSelf)
static Messages confirmDeletion()
static EntityCollections entities(Collection values)
boolean remove(IDaoEntity entity)
default void prepareSave()