BrightSide Workbench Full Report + Source Code
WwwMenu.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.elephant.zul.menu;
19 
20 import org.turro.string.Strings;
21 import org.turro.annotation.ExternalMenu;
22 import org.turro.auth.Authentication;
23 import org.turro.command.Context;
24 import org.turro.elephant.context.Application;
25 import org.turro.entities.EntityCombobox;
26 import org.turro.i18n.I_;
27 import org.turro.menu.ElephantMenu;
28 import org.turro.menu.ElephantMenuBar;
29 import org.turro.menu.ElephantSubmenu;
30 import org.turro.security.Permission;
31 import org.turro.timetracker.TimeTrackerExporter;
32 import org.turro.zkoss.dialog.InputDialog;
33 import org.turro.zkoss.dialog.InputField;
34 import org.turro.zul.frame.Framework;
35 import org.zkoss.zk.ui.HtmlBasedComponent;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.util.Clients;
39 
45 public class WwwMenu extends ElephantMenu {
46 
47  @Override
48  public void addToSessionMenu(ElephantSubmenu submenu) {
49  submenu.addMenuitem("Impersonate", "spy", (EventListener) (Event event) -> {
51  I_.get("Impersonate"),
52  new InputField[] {
53  new InputField("Contact", null, null, 0) {
54  @Override
55  protected HtmlBasedComponent createEditor() {
56  EntityCombobox ec = new EntityCombobox();
57  ec.setRoot("contact");
58  return ec;
59  }
60  @Override
61  protected Object getEditorValue() {
62  return ((EntityCombobox) editor).getObjectValue();
63  }
64  }
65  }, (Context context) -> {
66  InputField[] fields = (InputField[]) context.get("fields");
67  if(fields.length > 0) {
68  for(InputField f : fields) {
69  if("Contact".equals(f.getLabel())) {
70  Authentication.impersonateContact(f.getValue());
71  Clients.evalJavaScript("exitWanted=true;");
72  Application.getApplication().sendRedirect("/app/frame");
73  break;
74  }
75  }
76  }
77  return null;
78  });
79  }, Permission.from(() -> {
81  }))
82  .addMenuitem("Back to self", "no-spy", (EventListener) (Event event) -> {
84  Clients.evalJavaScript("exitWanted=true;");
85  Application.getApplication().sendRedirect("/app/frame");
86  }, Permission.from(() -> {
87  return Authentication.isBehaving();
88  }))
89  .addMenuitem("Tags", "tag", "/commons/tagEntities.zul", true)
90  .addMenuitem("Warnings", "warn", "/error/warnings.zul")
91  .addMenuitem("Log", "log", (EventListener) (Event event) -> {
92  showLog(null, null);
93  }, Permission.from("contact:log"))
94  .addMenuitem("Skills", "/commons/rootSkills.zul");
95  }
96 
97  @Override
98  public void addToToolsMenu(ElephantSubmenu submenu) {
99  submenu.addMenuitem("Contexts", "www_context", "/www/admin/webadmin.zul", Permission.from("context:list"))
100  .addMenuitem("Files", "/www/admin/files.zul", Permission.from("context:list"))
101  .addMenuitem("Synonyms", "/publication/synonyms.zul", Permission.from("publication:edit"))
102  .addMenuitem("Occurrences", "/bs/apis/occurrences.zul")
103  .addMenuitem("Actors", "/bs/apis/actors.zul")
104  .addMenuitem("Send by entity", "/mail/mailTo.zul", Permission.from("contact:all"))
105  .addMenuitem("Cleanup", "/bs/apis/cleanup.zul")
106  .addMenuitem("Export time tracker", (EventListener) (Event event) -> {
108  }, Permission.from("contact:list"))
110  .addMenuitem("Reset site settings", (EventListener) (Event event) -> {
112  }, Permission.from("context:list"))
113  .addMenuitem("Reset schemes", (EventListener) (Event event) -> {
115  }, Permission.from("context:list"))
116  .addMenuitem("Configuration", "/www/config/configurator.zul", Permission.from("context:list"))
117  .addMenuSeparator();
118  }
119 
120  @Override
121  public void addToMenu(ElephantMenuBar bar) {
122  bar.addMenu("Statistics", Permission.from("sysinfo:list"))
123  .addSubmenu()
124  .addMenuitem("Rankings", "ranking", "/statistics/rankings.zul", false)
125  .addMenuitem("Matchings", "matching", "/statistics/matchings.zul", false);
126  }
127 
128  public static void showWarnings() {
129  showZulFile("Warnings", "/error/warnings.zul");
130  }
131 
132  public static void showLog(String generatorPath, String entityPath) {
133  Framework.getCurrent().getDesktop().removeAttribute("generatorPath");
134  Framework.getCurrent().getDesktop().removeAttribute("entityPath");
135  if(!Strings.isBlank(generatorPath)) {
136  Framework.getCurrent().getDesktop().setAttribute("generatorPath", generatorPath);
137  } else if(!Strings.isBlank(entityPath)) {
138  Framework.getCurrent().getDesktop().setAttribute("entityPath", entityPath);
139  }
141  "@" + I_.get("Log"),
142  "/log/systemLog.zul", null);
143  }
144 
145 }
static void impersonateIContact(IContact contact)
static void impersonateContact(Object contact)
abstract void sendRedirect(String uri)
void addToMenu(ElephantMenuBar bar)
Definition: WwwMenu.java:121
void addToToolsMenu(ElephantSubmenu submenu)
Definition: WwwMenu.java:98
void addToSessionMenu(ElephantSubmenu submenu)
Definition: WwwMenu.java:48
static void showLog(String generatorPath, String entityPath)
Definition: WwwMenu.java:132
static String get(String msg)
Definition: I_.java:41
ElephantMenu addMenu(String label)
static void showModalZulFile(String label, String source, Command command)
ElephantSubmenu addSubmenu()
ElephantSubmenu addMenuitem(String label, String include)
static Permission from(String... roles)
Definition: Permission.java:79
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static Framework getCurrent()
Definition: Framework.java:203
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216