Difference between revisions of "菜单"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
m (Import interlang links (links to translated versions of this page in other languages) from origin English page "Menus_system".)
Tag: 2017 source edit
Line 14: Line 14:
 
{{TemplateMainPageZh}}
 
{{TemplateMainPageZh}}
  
= 菜单 =
+
=Dolibarr菜单系统=
Dolibarr 有两个菜单系统。电脑菜单和手机菜单。
+
Dolibarr 有两个菜单系统。菜单系统定义要显示的菜单项、条件和位置(顶部菜单、左部菜单)。
  
菜单系统定义那一条显示,那个条件,在哪儿显示(顶部菜单、左部菜单)。
+
要更改菜单系统,首先要进入 '''主页 - 设置 - 菜单''' 页面。然后选择 '''菜单编辑器'''。以菜单管理器“Auguria”为例,其作为标准提供,而“Eldy”不是。这些菜单管理器(左侧和顶部)完全可操作,提供相同的视图,但使用不同的存储技术。
  
更改菜单管理器可以从页面: '''主页-菜单'''.  
+
要自定义这些默认菜单,您可以添加自己的菜单项,也可以开发自己的菜单管理器,该管理器将完全覆盖默认菜单管理器。然后,您可以决定如何存储菜单(在数据库中,如Auguria菜单管理器;集中在硬文件中,如菜单管理器Eldy,在XML文件中)。请参阅以下章节...
  
在列表中选择你想要的菜单管理器。
+
=添加您的菜单项=
 +
假设您想添加一个菜单项。前往 '''主页 - 设置 - 菜单'''。选择 '''菜单编辑器'''。添加条目。
  
