Hi,

So I have a dirty source code for you \o/
It works for me so I think it will works for you too.
I'm not proud of that but it's not as worst as I was thinking ;)
I automated all I can, just the URL of the target that I create manually and also the component menu location and name... if somebody want to comment, don't hesitate !

Following the groovy script you have to put in the screen definition.

/** * Created by julien on 12/10/15. */ import javolution.util.FastList
import org.ofbiz.base.component.*
import org.ofbiz.base.util.UtilValidate
import org.ofbiz.widget.PortalPageWorker
import org.ofbiz.widget.menu.* ;
import org.ofbiz.widget.menu.ModelMenuItem

String ofbizServerName = application.getAttribute("_serverId")
if (ofbizServerName.isEmpty()) {
    ofbizServerName ="default-server" ;
}
List<ComponentConfig.WebappInfo> displayApps = 
ComponentConfig.getAppBarWebInfos(ofbizServerName,"main") ;

componentList = FastList.newInstance() ;
HashMap<String, Object> itemMenu;

for (ComponentConfig.WebappInfo currentComponent : displayApps) {
    componentPermission =true ;
    componentPermissions = currentComponent.getBasePermission() ;
    for (String permission : componentPermissions) {
        if( !permission.equals("NONE") && 
!security.hasEntityPermission(permission,"_VIEW", session)){
            componentPermission =false ;
        }
    }
    if (!componentPermission) {
        continue;
    }
    mainMenu = FastList.newInstance() ;

    if (currentComponent.name =="order") {
        componentMenuLocation 
="component://order/widget/ordermgr/OrderMenus.xml" ;
        componentMenuName ="OrderAppBar" ;
    }
    if (currentComponent.name =="party") {
        componentMenuLocation 
="component://party/widget/partymgr/PartyMenus.xml" ;
        componentMenuName ="PartyAppBar" ;
    }
    if (currentComponent.name =="ar") {
        componentMenuLocation ="component://accounting/widget/ar/ArMenus.xml" ;
        componentMenuName ="ArAppBar" ;
    }
    if (currentComponent.name =="ap") {
        componentMenuLocation ="component://accounting/widget/ap/ApMenus.xml" ;
        componentMenuName ="ApAppBar" ;
    }
    if (currentComponent.name =="billing") {
        componentMenuLocation 
="component://accounting/widget/AccountingMenus.xml" ;
        componentMenuName ="menuAccounting" ;
    }
    if (currentComponent.name =="catalog") {
        componentMenuLocation 
="component://product/widget/catalog/CatalogMenus.xml" ;
        componentMenuName ="CatalogAppBar" ;
    }
    if (currentComponent.name =="facility") {
        componentMenuLocation 
="component://product/widget/facility/FacilityMenus.xml" ;
        componentMenuName ="FacilityAppBar" ;
    }
    if (currentComponent.name =="humanres") {
        componentMenuLocation ="component://humanres/widget/HumanresMenus.xml" ;
        componentMenuName ="menuHumanRes" ;
    }
    if (currentComponent.name =="marketing") {
        componentMenuLocation 
="component://marketing/widget/MarketingMenus.xml" ;
        componentMenuName ="MarketingAppBar" ;
    }

    displayMainItems = MenuFactory.getMenuFromLocation(componentMenuLocation, 
componentMenuName) ;
    componentMountPoint = currentComponent.mountPoint.replace('*','') ;
    componentTitle = currentComponent.getTitle();
    componentDescription = currentComponent.getDescription();

    componentInfo =new HashMap<String, Object>() ;
    componentInfo.put("type","Component");
    componentInfo.put("title",componentTitle);
    componentInfo.put("description",componentDescription);
    componentInfo.put("mountPoint",componentMountPoint);
    componentInfo.put("basePermission", currentComponent.getBasePermission()) ;
    mainMenu.add(componentInfo) ;

    for (ModelMenuItem item : displayMainItems.getMenuItemList()) {
        itemMenu =new HashMap<String, Object>();

        if(UtilValidate.isEmpty(item.getLink())) {
            portalPageId = item.parentPortalPageId.toString();
            portalPage = PortalPageWorker.getPortalPage(portalPageId, context) ;
            currentTarget 
="showPortalPage?portalPageId="+portalPageId+"&amp;parentPortalPageId="+portalPageId
 ;
            menuTitle = portalPage.getString("portalPageName");
        }else{
            currentTarget = item.getLink().targetExdr ;
            menuTitle = item.title;
        }

        itemMenu.put("type","ItemMenu");
        itemMenu.put("menuTitle", menuTitle);
        itemMenu.put("urlLink", componentMountPoint+"control/"+currentTarget);

        mainMenu.add(itemMenu);
    }
    componentList.add(mainMenu) ;
}

context.put("componentList",componentList);

And the ftl file you need to show the menu list for all applications

<#assign isComponentEmpty=true> <#list componentListas mainMenu > <#list mainMenuas itemMenu > <#if itemMenu.type=="Component"> <ul class="hp-applist"> <div class="app-title"><span><a href="${itemMenu.mountPoint}control/main"<#if uiLabelMap?exists > title="${uiLabelMap[itemMenu.description]}">${uiLabelMap[itemMenu.title]}<#else> title="${itemMenu.description}">${itemMenu.title}</#if></a></span></div> <#else> <#assign isComponentEmpty=false> <#assign menuTitle = Static["org.ofbiz.base.util.string.FlexibleStringExpander"].expandString(itemMenu.menuTitle, context)/> <li class="hp-menu-item normalItem"> <a href="${itemMenu.urlLink}" class="menu-link" title="${itemMenu.menuTitle}">${menuTitle}</a> <a href="javascript:addReplaceFavorites(this)" title="${uiLabelMap.ClicToAddInFavorite}"> <img class="star-link" src="/embisphere-theme/images/star-yellow.svg"> </a> </li> </#if> </#list> <#if !isComponentEmpty > </ul> <#assign isComponentEmpty=true> </#if> </#list>

Don't forget to put all the uiLabel for all the component in the screen definition.

<property-map resource="OrderUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="OrderErrorUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="ManufacturingUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="WorkEffortUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="PartyUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="HumanResUiLabels" map-name="uiLabelMap" global="true"/> <property-map resource="MarketingUiLabels" map-name="uiLabelMap" global="true"/>

Regards,

Julien.


Le 15/10/2015 10:05, Barou a écrit :
Hi Julien
I am very much interested I am new to ofbiz.
please share it with me



--
View this message in context: 
http://ofbiz.135035.n4.nabble.com/Get-the-menu-list-from-component-tp4673372p4673406.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Reply via email to