BrightSide Workbench Full Report + Source Code
ContactMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts.zul.menu;
19 
20 import java.util.Map;
21 import org.turro.string.Strings;
22 import org.turro.annotation.ExternalMenu;
23 import org.turro.auth.Authentication;
24 import org.turro.command.Command;
25 import org.turro.command.Context;
26 import org.turro.contacts.Contact;
27 import org.turro.elephant.zkoss.Modal;
28 import org.turro.elephant.zkoss.ModalWindow;
29 import org.turro.i18n.I_;
30 import org.turro.menu.ElephantMenu;
31 import org.turro.menu.ElephantMenuBar;
32 import org.turro.menu.ElephantSubmenu;
33 import org.turro.security.Permission;
34 import org.turro.zul.frame.Framework;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 
43 public class ContactMenu extends ElephantMenu {
44 
45  @Override
46  public void addToMenu(ElephantMenuBar bar) {
47  bar.addMenu("Contacts", Permission.from("contact:list"))
48  .addSubmenu()
49  //.addMenuitem("My contacts", "contacts", "/contact/mycontacts.zul", false)
50  .addMenuitem("Contacts", "contacts", "/contact/contacts.zul", true)
51  .addMenuitem("New contact", "contact_new", (EventListener) (Event event) -> {
52  ContactMenu.showContact((String) null);
53  }, Permission.from("contact:new"))
54  .addMenuitem("Pending to accept", "/contact/relation/pendingToAccept.zul", false, Permission.from("contact:new"))
55  .addMenuitem("Contact proposals", "/contact/proposals.zul", Permission.from("contact-proposal:import"))
56  .addMenuitem("Relation proposals", "/contact/importer/importer.zul", Permission.from("contact-proposal:import"))
57  .addMenuitem("Social grups check", "/contact/relation/socialCheck.zul", false, Permission.from("contact:new"))
58  .addMenuitem("Name proposals", "/contact/names/names.zul", false, Permission.from("contact:new"))
60  .addMenuitem("Field definitions", "/contact/fielddefs.zul", Permission.from("contact-field:list"))
61  .addToolbarSeparator(true)
62  .addMenuitem("Subscriptions", "forward", (EventListener) (Event event) -> {
64  }, Permission.from("contact:all"));
65  }
66 
67  @Override
68  public void addToSessionMenu(ElephantSubmenu submenu) {
69  submenu.addMenuSeparator()
70  .addMenuitem("Groups", "group", "/contact/groupIt/groups.zul", true, Permission.from("groups:list"))
71  .addMenuitem("Acceptance", "acceptation", "/contact/acceptances.zul", true)
72  .addMenuitem("Participations", "participation", "/contact/entityParticipation.zul", false, Permission.from("contact:all"))
73  .addMenuitem("Agreements", "acceptation", "/agreements/agreements.zul", false, Permission.from("contact:all"))
75  .addMenuitem("New convocation", "/contact/convocation/convocation.zul", Permission.from("convocation:new"));
76  }
77 
78  public static void showAcceptance(String path, final Command command) {
79  if(!Strings.isBlank(path)) {
80  Framework frame = Framework.getCurrent();
81  if(frame != null) {
82  frame.getDesktop().setAttribute("acceptancePath", path);
83  Modal.doModal(ElephantMenu.makeInclude("/contact/acceptance.zul"), new Command() {
84  @Override
85  public Object execute(Context context) {
86  ModalWindow mw = (ModalWindow) context.get("win");
87  if(mw.getResult() == 1) {
88  if(command != null) command.execute(context);
89  }
90  return null;
91  }
92  });
93  }
94  }
95  }
96 
97  public static void showAcceptances() {
98  Framework frame = Framework.getCurrent();
99  frame.addContent(I_.get("Acceptance"), ElephantMenu.makeInclude("/contact/acceptances.zul"));
100  frame.invalidateSelected();
101  }
102 
103  public static void showContact(Contact contact) {
104  showEntity(contact.getId(), "contactId", "Contact", "/contact/contact.zul", Map.of("contactGenerated", contact));
105  }
106 
107  public static void showContact(String id) {
108  showEntity(id, "contactId", "Contact", "/contact/contact.zul");
109  }
110 
111  public static void showConvocation(String id) {
112  showEntity(id, "convocationId", "Convocation", "/contact/convocation/convocation.zul");
113  }
114 
115  public static void showService(String id) {
116  showEntity(id, "serviceId", "Service", "/contact/service/service.zul");
117  }
118 
119  public static void showParticipations(String entityPath) {
120  showZulFile("Participations", "/contact/entityParticipation.zul", Map.of("entityPath", entityPath));
121  }
122 
123  public static void showSubscriptions(Contact contact) {
124  showZulFile("Subscriptions", "/contact/subscriptions.zul", Map.of("contact", contact));
125  }
126 
127  public static void showOrganigram(Contact contact) {
128  showZulFile("Organigram", "/contact/organigram.zul", Map.of("contact", contact));
129  }
130 
131 }
static void showAcceptance(String path, final Command command)
static void showOrganigram(Contact contact)
void addToMenu(ElephantMenuBar bar)
static void showSubscriptions(Contact contact)
static void showConvocation(String id)
static void showContact(Contact contact)
void addToSessionMenu(ElephantSubmenu submenu)
static void showParticipations(String entityPath)
static int doModal(String file)
Definition: Modal.java:38
static String get(String msg)
Definition: I_.java:41
ElephantMenu addMenu(String label)
static String makeInclude(String include)
static void showEntity(Object id, String attribute, String label, String include)
ElephantSubmenu addSubmenu()
static void showZulFile(String label, String include)
ElephantSubmenu addMenuitem(String label, String include)
ElephantSubmenu addToolbarSeparator(boolean bar)
static Permission from(String... roles)
Definition: Permission.java:79
void addContent(String label, String src)
Definition: Framework.java:69
static Framework getCurrent()
Definition: Framework.java:203
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216