Qual: Clean code for adding menu entries into Modules system admin

entry.
New: Add entry for admin page Mass barcode init.
This commit is contained in:
Laurent Destailleur 2014-02-18 20:49:22 +01:00
parent 5780f14a65
commit 03d056319c
7 changed files with 73 additions and 9 deletions

View File

@ -110,11 +110,11 @@ class MenuManager
// Modules system tools
// TODO Find a way to add parent menu only if child menu exists. For the moment, no other method than hard coded methods.
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules
|| ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
{
if (empty($user->societe_id))
{
//$newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', 'home', 'modulesadmintools');
if ($leftmenu=="modulesadmintools" && $user->admin)
{
$langs->load("products");
@ -131,9 +131,27 @@ class MenuManager
'type'=>'left',
'position'=>20
);
array_unshift($tabMenu,$array_menu_product);
//$newmenu->add("/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
if ($leftmenu=="modulesadmintools" && $user->admin)
{
$langs->load("admin");
$array_menu_product=array(
'url'=>"/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools",
'titre'=>$langs->trans("MassBarcodeInit"),
'enabled'=>($user->admin?true:false),
'perms'=>($user->admin?true:false),
'fk_mainmenu'=>'home',
'fk_leftmenu'=>'modulesadmintools',
'fk_menu'=>-1,
'mainmenu'=>'home',
'leftmenu'=>'modulesadmintools_massbarcode',
'type'=>'left',
'position'=>21
);
array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
// Main menu title
$array_menu_product=array(
'url'=>"/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools",
'titre'=>$langs->trans("ModulesSystemTools"),
@ -146,7 +164,7 @@ class MenuManager
'type'=>'left',
'position'=>20
);
array_unshift($tabMenu,$array_menu_product);
array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
}

View File

@ -539,11 +539,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
}
// Modules system tools
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules
|| ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) // Some external modules may need to force to have this entry on.
{
if (empty($user->societe_id))
{
$newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', $mainmenu, 'modulesadmintools');
// Special case: This entry can't be embedded into modules because we need it for both module service and products and we don't want duplicate lines.
if ((empty($leftmenu) || $leftmenu=="modulesadmintools") && $user->admin)
{
$langs->load("products");

View File

@ -101,14 +101,26 @@ class modBarcode extends DolibarrModules
'leftmenu'=>'barcodeprint',
'type'=>'left', // This is a Left menu entry
'titre'=>'BarCodePrintsheet',
'url'=>'/barcode/printsheet.php',
'url'=>'/barcode/printsheet.php?mainmenu=home&leftmenu=modulesadmintools',
'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>200,
'enabled'=>'$conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
$r++;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'MassBarcodeInit',
'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools',
'langs'=>'barcode', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>300,
'enabled'=>'$conf->barcode->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
$r++;
}

View File

@ -129,6 +129,20 @@ class modProduct extends DolibarrModules
$this->rights[$r][4] = 'export';
$r++;
/* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
$r=0;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'ProductVatMassChange',
'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools',
'langs'=>'admin', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>300,
'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
$r++;
*/
// Exports
//--------

View File

@ -114,6 +114,22 @@ class modService extends DolibarrModules
$r++;
/* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
$r=0;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'ProductVatMassChange',
'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools',
'langs'=>'admin', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>300,
'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
$r++;
*/
// Exports
//--------
$r=0;

View File

@ -347,6 +347,8 @@ GetSecuredUrl=Get calculated URL
ButtonHideUnauthorized=Hide buttons for unauthorized actions instead of showing disabled buttons
ProductVatMassChange=Mass VAT change
ProductVatMassChangeDesc=This page can be used to modify a VAT rate defined on products or services from a value to another. Warning, this change is done on all database.
MassBarcodeInit=Mass barcode init
MassBarcodeInitDesc=This page can be used to initialize a barcode on objects that does not have barcode defined. Check before that setup of module barcode is complete.
OldVATRates=Old VAT rate
NewVATRates=New VAT rate
PriceBaseTypeToChange=Modify on prices with base reference value defined on

View File

@ -217,4 +217,4 @@ DefinitionOfBarCodeForThirdpartyNotComplete=Definition of type or value of bar c
BarCodeDataForProduct=Barcode information of product %s :
BarCodeDataForThirdparty=Barcode information of thirdparty %s :
BarcodeStickersMask=xxx