BrightSide Workbench Full Report + Source Code
AllianceMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.alliance.menu;
20 
21 import org.turro.alliance.model.AllianceServerCombobox;
22 import org.turro.alliance.service.AxConstants;
23 import org.turro.alliance.service.AxServer;
24 import org.turro.alliance.service.AxClient;
25 import org.turro.annotation.ExternalMenu;
26 import org.turro.i18n.I_;
27 import org.turro.importer.ImportFromMembers;
28 import org.turro.json.Jsons;
29 import org.turro.menu.ElephantMenu;
30 import org.turro.menu.ElephantMenuBar;
31 import org.turro.security.Permission;
32 import org.turro.ws.WsServer;
33 import org.turro.ws.service.server.Clients;
34 import org.turro.ws.service.member.Servers;
35 import org.turro.zkoss.dialog.DialogField;
36 import org.turro.zkoss.dialog.Dialogs;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.EventListener;
39 
45 public class AllianceMenu extends ElephantMenu {
46 
47  @Override
48  public void addToMenu(ElephantMenuBar bar) {
49  bar.addMenu("Alliance", Permission.from("@alliance_admin:on"))
50  .addSubmenu()
51  .addMenuitem("Categories", "/alliance/categories.zul", Permission.from(() -> {
52  return Clients.hasMembers(AxClient.CLIENT_SERVICE);
53  }))
54  .addMenuitem("Projects", "/alliance/projects.zul", Permission.from(() -> {
55  return Servers.hasServers(AxServer.SERVER_SERVICE);
56  }))
57  .addMenuitem("Preferences", "/alliance/preferences.zul", Permission.from(() -> {
58  return Servers.hasServers(AxServer.SERVER_SERVICE);
59  }))
60  .addMenuitem("Pending requests", "/alliance/requests.zul", Permission.from(() -> {
61  return Servers.hasServers(AxServer.SERVER_SERVICE);
62  }))
63  .addMenuitem("Full requests", "/alliance/participations.zul", Permission.from(() -> {
64  return Servers.hasServers(AxServer.SERVER_SERVICE);
65  }))
67  .addMenuitem("Talent categories", "/alliance/talentCategories.zul", Permission.from(() -> {
68  return Clients.hasMembers(AxClient.CLIENT_SERVICE);
69  }))
71  .addMenuitem("Update server", "alliance", (EventListener) (Event event) -> {
72  Dialogs.title(I_.get("Select server"))
73  .width("400px")
74  .height("200px")
75  .addField(DialogField.field("Server").onEditor(() -> {
76  return new AllianceServerCombobox();
77  }))
78  .onOk((dialogs) -> {
79  WsServer server = dialogs.<AllianceServerCombobox>getEditor("Server").getObjectValue();
80  if(server != null) Servers.getData(server, AxConstants.UPDATE_SERVER, Jsons.object());
81  })
82  .emptyCancel()
83  .show();
84  }, Permission.from(() -> {
85  return Permission.from("alliance:connect").check() && Servers.hasServers(AxServer.SERVER_SERVICE);
86  }))
87  .addMenuitem("Connect to members", "alliance", (EventListener) (Event event) -> {
89  }, Permission.from(() -> {
90  return Permission.from("alliance:connect").check() && Clients.hasMembers(AxClient.CLIENT_SERVICE);
91  }));
92  }
93 
94 }
void addToMenu(ElephantMenuBar bar)
static final String CLIENT_SERVICE
Definition: AxClient.java:58
static final String SERVER_SERVICE
Definition: AxServer.java:51
static String get(String msg)
Definition: I_.java:41
ElephantMenu addMenu(String label)
ElephantSubmenu addSubmenu()
ElephantSubmenu addMenuitem(String label, String include)
static Permission from(String... roles)
Definition: Permission.java:79
static DialogField field(String label)
Dialogs width(String width)
Definition: Dialogs.java:70
Dialogs height(String height)
Definition: Dialogs.java:75
Dialogs onOk(Consumer< Dialogs > onOk)
Definition: Dialogs.java:85
static Dialogs title(String title)
Definition: Dialogs.java:161
Dialogs addField(DialogField field)
Definition: Dialogs.java:110