18 package org.turro.contacts.zul.contact;
20 import java.math.BigDecimal;
21 import org.turro.auth.Authentication;
22 import org.turro.contacts.Address;
23 import org.turro.contacts.Contact;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.util.Messages;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.label.LabelTypes;
28 import org.turro.zkoss.layout.GridLayout;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zul.*;
42 private Toolbar toolbar;
43 private Toolbarbutton addButton;
51 this.contact = contact;
52 rows.getChildren().clear();
60 toolbar =
new Toolbar();
61 getParent().appendChild(toolbar);
70 rows.appendChild(row);
76 private void addRow(
final Address a,
final Row parentRow) {
78 parentRow.appendChild(grid);
82 Hlayout hbox =
new Hlayout();
83 hbox.setSclass(
"z-valign-middle");
84 hbox.setValign(
"middle");
85 hbox.setSpacing(
"5px");
90 name.addEventListener(Events.ON_CHANGE,
new EventListener() {
92 public void onEvent(Event event)
throws Exception {
96 hbox.appendChild(name);
98 if(Application.getApplication().isInRole(
"contact-address:delete")) {
99 Image img =
new Image(
"/_zul/images/edit-delete.png");
100 img.setStyle(
"cursor:pointer");
101 img.addEventListener(Events.ON_CLICK,
new EventListener() {
103 public void onEvent(Event event)
throws Exception {
104 Messages.confirmDeletion().show(() -> {
111 hbox.appendChild(img);
116 final Textbox street =
new Textbox();
117 street.setWidth(
"100%");
119 street.addEventListener(Events.ON_CHANGE,
new EventListener() {
121 public void onEvent(Event event)
throws Exception {
129 hbox =
new Hlayout();
130 hbox.setSclass(
"z-valign-middle");
131 hbox.setValign(
"middle");
132 hbox.setSpacing(
"5px");
135 final Textbox zipCode =
new Textbox();
138 zipCode.addEventListener(Events.ON_CHANGE,
new EventListener() {
140 public void onEvent(Event event)
throws Exception {
144 hbox.appendChild(zipCode);
146 hbox.appendChild(
new Space());
147 hbox.appendChild(LabelTypes.getGridCaptionLabel(I_.get(
"City")));
149 final Textbox city =
new Textbox();
152 city.addEventListener(Events.ON_CHANGE,
new EventListener() {
154 public void onEvent(Event event)
throws Exception {
158 hbox.appendChild(city);
160 hbox.appendChild(
new Space());
161 hbox.appendChild(LabelTypes.getGridCaptionLabel(I_.get(
"Province")));
163 final Textbox province =
new Textbox();
164 province.setCols(20);
166 province.addEventListener(Events.ON_CHANGE,
new EventListener() {
168 public void onEvent(Event event)
throws Exception {
172 hbox.appendChild(province);
174 hbox.appendChild(
new Space());
175 hbox.appendChild(LabelTypes.getGridCaptionLabel(I_.get(
"State")));
177 final Textbox state =
new Textbox();
180 state.addEventListener(Events.ON_CHANGE,
new EventListener() {
182 public void onEvent(Event event)
throws Exception {
186 hbox.appendChild(state);
190 hbox =
new Hlayout();
191 hbox.setSclass(
"z-valign-middle");
192 hbox.setValign(
"middle");
193 hbox.setSpacing(
"5px");
196 final Decimalbox longitude =
new Decimalbox(BigDecimal.valueOf(a.
getLongitude()));
197 longitude.addEventListener(Events.ON_CHANGE,
new EventListener() {
199 public void onEvent(Event event)
throws Exception {
203 hbox.appendChild(longitude);
205 hbox.appendChild(
new Space());
206 hbox.appendChild(LabelTypes.getGridCaptionLabel(I_.get(
"Latitude")));
208 final Decimalbox latitude =
new Decimalbox(BigDecimal.valueOf(a.
getLatitude()));
209 latitude.addEventListener(Events.ON_CHANGE,
new EventListener() {
211 public void onEvent(Event event)
throws Exception {
215 hbox.appendChild(latitude);
223 private void addToolbarButtons() {
224 addButton =
new Toolbarbutton(
226 "/_zul/images/new.png"
228 addButton.addEventListener(Events.ON_CLICK,
new EventListener() {
231 public void onEvent(Event event)
throws Exception {
232 Address a =
new Address();
233 a.setContact(contact);
234 a.setOwner(Authentication.getIContact().getId());
240 toolbar.appendChild(addButton);
static String get(String msg)
GridLayout addComponent(HtmlBasedComponent comp)
GridLayout addCaption(String label)