BrightSide Workbench Full Report + Source Code
MailToControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.mail.zul;
20 
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.apache.commons.mail.EmailException;
26 import org.turro.action.Contacts;
27 import org.turro.action.MailSenders;
28 import org.turro.auth.Authentication;
29 import org.turro.command.Command;
30 import org.turro.command.Context;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.entities.Entities;
33 import org.turro.entities.EntityCombobox;
34 import org.turro.i18n.I_;
35 import org.turro.plugin.contacts.ContactList;
36 import org.turro.plugin.contacts.IContact;
37 import org.turro.sendable.MailRecipients;
38 import org.turro.zkoss.text.WikiEditor;
39 import org.zkoss.zk.ui.Executions;
40 import org.zkoss.zk.ui.IdSpace;
41 import org.zkoss.zk.ui.ext.AfterCompose;
42 import org.zkoss.zk.ui.select.Selectors;
43 import org.zkoss.zk.ui.select.annotation.Listen;
44 import org.zkoss.zk.ui.select.annotation.Wire;
45 import org.zkoss.zk.ui.util.Clients;
46 import org.zkoss.zul.Panel;
47 import org.zkoss.zul.Textbox;
48 
53 public class MailToControl extends Panel implements IdSpace, AfterCompose {
54 
55  @Wire("#subject")
56  private Textbox subject;
57 
58  @Wire("#wikiText")
59  private WikiEditor wikiText;
60 
61  @Wire("#from")
62  private EntityCombobox from;
63 
64  @Wire("#entity")
65  private EntityCombobox entity;
66 
67  @Wire("#recipients")
68  private RecipientsGrid recipients;
69 
70  @Listen("onClick = #send")
71  public void onSend() {
72  try {
73  IContact cfrom = Contacts.getContact(from.getEntity());
75  .setRoot("/mailTo")
76  .setFrom(cfrom)
77  .addAssistants(recipients.getAssistants())
78  .put("iee", Entities.getController(entity.getEntity()))
79  .put("subject", subject.getValue())
80  .put("text", wikiText.getHtml())
81  .sendTemplate("mailTo", subject.getValue());
82  Clients.showNotification(I_.get("Comment was sent..."));
83  } catch (EmailException ex) {
84  Logger.getLogger(MailToControl.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
85  }
86  }
87 
88  @Listen("onClick = #sendTest")
89  public void onSendTest() {
90  ContactList contacts = new ContactList();
91  contacts.add(Authentication.getIContact());
92  MailRecipients.selectRecipients(contacts, new Command() {
93  @Override
94  public Object execute(Context context) {
95  MailRecipients mr = (MailRecipients) context.get("component");
96  Collection<IContact> emails = mr.getRecipients();
97  if(emails != null) {
98  try {
99  IContact cfrom = Contacts.getContact(from.getEntity());
100  HashMap args = new HashMap();
102  .setRoot("/mailTo")
103  .setFrom(cfrom)
104  .addContacts(emails)
105  .put("iee", Entities.getController(entity.getEntity()))
106  .put("subject", subject.getValue())
107  .put("text", wikiText.getHtml())
108  .sendTemplate("mailTo", subject.getValue());
109  Clients.showNotification(I_.get("Comment was sent..."));
110  } catch (EmailException ex) {
111  Logger.getLogger(MailToControl.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
112  }
113  }
114  return null;
115  }
116  });
117  }
118 
119  public MailToControl() {
120  Executions.createComponents("/WEB-INF/_zul/bs/comps/mailTo/mailToControl.zul", this, null);
121  Selectors.wireComponents(this, this, false);
122  Selectors.wireEventListeners(this, this);
123  }
124 
125  @Override
126  public void afterCompose() {
127  initComponents();
128  }
129 
130  private void initComponents() {
131  from.setRoot("contact");
133  recipients.initGrid();
134  updateButtons();
135  }
136 
137  private void updateButtons() {
138  }
139 
140 }
static IContact getContact(Object object)
Definition: Contacts.java:109
static IMailSender getPool()
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String get(String msg)
Definition: I_.java:41
static void selectRecipients(Collection< IContact > recipients, Command command)
T addContacts(Collection< IContact > contacts)
T addAssistants(AssistantSet assistants)
IMailSender setFrom(IContact contact)
IMailSender setRoot(String root)