From 3406d2b24d1b2dc5b25fa104124afb825d4f803b Mon Sep 17 00:00:00 2001 From: Lorenzo Tilve Date: Thu, 9 Jul 2009 22:50:33 +0200 Subject: [PATCH] ItEr16S07RFDesenhoGraficoPortalItEr15S09: Separated menus to a macro component and managed from a separate controller --- .../web/common/CustomMenuController.java | 120 ++++++++++++++++++ .../main/webapp/common/layout/_customMenu.zul | 28 ++++ .../webapp/common/layout/template_v02.zul | 33 +---- 3 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java create mode 100644 navalplanner-webapp/src/main/webapp/common/layout/_customMenu.zul diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java new file mode 100644 index 000000000..027e35b32 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java @@ -0,0 +1,120 @@ +package org.navalplanner.web.common; + +import java.util.ArrayList; +import java.util.List; + +import org.zkoss.zk.ui.Executions; +import org.zkoss.zul.Div; + +/** + * Controller for customMenu
+ * @author Lorenzo Tilve Álvaro + */ +public class CustomMenuController extends Div { + + private List firstLevel; + + public class CustomMenuItem { + + private final String name; + private final String url; + private final List children; + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } + + public List getChildren() { + return children; + } + + public CustomMenuItem(String name, String url) { + this.name = name; + this.url = url; + this.children = new ArrayList(); + } + + public CustomMenuItem(String name, String url, + List children) { + this.name = name; + this.url = url; + this.children = children; + } + + public void appendChildren(CustomMenuItem newChildren) { + this.children.add(newChildren); + } + + } + + public CustomMenuController() { + initializeMenu(); + } + + public void initializeMenu() { + List l = new ArrayList(); + CustomMenuItem ci; + + ci = new CustomMenuItem("mainmenu.plannification", + "/navalplanner-webapp/"); + ci.appendChildren(new CustomMenuItem("mainmenu.plannification", + "/navalplanner-webapp/planner/main.zul")); + ci.appendChildren(new CustomMenuItem("mainmenu.company_overview", + "/navalplanner-webapp/planner/main.zul")); + ci.appendChildren(new CustomMenuItem("mainmenu.plannifications_list", + "/navalplanner-webapp/planner/main.zul")); + l.add(ci); + + ci = new CustomMenuItem("mainmenu.resources", + "/navalplanner-webapp/resources/worker/worker.zul"); + ci.appendChildren(new CustomMenuItem("mainmenu.list_workers", + "/navalplanner-webapp/resources/worker/worker.zul#list")); + ci.appendChildren(new CustomMenuItem("mainmenu.manage_criterions", + "/navalplanner-webapp/resources/criterions/criterions.zul")); + l.add(ci); + + ci = new CustomMenuItem("mainmenu.orders", + "/navalplanner-webapp/orders/orders.zul"); + ci.appendChildren(new CustomMenuItem("mainmenu.list_orders", + "/orders/orders.zul")); + ci.appendChildren(new CustomMenuItem("mainmenu.activity_work_types", + "/orders/orders.zul")); + ci.appendChildren(new CustomMenuItem("mainmenu.models", + "/orders/orders.zul")); + l.add(ci); + + ci = new CustomMenuItem("mainmenu.work_reports", + "/navalplanner-webapp/"); + l.add(ci); + + ci = new CustomMenuItem("mainmenu.quality_management", + "/navalplanner-webapp/"); + l.add(ci); + + ci = new CustomMenuItem("mainmenu.quality_management", + "/navalplanner-webapp/"); + l.add(ci); + + this.firstLevel = l; + } + + public List getCustomMenuItems() { + return this.firstLevel; + } + + public List getCustomMenuSecondaryItems() { + String requestPath = Executions.getCurrent().getDesktop() + .getRequestPath(); + for (CustomMenuItem ci : this.firstLevel) { + if (requestPath.contains(ci.url) || ci.url.contains(requestPath)) { + return ci.getChildren(); + } + } + return this.firstLevel.get(0).getChildren(); + } + +} \ No newline at end of file diff --git a/navalplanner-webapp/src/main/webapp/common/layout/_customMenu.zul b/navalplanner-webapp/src/main/webapp/common/layout/_customMenu.zul new file mode 100644 index 000000000..c7204c062 --- /dev/null +++ b/navalplanner-webapp/src/main/webapp/common/layout/_customMenu.zul @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/navalplanner-webapp/src/main/webapp/common/layout/template_v02.zul b/navalplanner-webapp/src/main/webapp/common/layout/template_v02.zul index f572eb9c0..04a00f474 100644 --- a/navalplanner-webapp/src/main/webapp/common/layout/template_v02.zul +++ b/navalplanner-webapp/src/main/webapp/common/layout/template_v02.zul @@ -1,6 +1,8 @@ + + @@ -15,37 +17,15 @@ usuario: admin - PECHAR SESIÓN + PECHAR SESIÓN - - - ${c:l('mainmenu.plannification')} - ${c:l('mainmenu.resources')} - ${c:l('mainmenu.orders')} - ${c:l('mainmenu.work_reports')} - ${c:l('mainmenu.quality_management')} - ${c:l('mainmenu.administration')} - - - - - - - - - ${c:l('mainmenu.list_workers')} - - ${c:l('mainmenu.manage_criterions')} - - - - - + + @@ -73,4 +53,5 @@ - \ No newline at end of file + + \ No newline at end of file