ItEr16S07RFDesenhoGraficoPortalItEr15S09: Separated menus to a macro component and managed from a separate controller

This commit is contained in:
Lorenzo Tilve 2009-07-09 22:50:33 +02:00 committed by Javier Moran Rua
parent bbf9af0978
commit 3406d2b24d
3 changed files with 155 additions and 26 deletions

View file

@ -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 <br />
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
*/
public class CustomMenuController extends Div {
private List<CustomMenuItem> firstLevel;
public class CustomMenuItem {
private final String name;
private final String url;
private final List<CustomMenuItem> children;
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public List<CustomMenuItem> getChildren() {
return children;
}
public CustomMenuItem(String name, String url) {
this.name = name;
this.url = url;
this.children = new ArrayList<CustomMenuItem>();
}
public CustomMenuItem(String name, String url,
List<CustomMenuItem> 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<CustomMenuItem> l = new ArrayList<CustomMenuItem>();
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<CustomMenuItem> getCustomMenuItems() {
return this.firstLevel;
}
public List<CustomMenuItem> 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();
}
}

View file

@ -0,0 +1,28 @@
<div id="menuContainer" xmlns:n="http://www.zkoss.org/2005/zk/native"
use="org.navalplanner.web.common.CustomMenuController">
<n:table border="0" cellspacing="0" cellpadding="0">
<n:tr>
<n:td forEach="${menuContainer.customMenuItems}">
<n:a href="${each.url}" class="menuup">${c:l(each.name)}</n:a>
</n:td>
</n:tr>
</n:table>
<n:table width="100%" height="30" border="0" cellpadding="0"
cellspacing="0">
<n:tr>
<n:td bgcolor="#2A83B4">
<n:table border="0" cellspacing="0" cellpadding="0">
<n:tr>
<n:td width="10" />
<n:td forEach="${menuContainer.customMenuSecondaryItems}">
<n:a href="${each.url}" class="sub_menu">${c:l(each.name)}</n:a>
<n:td width="14"
background="/navalplanner-webapp/common/img/sub_separacion.gif" />
</n:td>
</n:tr>
</n:table>
</n:td>
</n:tr>
</n:table>
</div>

View file

@ -1,6 +1,8 @@
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_v01.css"?>
<?link rel="stylesheet" type="text/css" href="/common/css/navalpro_zk.css"?>
<?component name="customMenu" inline="true" macroURI="_customMenu.zul"?>
<zk self="@{define(content)}">
<n:div xmlns:n="http://www.zkoss.org/2005/zk/native">
<n:table width="100%" border="0" cellpadding="0" cellspacing="0">
@ -15,37 +17,15 @@
<n:td height="20" align="right"><n:table border="0" cellspacing="0" cellpadding="0">
<n:tr>
<n:td class="usuario">usuario: admin</n:td>
<n:td><n:a href="#" class="cerrar_sesion">PECHAR SESIÓN </n:a></n:td>
<n:td><n:a href="#" class="cerrar_sesion">PECHAR SESIÓN</n:a></n:td>
<n:td><n:a href="#"><n:img src="/navalplanner-webapp/common/img/axuda.gif" alt="Axuda" width="23" height="24" border="0" /></n:a></n:td>
</n:tr>
</n:table></n:td>
</n:tr>
</n:table>
<n:table border="0" cellspacing="0" cellpadding="0">
<n:tr>
<n:td><n:a href="/navalplanner-webapp/" class="menuup">${c:l('mainmenu.plannification')}</n:a></n:td>
<n:td><n:a href="/navalplanner-webapp/resources/worker/worker.zul" class="menuup">${c:l('mainmenu.resources')}</n:a></n:td>
<n:td><n:a href="/navalplanner-webapp/orders/orders.zul" class="menuup">${c:l('mainmenu.orders')}</n:a></n:td>
<n:td><n:a href="#" class="menuup">${c:l('mainmenu.work_reports')}</n:a></n:td>
<n:td><n:a href="#" class="menuup">${c:l('mainmenu.quality_management')}</n:a></n:td>
<n:td><n:a href="#" class="menuup">${c:l('mainmenu.administration')}</n:a></n:td>
</n:tr>
</n:table>
<n:table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
<n:tr>
<n:td bgcolor="#2A83B4">
<n:table border="0" cellspacing="0" cellpadding="0">
<n:tr>
<n:td width="10"></n:td>
<n:td><n:a href="/navalplanner-webapp/resources/worker/worker.zul#list" class="sub_menu">${c:l('mainmenu.list_workers')}</n:a></n:td>
<n:td width="14" background="/navalplanner-webapp/common/img/sub_separacion.gif"></n:td>
<n:td><n:a href="/navalplanner-webapp/resources/criterions/criterions.zul" class="sub_menu">${c:l('mainmenu.manage_criterions')}</n:a></n:td>
</n:tr>
</n:table>
</n:td>
</n:tr>
</n:table>
<customMenu top_id="customMenu" title="Main menu"/>
</n:td>
</n:tr>
</n:table></n:td>
@ -73,4 +53,5 @@
<n:td height="75" align="right" valign="bottom" background="img/linea_down.gif"><n:img src="/navalplanner-webapp/common/img/logos_aplicacion.gif" width="332" height="73" /></n:td>
</n:tr>
</n:table>
</n:div>
</n:div>
</zk>