BrightSide Workbench Full Report + Source Code
ErpMenu.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.erp.menu;
19 
20 import java.util.HashMap;
21 import org.turro.annotation.ExternalMenu;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.zkoss.RoleMap;
24 import org.turro.erp.db.ErpPU;
25 import org.turro.erp.entity.RequiredUsage;
26 import org.turro.erp.entity.Task;
27 import org.turro.erp.entity.WorkOrder;
28 import org.turro.zkoss.menu.ElephantMenu;
29 import org.turro.zkoss.menu.ElephantMenuBar;
30 import org.turro.elephant.zkoss.ElLabel;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.EventListener;
33 import org.zkoss.zul.Menu;
34 import org.zkoss.zul.Menupopup;
35 
41 public class ErpMenu extends ElephantMenu {
42 
43  @Override
44  public void addMenus(final ElephantMenuBar bar) {
45  RoleMap rm = new RoleMap(Application.getApplication());
46  if(rm.containsKey("erp-purchase,erp-sales")) {
47  // Supply chain
48  Menu m = bar.addMenu(Application.getString("lSupplyChain"));
49  Menupopup mp = bar.addMenupopup(m);
50  // Purchase
51  if(rm.get("erp-purchase:new")) {
52  Menu mm = bar.addMenu(mp, Application.getString("lPurchase"));
53  Menupopup mip = bar.addMenupopup(mm);
54  bar.addMenuitem(mip, Application.getString("lOrders"), "/_zul/images/orders.png", "/WEB-INF/_zul/erp/purchase/orders.zul", false);
55  bar.addMenuitem(mip, Application.getString("lHoursOrder"), null, "/WEB-INF/_zul/erp/purchase/hoursOrder.zul", false);
56  bar.addMenuitem(mip, Application.getString("lProductsOrder"), null, "/WEB-INF/_zul/erp/purchase/productsOrder.zul", false);
57  bar.addMenuSeparator(mp);
58  bar.addMenuitem(mip, Application.getString("lReceipts"), "/_zul/images/receipts.png", "/WEB-INF/_zul/erp/purchase/receipts.zul", false);
59  bar.addMenuitem(mip, Application.getString("lHoursReceipt"), null, "/WEB-INF/_zul/erp/purchase/hoursReceipt.zul", false);
60  bar.addMenuitem(mip, Application.getString("lProductsReceipt"), null, "/WEB-INF/_zul/erp/purchase/productsReceipt.zul", false);
61  }
62  // Sales
63  if(rm.get("erp-sales:new")) {
64  Menu mm = bar.addMenu(mp, Application.getString("lSales"));
65  Menupopup mip = bar.addMenupopup(mm);
66  bar.addMenuitem(mip, Application.getString("lCustomerOrders"), "/_zul/images/orders.png", "/WEB-INF/_zul/erp/sales/orders.zul", false);
67  bar.addMenuitem(mip, Application.getString("lNewCustomerOrder"), "/_zul/images/order_new.png", new EventListener() {
68  @Override
69  public void onEvent(Event event) throws Exception {
71  }
72  }, false);
73  }
74  }
75  if(rm.containsKey("erp-workorder,erp-task,erp-reference")) {
76  // Manufacture
77  Menu m = bar.addMenu(Application.getString("lManufacturing"));
78  Menupopup mp = bar.addMenupopup(m);
79  if(rm.get("erp-task:list")) {
80  bar.addMenuitem(mp, Application.getString("lPendingTasks"), "/_zul/images/task_pending.png", "/WEB-INF/_zul/erp/task/pendingTasks.zul", true);
81  bar.addMenuitem(mp, Application.getString("lWorkload"), "/_zul/images/workload.png", "/WEB-INF/_zul/erp/task/workloads.zul", true);
82  }
83  bar.addMenuitem(mp, Application.getString("lTimeControl"), null, "/WEB-INF/_zul/erp/resource/timeControl.zul", false);
84  if(rm.get("erp-workorder:list") || rm.get("erp-reference:list") || rm.get("erp-task:list")) {
85  Menu mm = bar.addMenu(mp, Application.getString("lWorkOrders"));
86  Menupopup mip = bar.addMenupopup(mm);
87  if(rm.get("erp-workorder:list")) {
88  bar.addMenuitem(mip, Application.getString("lWorkOrders"), "/_zul/images/workorder.png", "/WEB-INF/_zul/erp/workorder/workorders.zul", true);
89  }
90  if(rm.get("erp-task:list")) {
91  bar.addMenuitem(mip, Application.getString("lTasks"), "/_zul/images/task.png", "/WEB-INF/_zul/erp/task/tasks.zul", false);
92  }
93  bar.addToolbarSeparator(true);
94  bar.addMenuSeparator(mip);
95  if(rm.get("erp-workorder:new")) {
96  bar.addMenuitem(mip, Application.getString("lNewWorkOrder"), "/_zul/images/workorder_new.png", new EventListener() {
97  @Override
98  public void onEvent(Event event) throws Exception {
99  showModalZulFile("lNewWorkOrder", "/WEB-INF/_zul/erp/workorder/newWorkorder.zul", null);
100  }
101  }, true);
102  }
103  if(rm.get("erp-workorder:new")) {
104  bar.addMenuitem(mip, Application.getString("lNewProductOrder"), "/_zul/images/productorder_new.png", new EventListener() {
105  @Override
106  public void onEvent(Event event) throws Exception {
107  showModalZulFile("lNewProductOrder", "/WEB-INF/_zul/erp/workorder/newProductorder.zul", null);
108  }
109  }, true);
110  }
111  bar.addToolbarSeparator(true);
112  }
113  if(rm.get("erp-config:list")) {
114  Menu mm = bar.addMenu(mp, Application.getString("lConfiguration"));
115  Menupopup mip = bar.addMenupopup(mm);
116  bar.addMenuitem(mip, Application.getString("lHumanResources"), "/_zul/images/operator.png", "/WEB-INF/_zul/erp/config/humanResources.zul");
117  bar.addMenuitem(mip, Application.getString("lAptitudes"), "/_zul/images/aptitude.png", "/WEB-INF/_zul/erp/config/aptitudes.zul");
118  bar.addMenuitem(mip, Application.getString("lResources"), "/_zul/images/resource.png", "/WEB-INF/_zul/erp/config/resources.zul");
119  }
120  }
121  }
122 
123  public static void showWorkOrder(WorkOrder workOrder) {
124  HashMap<String, Object> map = new HashMap<String, Object>();
125  map.put("workOrderGenerated", workOrder);
126  showEntity(workOrder.getId(), "workOrderId", "lWorkOrder", "/WEB-INF/_zul/erp/workorder/workorder.zul", map);
127  }
128 
129  public static void showWorkOrder(Long id) {
130  showEntity(id, "workOrderId", "lWorkOrder", "/WEB-INF/_zul/erp/workorder/workorder.zul");
131  }
132 
133  public static void showTask(Task task) {
134  HashMap<String, Object> map = new HashMap<String, Object>();
135  map.put("taskGenerated", task);
136  showEntity(task.getId(), "taskId", "lTask", "/WEB-INF/_zul/erp/task/task.zul", map);
137  }
138 
139  public static void showTaskDetail(Long id, boolean view) {
140  Task task = new ErpPU().find(Task.class, id);
141  if(task != null) {
142  showTaskDetail(task, view);
143  }
144  }
145 
146  public static void showTaskDetail(Task task, boolean view) {
147  HashMap<String, Object> map = new HashMap<String, Object>();
148  map.put("task", task);
149  map.put("view", view);
150  showPopupZulFile("@" + task.getFullDescription(), "/WEB-INF/_zul/erp/task/detail.zul", map);
151  }
152 
153  public static void showUsageDetail(Long id) {
154  RequiredUsage requiredUsage = new ErpPU().find(RequiredUsage.class, id);
155  if(requiredUsage != null) {
156  showUsageDetail(requiredUsage);
157  }
158  }
159 
160  public static void showUsageDetail(RequiredUsage requiredUsage) {
161  HashMap<String, Object> map = new HashMap<String, Object>();
162  map.put("requiredUsage", requiredUsage);
163  showPopupZulFile("@" + requiredUsage.getTask().getFullDescription(), "/WEB-INF/_zul/erp/task/usageDetail.zul", map);
164  }
165 
166  public static void showTask(Long id) {
167  showEntity(id, "taskId", "lTask", "/WEB-INF/_zul/erp/task/task.zul");
168  }
169 
170  public static void showAptitude(Long id) {
171  showEntity(id, "aptitudeId", "lAptitude", "/WEB-INF/_zul/erp/config/aptitude.zul");
172  }
173 
174  public static void showResource(Long id) {
175  showEntity(id, "resourceId", "lResource", "/WEB-INF/_zul/erp/config/resource.zul");
176  }
177 
178  public static void showHumanResource(Long id) {
179  showEntity(id, "humanResourceId", "lHumanResource", "/WEB-INF/_zul/erp/config/humanResource.zul");
180  }
181 
182  public static void showCustomerOrder(Long id) {
183  showEntity(id, "customerOrderId", "lCustomerOrder", "/WEB-INF/_zul/erp/sales/order.zul");
184  }
185 
186 }
static String getString(String key)
static void showUsageDetail(Long id)
Definition: ErpMenu.java:153
static void showWorkOrder(Long id)
Definition: ErpMenu.java:129
static void showHumanResource(Long id)
Definition: ErpMenu.java:178
static void showWorkOrder(WorkOrder workOrder)
Definition: ErpMenu.java:123
static void showAptitude(Long id)
Definition: ErpMenu.java:170
static void showResource(Long id)
Definition: ErpMenu.java:174
void addMenus(final ElephantMenuBar bar)
Definition: ErpMenu.java:44
static void showTaskDetail(Task task, boolean view)
Definition: ErpMenu.java:146
static void showTask(Long id)
Definition: ErpMenu.java:166
static void showTaskDetail(Long id, boolean view)
Definition: ErpMenu.java:139
static void showUsageDetail(RequiredUsage requiredUsage)
Definition: ErpMenu.java:160
static void showCustomerOrder(Long id)
Definition: ErpMenu.java:182
static void showTask(Task task)
Definition: ErpMenu.java:133