BrightSide Workbench Full Report + Source Code
ConvocationComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zul.convocation;
20 
21 import org.turro.contacts.Attendee;
22 import org.turro.contacts.Convocation;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.contacts.zul.menu.ContactMenu;
25 import org.turro.elephant.context.Application;
26 import org.turro.elephant.util.Messages;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.composer.EntityComposer;
29 import org.turro.jpa.entity.DaoEntity;
30 import org.turro.zul.frame.Framework;
31 import org.zkoss.lang.Strings;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.select.annotation.Listen;
35 import org.zkoss.zk.ui.util.Clients;
36 
41 public class ConvocationComposer extends EntityComposer<Convocation, String> {
42 
43  @Listen("onUser = #detail #attendees")
44  public void onSendToAttendee(Event event) {
45  if(event.getData() instanceof Attendee) {
46  if(!entity.isEmpty()) {
47  new ConvocationSender(entity, ((Attendee) event.getData()).getIContact()).send();
48  Clients.showNotification(I_.get("Convocation sent"));
49  }
50  }
51  }
52 
53  @Listen("onClick = #sendMail")
54  public void onSendMail() {
55  if(!entity.isEmpty()) {
57  Clients.showNotification(I_.get("Convocation sent"));
58  }
59  }
60 
61  @Listen("onClick = #savesendMail")
62  public void onSaveAndSendMail() {
63  if(!entity.isEmpty()) {
64  doOnSave();
66  Clients.showNotification(I_.get("Convocation sent"));
67  }
68  }
69 
70  @Override
71  protected String getAttributeName() {
72  return "convocation";
73  }
74 
75  @Override
76  protected Convocation getEntityInstance(String id) {
77  if(id == null) {
78  entity = new Convocation();
79  } else {
80  entity = new ContactsPU().find(Convocation.class, id);
81  }
82  return entity;
83  }
84 
85  @Override
86  protected DaoEntity getWrapperInstance(Component comp) {
90  return w;
91  }
92 
93  @Override
94  public void doFinally() throws Exception {
95  super.doFinally();
97  }
98 
99  @Override
100  protected boolean shouldBeSaved() {
101  return !entity.isEmpty() && (Strings.isBlank(entity.getId())) || super.shouldBeSaved();
102  }
103 
104  @Override
105  protected boolean inSaveRole() {
106  return Application.getApplication().isInRole("convocation:edit");
107  }
108 
109  @Override
110  protected boolean inDeleteRole() {
111  return Application.getApplication().isInRole("convocation:delete");
112  }
113 
114  @Override
115  protected void doOnDelete() {
116  Messages.confirmDeletion().show(() -> {
118  });
119  }
120 
121  @Override
122  public void afterSave() {
123  if(entity != null) {
125  }
126  }
127 
128 }
static void showConvocation(String id)
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41
static AssistantSet getAsAssistants(Convocation convocation)
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
void setSelectedTooltiptext(String text)
Definition: Framework.java:107