如果您想个性化菜单,可以添加自己的菜单项或开发自己的菜单管理器,将完全替换默认菜单项。您将决定如何存储菜单定义(数据库与菜单管理器的‘Urgur'’一样,集中硬编码的菜单条目,如菜单中的‘ELDY’,XML文件,……)。正如你所看到的,你可以提供一个菜单管理器,你需要的行为和你想要的技术。请参阅下一章。
+
例如,要添加一个菜单项以进入仅列出已设置过滤器的商机的页面,请添加一个如下所示的条目:
 
 
= 增加菜单项 =
 
打开 '''主页 - 菜单''' 选择 '''菜单编辑器'''。增加一条。
 
For example to add a menu entry to switch to a page that list opportunities with filters already set, you will add and entry that will looks like this:
 
  
 
<div class="divforimgcentpercent">
 
<div class="divforimgcentpercent">
Line 33: Line 30:
 
</div>
 
</div>
  
= 开发自己的菜单管理器 =
+
=开发自己的菜单系统=
The aim of this paper is to describe how to create a new menu system in its entirety (to replace the entire menu entries, complete upheaval of the concept of navigation).
+
本文的目的是描述如何创建一个完整的新菜单系统(替换所有菜单项,完全改变导航概念)。
This does not relate how to add menu entries. If you just want to know how to add menu entries within an existing menu manager, when developing an extension or a new module for example, you should look page [[Module development]] instead.
+
 
If you want to completely replace a system menu with your own, the easiest way is to use the menu Manager "eldy_backoffice" as an example:
+
这不仅仅是添加菜单项。如果是这种情况,并且您只想知道如何在现有菜单管理器中添加菜单项,例如,在开发扩展或新模块时,请参阅 [[模块开发]] 页面。
 +
 
 +
如果您想用自己的菜单系统完全替换现有菜单系统,最简单的方法是使用菜单管理器“eldy_backoffice”作为示例。
 +
 
 +
==开发您的顶部菜单==
 +
只需要
 +
#复制 '''htdocs/core/menus/standard/eldy_backoffice.php''' 为 '''htdocs/core/menus/standard/mymenu.php'''
 +
#编辑 '''mymenu.php'''. 类MenuTop的函数 showmenu() 在生成页面时显示菜单。 You can put here the code you want, this function does not change any external vairable and must show using "print" the menu to show. So you can get menu to show from a configuration file, a database and personalized it according to environment. Environment Dolibarr is stored into 3 global variables: $user, $conf, $langs.
  
== 开发自己的“顶部菜单” ==
 
# 复制 '''htdocs/core/menus/standard/eldy_backoffice.php''' 为 '''htdocs/core/menus/standard/mymenu.php'''
 
# 编辑 '''mymenu.php'''. 类MenuTop的函数 showmenu() 在生成页面时显示菜单。 You can put here the code you want, this function does not change any external vairable and must show using "print" the menu to show. So you can get menu to show from a configuration file, a database and personalized it according to environment. Environment Dolibarr is stored into 3 global variables: $user, $conf, $langs.
 
 
  $user contains information about current user.
 
  $user contains information about current user.
 
  $conf contains information about setup (activated modules, permissions, options, etc...)
 
  $conf contains information about setup (activated modules, permissions, options, etc...)
Line 63: Line 64:
 
</source>
 
</source>
  
== 开发 '''左侧菜单''' ==
+
==开发 '''左侧菜单'''==
 
Principle is same than for top menu.
 
Principle is same than for top menu.
# You must edit function showmenu() of class MenuLeft to build your left menu. If you want to show standard menu with just minor changes without redoing everything, you have to loop on content of array $menu->liste. If you want to build a menu completely different and controled only by yourself, you must, into the method showmenu(), create an object $newmenu=new Menu() and use methods $newmenu->add and $newmenu->add_submenu to defined list of left menu entries to show. Once this is done, you show those entries using some "print" to show content of array $newmenu->liste (that we have just defined) instead of printing content of $menu->liste.
+
 
 +
#You must edit function showmenu() of class MenuLeft to build your left menu. If you want to show standard menu with just minor changes without redoing everything, you have to loop on content of array $menu->liste. If you want to build a menu completely different and controled only by yourself, you must, into the method showmenu(), create an object $newmenu=new Menu() and use methods $newmenu->add and $newmenu->add_submenu to defined list of left menu entries to show. Once this is done, you show those entries using some "print" to show content of array $newmenu->liste (that we have just defined) instead of printing content of $menu->liste.
  
 
Example of file htdocs/core/menus/standard/mymenu.php
 
Example of file htdocs/core/menus/standard/mymenu.php
Line 144: Line 146:
 
</source>
 
</source>
  
= 强制使用菜单管理器 =
+
=强制使用菜单管理器=
 
You can force usage of your own menu manager by creating a module.
 
You can force usage of your own menu manager by creating a module.
 
For this , all you have to do is to declare the 4 following constants into the array $this->const of your module descriptor file (See page [[Module development]]).
 
For this , all you have to do is to declare the 4 following constants into the array $this->const of your module descriptor file (See page [[Module development]]).

Revision as of 07:38, 25 September 2023

Dolibarr菜单系统

Dolibarr 有两个菜单系统。菜单系统定义要显示的菜单项、条件和位置(顶部菜单、左部菜单)。

要更改菜单系统,首先要进入 主页 - 设置 - 菜单 页面。然后选择 菜单编辑器。以菜单管理器“Auguria”为例,其作为标准提供,而“Eldy”不是。这些菜单管理器(左侧和顶部)完全可操作,提供相同的视图,但使用不同的存储技术。

要自定义这些默认菜单,您可以添加自己的菜单项,也可以开发自己的菜单管理器,该管理器将完全覆盖默认菜单管理器。然后,您可以决定如何存储菜单(在数据库中,如Auguria菜单管理器;集中在硬文件中,如菜单管理器Eldy,在XML文件中)。请参阅以下章节...

添加您的菜单项

假设您想添加一个菜单项。前往 主页 - 设置 - 菜单。选择 菜单编辑器。添加条目。

例如,要添加一个菜单项以进入仅列出已设置过滤器的商机的页面,请添加一个如下所示的条目:

Menu editor.png

开发自己的菜单系统

本文的目的是描述如何创建一个完整的新菜单系统(替换所有菜单项,完全改变导航概念)。

这不仅仅是添加菜单项。如果是这种情况,并且您只想知道如何在现有菜单管理器中添加菜单项,例如,在开发扩展或新模块时,请参阅 模块开发 页面。

如果您想用自己的菜单系统完全替换现有菜单系统,最简单的方法是使用菜单管理器“eldy_backoffice”作为示例。

开发您的顶部菜单

只需要

  1. 复制 htdocs/core/menus/standard/eldy_backoffice.phphtdocs/core/menus/standard/mymenu.php
  2. 编辑 mymenu.php. 类MenuTop的函数 showmenu() 在生成页面时显示菜单。 You can put here the code you want, this function does not change any external vairable and must show using "print" the menu to show. So you can get menu to show from a configuration file, a database and personalized it according to environment. Environment Dolibarr is stored into 3 global variables: $user, $conf, $langs.
$user contains information about current user.
$conf contains information about setup (activated modules, permissions, options, etc...)
$langs contains information about active language.

Example of a function showmenu() into file htdocs/core/menus/standard/mymenu.php

    function showmenu()
    {
        global $user,$conf,$langs,$dolibarr_main_db_name;;
        
        print '<table class="tmenu"><tr class="tmenu">';

	    // Menu Home
	    print '<td class="tmenu"><a '.$class.' href="'.DOL_URL_ROOT.'/index.php?mainmenu=home&leftmenu="'.($this->atarget?" target=".$this->atarget:"").'>'.$langs->trans("Home").'</a></td>';
	    
	    // Put here other entries
	    // ...
	    
        print '</tr></table>';
    }

开发 左侧菜单

Principle is same than for top menu.

  1. You must edit function showmenu() of class MenuLeft to build your left menu. If you want to show standard menu with just minor changes without redoing everything, you have to loop on content of array $menu->liste. If you want to build a menu completely different and controled only by yourself, you must, into the method showmenu(), create an object $newmenu=new Menu() and use methods $newmenu->add and $newmenu->add_submenu to defined list of left menu entries to show. Once this is done, you show those entries using some "print" to show content of array $newmenu->liste (that we have just defined) instead of printing content of $menu->liste.

Example of file htdocs/core/menus/standard/mymenu.php

    function showmenu()
    {
        global $user,$conf,$langs,$dolibarr_main_db_name;
        $newmenu = new Menu();
        
	// Put here left menu entries
	// ***** START *****

	$langs->load("admin");	// Load translation file admin.lang
	$newmenu->add(DOL_URL_ROOT."/admin/index.php?leftmenu=setup", $langs->trans("Setup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/company.php", $langs->trans("MenuCompanySetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/modules.php", $langs->trans("Modules"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/ihm.php", $langs->trans("GUISetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/boxes.php", $langs->trans("Boxes"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/delais.php",$langs->trans("Alerts"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/triggers.php", $langs->trans("Triggers"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/perms.php", $langs->trans("Security"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/dict.php", $langs->trans("DictionnarySetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/const.php", $langs->trans("OtherSetup"));
		
	// ***** END *****
		
        // do not change code after this

        // override menu_array by value array in $newmenu
	$this->menu_array=$newmenu->liste;

        $alt=0;
        for ($i = 0 ; $i < sizeof($this->menu_array) ; $i++) 
        {
            $alt++;
            if ($this->menu_array[$i]['level']==0) {
                if (($alt%2==0))
                {
                    print '<div class="blockvmenuimpair">'."\n";
                }
                else
                {
                    print '<div class="blockvmenupair">'."\n";
                }
            }

            if ($this->menu_array[$i]['level']==0) {
                if ($this->menu_array[$i]['enabled'])
                    print '<a class="vmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '<font class="vmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==1) {
                if ($this->menu_array[$i]['enabled'])
                    print '<a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '<font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==2) {
                if ($this->menu_array[$i]['enabled'])
                    print '&nbsp; &nbsp; <a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '&nbsp; &nbsp; <font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==3) {
                if ($this->menu_array[$i]['enabled'])
                    print '&nbsp; &nbsp; &nbsp; &nbsp; <a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '&nbsp; &nbsp; &nbsp; &nbsp; <font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            
            if ($i == (sizeof($this->menu_array)-1) || $this->menu_array[$i+1]['level']==0)  {
                print "</div>\n";
            }
        }

    }

强制使用菜单管理器

You can force usage of your own menu manager by creating a module. For this , all you have to do is to declare the 4 following constants into the array $this->const of your module descriptor file (See page Module development).

* 1=>array('MAIN_MENU_STANDARD_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 2=>array('MAIN_MENUFRONT_STANDARD_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 3=>array('MAIN_MENU_SMARTPHONE_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 4=>array('MAIN_MENUFRONT_SMARTPHONE_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),

Your menu manager will be used once the module is activated.