N°4621 Fix naming inconsistencies in sources/*

This commit is contained in:
Pierre Goiffon
2021-12-31 15:21:08 +01:00
parent 16142bd979
commit 5f575d524a
192 changed files with 384 additions and 380 deletions

View File

@@ -0,0 +1,68 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
/**
* Class NewsroomMenu
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\NewsroomMenu
* @internal
* @since 3.0.0
*/
class NewsroomMenu extends PopoverMenu
{
// Overloaded constants
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/newsroom-menu/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/popover-menu/newsroom-menu/layout';
public const DEFAULT_JS_FILES_REL_PATH = [
'js/components/newsroom-menu.js',
];
/** @var array $aParams */
protected $aParams;
/**
* Set all parameters at once
*
* @param array $aParams
*
* @return $this
*/
public function SetParams(array $aParams)
{
$this->aParams = $aParams;
return $this;
}
/**
* Return all parameters as a JSON string
*
* @return false|string
*/
public function GetParamsAsJson(): string
{
return json_encode($this->aParams);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu;
use appUserPreferences;
use MetaModel;
use UserRights;
use utils;
/**
* Class NewsroomMenuFactory
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\NewsroomMenu
* @internal
* @since 3.0.0
*/
class NewsroomMenuFactory
{
/**
* Make a standard NewsroomMenu layout for backoffice pages
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\NewsroomMenu\NewsroomMenu
* @throws \CoreException
* @throws \Exception
*/
public static function MakeNewsroomMenuForNavigationMenu()
{
$oMenu = new NewsroomMenu('ibo-navigation-menu--notifications-menu');
$oMenu->SetParams(static::PrepareParametersForNewsroomMenu());
return $oMenu;
}
/**
* Prepare parameters for the newsroom JS widget
*
* @return array
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
* @throws \OQLException
*/
protected static function PrepareParametersForNewsroomMenu()
{
$aProviderParams=[];
$oUser = UserRights::GetUserObject();
/**
* @var \iNewsroomProvider[] $aProviders
*/
$aProviders = MetaModel::EnumPlugins('iNewsroomProvider');
foreach($aProviders as $oProvider) {
$oConfig = MetaModel::GetConfig();
$oProvider->SetConfig($oConfig);
$bProviderEnabled = appUserPreferences::GetPref('newsroom_provider_'.get_class($oProvider), true);
if ($bProviderEnabled && $oProvider->IsApplicable($oUser)) {
$aProviderParams[] = array(
'label' => $oProvider->GetLabel(),
'fetch_url' => $oProvider->GetFetchURL(),
'target' => utils::StartsWith($oProvider->GetFetchURL(), $oConfig->Get('app_root_url')) ? '_self' : '_blank',
'view_all_url' => $oProvider->GetViewAllURL(),
'mark_all_as_read_url' => $oProvider->GetMarkAllAsReadURL(),
'placeholders' => $oProvider->GetPlaceholders(),
'ttl' => $oProvider->GetTTL(),
);
}
}
$sImageUrl= 'fas fa-comment-dots';
$sPlaceholderImageUrl= 'far fa-envelope';
$aParams = array(
'image_icon' => $sImageUrl,
'no_message_icon' => file_get_contents(APPROOT.'images/illustrations/undraw_empty.svg'),
'placeholder_image_icon' => $sPlaceholderImageUrl,
'cache_uuid' => 'itop-newsroom-'.UserRights::GetUserId().'-'.md5(APPROOT),
'providers' => $aProviderParams,
'display_limit' => (int)appUserPreferences::GetPref('newsroom_display_size', 7),
'labels' => array(
'no_notification' => 'UI:Newsroom:NoNewMessage',
'x_notifications' => 'UI:Newsroom:XNewMessage',
'mark_all_as_read' => 'UI:Newsroom:MarkAllAsRead',
'view_all' => 'UI:Newsroom:ViewAllMessages'
),
);
return $aParams;
}
}

View File

@@ -0,0 +1,536 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem;
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\UIBlock;
use Exception;
/**
* Class PopoverMenu
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu
* @internal
* @since 3.0.0
*/
class PopoverMenu extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-popover-menu';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/popover-menu/layout';
public const DEFAULT_JS_FILES_REL_PATH = [
'js/components/popover-menu.js',
];
// Specific constants
/** @see static::$sContainer */
public const ENUM_CONTAINER_BODY = 'body';
/** @see static::$sContainer */
public const ENUM_CONTAINER_PARENT = 'parent';
/** @see static::$sTargetForPositionJSSelector */
public const ENUM_TARGET_FOR_POSITION_TOGGLER = 'toggler';
/** @see static::$sVerticalPosition */
public const ENUM_VERTICAL_POSITION_ABOVE = 'above';
/** @see static::$sVerticalPosition */
public const ENUM_VERTICAL_POSITION_BELOW = 'below';
/**
* @see static::$sHorizontalPosition
*
* +--------+
* | Target |
* +--------+-----------+
* | |
* | Menu |
* | |
* +--------------------+
*/
public const ENUM_HORIZONTAL_POSITION_ALIGN_INNER_LEFT = 'align_inner_left';
/**
* @see static::$sHorizontalPosition
*
* +--------+
* | Target |
* +--------------------+--------+
* | |
* | Menu |
* | |
* +--------------------+
*/
public const ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_LEFT = 'align_outer_left';
/**
* @see static::$sHorizontalPosition
*
* +--------+
* | Target |
* +-----------+--------+
* | |
* | Menu |
* | |
* +--------------------+
*/
public const ENUM_HORIZONTAL_POSITION_ALIGN_INNER_RIGHT = 'align_inner_right';
/**
* @see static::$sHorizontalPosition
*
* +--------+
* | Target |
* +--------+--------------------+
* | |
* | Menu |
* | |
* +--------------------+
*/
public const ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_RIGHT = 'align_outer_right';
/** @see static::$sContainer */
public const DEFAULT_CONTAINER = self::ENUM_CONTAINER_PARENT;
/** @see static::$sTargetForPositionJSSelector */
public const DEFAULT_TARGET_FOR_POSITION = self::ENUM_TARGET_FOR_POSITION_TOGGLER;
/** @see static::$sVerticalPosition */
public const DEFAULT_VERTICAL_POSITION = self::ENUM_VERTICAL_POSITION_BELOW;
/** @see static::$sHorizontalPosition */
public const DEFAULT_HORIZONTAL_POSITION = self::ENUM_HORIZONTAL_POSITION_ALIGN_INNER_RIGHT;
/** @var string JS selector for the DOM element that should trigger the menu open/close */
protected $sTogglerJSSelector;
/** @var bool Whether the menu should add a visual hint (caret down) on the toggler to help the user understand that clicking on the toggler won't do something right away, but will open a menu instead */
protected $bAddVisualHintToToggler;
/** @var string Container element of the menu. Can be either:
* * static::ENUM_CONTAINER_PARENT (default, better performance)
* * static::ENUM_CONTAINER_BODY (use it if the menu gets cut by the hidden overflow of its parent)
*/
protected $sContainer;
/**
* @var string JS selector for the DOM element the menu should be positioned relatively to.
* * static::ENUM_TARGET_FOR_POSITION_TOGGLER (default, a shortcut pointing to the toggler)
* * A JS selector
*/
protected $sTargetForPositionJSSelector;
/** @var string Relative vertical position of the menu from the target. Value can be:
* * static::ENUM_VERTICAL_POSITION_BELOW for the menu to be directly below the target
* * static::ENUM_VERTICAL_POSITION_ABOVE for the menu to be directly above the target
* * A JS expression to be evaluated that must return pixels (eg. (oTargetPos.top + oTarget.outerHeight(true)) + 'px')
*/
protected $sVerticalPosition;
/** @var string Relative horizontal position of the menu from the target. Value can be:
* * static::ENUM_HORIZONTAL_POSITION_ALIGN_INNER_LEFT for the menu to be aligned with the target's left side
* * static::ENUM_HORIZONTAL_POSITION_ALIGN_INNER_RIGHT for the menu to be aligned with the target's right side
* * A JS expression to be evaluated that must return pixels (eg. (oTargetPos.left + oTarget.outerWidth(true) - popover.width()) + 'px')
*/
protected $sHorizontalPosition;
/** @var array */
protected $aSections;
/**
* PopoverMenu constructor.
*
* @param string|null $sId
*/
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->sTogglerJSSelector = '';
$this->bAddVisualHintToToggler = false;
$this->sContainer = static::DEFAULT_CONTAINER;
$this->sTargetForPositionJSSelector = static::DEFAULT_TARGET_FOR_POSITION;
$this->sVerticalPosition = static::DEFAULT_VERTICAL_POSITION;
$this->sHorizontalPosition = static::DEFAULT_HORIZONTAL_POSITION;
$this->aSections = [];
}
/**
* @param string $sSelector
*
* @return $this
* @uses static::$sTogglerJSSelector
*/
public function SetTogglerJSSelector(string $sSelector)
{
$this->sTogglerJSSelector = $sSelector;
return $this;
}
/**
* Shortcut to avoid passing the '#' in static::SetTogglerJSSelector().
*
* @param string $sId
*
* @return $this
*/
public function SetTogglerFromId(string $sId)
{
$this->SetTogglerJSSelector('#'.$sId);
return $this;
}
/**
* Shortcut to get the toggler JS selector directly from the block
*
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
*
* @return $this
*/
public function SetTogglerFromBlock(iUIBlock $oBlock)
{
$this->SetTogglerFromId($oBlock->GetId());
return $this;
}
/**
* @return string
* @uses static::$sTogglerJSSelector
*/
public function GetTogglerJSSelector(): string
{
return $this->sTogglerJSSelector;
}
/**
* @return bool
* @uses static::$sTogglerJSSelector
*/
public function HasToggler(): bool
{
return !empty($this->sTogglerJSSelector);
}
/**
* @return $this
* @uses static::$bAddVisualHintToToggler
*/
public function AddVisualHintToToggler()
{
$this->bAddVisualHintToToggler = true;
return $this;
}
/**
* @return bool
* @uses static::$bAddVisualHintToToggler
*/
public function HasVisualHintToAddToToggler(): bool
{
return $this->bAddVisualHintToToggler;
}
/**
* @param string $sContainer
*
* @return $this
* @uses static::$sContainer
*/
public function SetContainer(string $sContainer)
{
$this->sContainer = $sContainer;
return $this;
}
/**
* @return string
* @uses static::$sContainer
*/
public function GetContainer(): string
{
return $this->sContainer;
}
/**
* @param string $sJSSelector
*
* @return $this
* @uses static::$sTargetForPositionJSSelector
*/
public function SetTargetForPositionJSSelector(string $sJSSelector)
{
$this->sTargetForPositionJSSelector = $sJSSelector;
return $this;
}
/**
* @return string
* @uses static::$sTargetForPositionJSSelector
*/
public function GetTargetForPositionJSSelector(): string
{
return $this->sTargetForPositionJSSelector;
}
/**
* @param string $sPosition
*
* @return $this
* @uses static::$sVerticalPosition
*/
public function SetVerticalPosition(string $sPosition)
{
$this->sVerticalPosition = $sPosition;
return $this;
}
/**
* @return string
* @uses static::$sVerticalPosition
*/
public function GetVerticalPosition(): string
{
return $this->sVerticalPosition;
}
/**
* @param string $sPosition
*
* @return $this
* @uses static::$sHorizontalPosition
*/
public function SetHorizontalPosition(string $sPosition)
{
$this->sHorizontalPosition = $sPosition;
return $this;
}
/**
* @return string
* @uses static::$sHorizontalPosition
*/
public function GetHorizontalPosition(): string
{
return $this->sHorizontalPosition;
}
/**
* Add a section $sId if not already existing.
* Important: It does not reset the section.
*
* @param string $sId
*
* @return $this
*/
public function AddSection(string $sId)
{
if (false === $this->HasSection($sId))
{
$this->aSections[$sId] = [
'aItems' => [],
];
}
return $this;
}
/**
* Remove the $sId section.
* Note: If the section does not exist, we silently proceed anyway.
*
* @param string $sId
*
* @return $this
* @throws \Exception
*/
public function RemoveSection(string $sId)
{
if (true === $this->HasSection($sId))
{
unset($this->aSections[$sId]);
}
return $this;
}
/**
* Return true if the $sId section exists
*
* @param string $sId
*
* @return bool
*/
public function HasSection(string $sId): bool
{
return array_key_exists($sId, $this->aSections);
}
/**
* Clear the $sId section from all its items.
*
* @param string $sId
*
* @return $this
* @throws \Exception
*/
public function ClearSection(string $sId)
{
if (false === $this->HasSection($sId))
{
throw new Exception('Could not clear section "'.$sId.'" as it does not exist in the "'.$this->GetId().'" menu');
}
$this->aSections[$sId]['aItems'] = [];
return $this;
}
/**
* Return the sections
*
* @return array
*/
public function GetSections(): array
{
return $this->aSections;
}
/**
* @return bool Whether there are some sections, even if they have no items.
* @uses static::$aSections
*/
public function HasSections(): bool
{
return !empty($this->aSections);
}
/**
* Add the $oItem in the $sSectionId. If an item with the same ID already exists it will be overwritten.
*
* @param string $sSectionId
* @param \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem $oItem
*
* @return $this
* @throws \Exception
*/
public function AddItem(string $sSectionId, PopoverMenuItem $oItem)
{
if (false === $this->HasSection($sSectionId)) {
$this->AddSection($sSectionId);
}
$this->aSections[$sSectionId]['aItems'][$oItem->GetId()] = $oItem;
return $this;
}
/**
* Remove the $sItemId from the $sSectionId.
* Note: If the item is not in the section, we proceed silently.
*
* @param string $sSectionId
* @param string $sItemId
*
* @return $this
* @throws \Exception
*/
public function RemoveItem(string $sSectionId, string $sItemId)
{
if (false === $this->HasSection($sSectionId))
{
throw new Exception('Could not remove en item from the "'.$sSectionId.'" as it does not seem to exist in the "'.$this->GetId().'" menu.');
}
if (array_key_exists($sItemId, $this->aSections[$sSectionId]['aItems']))
{
unset($this->aSections[$sSectionId]['aItems'][$sItemId]);
}
return $this;
}
/**
* Add all $aItems to the $sSectionId after the existing items
*
* @param string $sSectionId
* @param PopoverMenuItem[] $aItems
*
* @return $this
* @throws \Exception
*/
public function AddItems(string $sSectionId, array $aItems)
{
foreach($aItems as $oItem){
$this->AddItem($sSectionId, $oItem);
}
return $this;
}
/**
* Set all $aItems at once in the $sSectionId, overwriting all existing.
*
* @param string $sSectionId
* @param PopoverMenuItem[] $aItems
*
* @return $this
* @throws \Exception
*/
public function SetItems(string $sSectionId, array $aItems)
{
if (false === $this->HasSection($sSectionId)) {
throw new Exception('Could not set items to the "'.$sSectionId.'" section has it does not seem to exist in the "'.$this->GetId().'" menu.');
}
$this->aSections[$sSectionId]['aItems'] = $aItems;
return $this;
}
/**
* @return bool Whether there is at least 1 section with some items
* @uses static::$aSections
*/
public function HasItems(): bool
{
$bResult = false;
foreach ($this->GetSections() as $sId => $aData) {
if (!empty($aData['aItems'])) {
$bResult = true;
break;
}
}
return $bResult;
}
/**
* @inheritDoc
*/
public function GetSubBlocks(): array
{
$aSubBlocks = [];
foreach ($this->aSections as $sSectionId => $aSectionData) {
foreach($aSectionData['aItems'] as $sItemId => $oItem)
{
$aSubBlocks[$sItemId] = $oItem;
}
}
return $aSubBlocks;
}
}

View File

@@ -0,0 +1,276 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
use Dict;
use JSPopupMenuItem;
use MetaModel;
use SeparatorPopupMenuItem;
use URLPopupMenuItem;
use iPopupMenuExtension;
use UserRights;
use utils;
/**
* Class PopoverMenuFactory
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu
* @internal
* @since 3.0.0
*/
class PopoverMenuFactory
{
/**
* Make a standard NavigationMenu layout for backoffice pages
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu
* @throws \CoreException
* @throws \Exception
*/
public static function MakeUserMenuForNavigationMenu()
{
$oMenu = new PopoverMenu('ibo-navigation-menu--user-menu');
$oMenu->SetTogglerJSSelector('[data-role="ibo-navigation-menu--user-menu--toggler"]')
->SetContainer(PopoverMenu::ENUM_CONTAINER_BODY)
->SetHorizontalPosition(PopoverMenu::ENUM_HORIZONTAL_POSITION_ALIGN_OUTER_RIGHT)
->SetVerticalPosition(PopoverMenu::ENUM_VERTICAL_POSITION_ABOVE);
// Allowed portals
$aAllowedPortalsItems = static::PrepareAllowedPortalsItemsForUserMenu();
if (!empty($aAllowedPortalsItems)) {
$oMenu->AddSection('allowed_portals')
->SetItems('allowed_portals', $aAllowedPortalsItems);
}
// User related pages
$oMenu->AddSection('user_related')
->SetItems('user_related', static::PrepareUserRelatedItemsForUserMenu());
// API: iPopupMenuExtension::MENU_USER_ACTIONS
$aAPIItems = static::PrepareAPIItemsForUserMenu($oMenu);
if (count($aAPIItems) > 0) {
$oMenu->AddSection('popup_menu_extension-menu_user_actions')
->SetItems('popup_menu_extension-menu_user_actions', $aAPIItems);
}
// Misc links
$oMenu->AddSection('misc')
->SetItems('misc', static::PrepareMiscItemsForUserMenu());
return $oMenu;
}
/**
* Return the allowed portals items for the current user
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem[]
*/
protected static function PrepareAllowedPortalsItemsForUserMenu()
{
$aItems = [];
foreach (UserRights::GetAllowedPortals() as $aAllowedPortal)
{
if ($aAllowedPortal['id'] !== 'backoffice')
{
$oPopupMenuItem = new URLPopupMenuItem(
'portal:'.$aAllowedPortal['id'],
Dict::S($aAllowedPortal['label']),
$aAllowedPortal['url'],
'_blank'
);
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem($oPopupMenuItem);
}
}
return $aItems;
}
/**
* Return the user related items (preferences, change password, log off, ...)
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem[]
* @throws \CoreException
* @throws \Exception
*/
protected static function PrepareUserRelatedItemsForUserMenu()
{
$aItems = [];
// Preferences
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:Preferences',
Dict::S('UI:Preferences'),
utils::GetAbsoluteUrlAppRoot().'pages/preferences.php'
)
);
// Archive mode
if(true === utils::IsArchiveMode())
{
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
'UI:ArchiveModeOff',
Dict::S('UI:ArchiveModeOff'),
'return ArchiveMode(false);'
)
);
}
elseif(UserRights::CanBrowseArchive())
{
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
'UI:ArchiveModeOn',
Dict::S('UI:ArchiveModeOn'),
'return ArchiveMode(true);'
)
);
}
// Logoff
if(utils::CanLogOff())
{
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:LogOffMenu',
Dict::S('UI:LogOffMenu'),
utils::GetAbsoluteUrlAppRoot().'pages/logoff.php?operation=do_logoff'
)
);
}
// Change password
if (UserRights::CanChangePassword())
{
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:ChangePwdMenu',
Dict::S('UI:ChangePwdMenu'),
utils::GetAbsoluteUrlAppRoot().'pages/UI.php?loginop=change_pwd'
)
);
}
return $aItems;
}
/**
* @param \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu $oMenu Here we must pass a block ($oMenu) as the helper will use it to dispatch the external resources (files) if some.
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem[] Return the items from the iPopupMenuExtension::MENU_USER_ACTIONS API
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \Exception
*/
protected static function PrepareAPIItemsForUserMenu(PopoverMenu &$oMenu)
{
$aOriginalItems = [];
utils::GetPopupMenuItemsBlock($oMenu, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aOriginalItems);
$aTransformedItems = [];
foreach($aOriginalItems as $sItemID => $aItemData) {
$aTransformedItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItemData($sItemID, $aItemData);
}
return $aTransformedItems;
}
/**
* Return the misc. items for the user menu (online doc., about box)
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem[]
*/
protected static function PrepareMiscItemsForUserMenu()
{
$aItems = [];
// Online documentation
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
'UI:Help',
Dict::S('UI:Help'),
MetaModel::GetConfig()->Get('online_help'),
'_blank'
)
);
// About box
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
'UI:AboutBox',
Dict::S('UI:AboutBox'),
'return ShowAboutBox();'
)
);
return $aItems;
}
/**
* Make a menu for the $aActions as prepared by \DisplayBlock
*
* @param string $sId
* @param array $aActions
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu
* @throws \Exception
*/
public static function MakeMenuForActions(string $sId, array $aActions): PopoverMenu
{
// Prepare sections and actions
$iSectionIndex = 0;
$aMenuItems = [];
foreach ($aActions as $sActionId => $aAction) {
// Skip separators as they are "transformed" into sections
if (empty($aAction['url'])) {
$iSectionIndex++;
continue;
}
$aMenuItems["{$sId}_section_{$iSectionIndex}"][$sActionId] = $aAction;
}
// Prepare actual menu
$oMenu = new PopoverMenu($sId);
$bFirst = true;
foreach ($aMenuItems as $sSection => $aActions) {
$oMenu->AddSection($sSection);
if (!$bFirst) {
$oMenu->AddItem($sSection, PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new SeparatorPopupMenuItem()
));
}
foreach ($aActions as $sActionId => $aAction) {
$oMenu->AddItem($sSection, PopoverMenuItemFactory::MakeFromApplicationPopupMenuItemData($sActionId, $aAction));
}
$bFirst = false;
}
return $oMenu;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use JSPopupMenuItem;
/**
* Class JsPopoverMenuItem
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @property \JSPopupMenuItem $oPopupMenuItem
* @since 3.0.0
*/
class JsPopoverMenuItem extends PopoverMenuItem
{
// Overloaded constants
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/mode_js';
/**
* @see \JSPopupMenuItem::GetJsCode()
* @return string
*/
public function GetJsCode()
{
return $this->oPopupMenuItem->GetJSCode();
}
/**
* @see \JSPopupMenuItem::GetUrl()
* @return string
*/
public function GetUrl()
{
return $this->oPopupMenuItem->GetUrl();
}
/**
* @inheritDoc
* @throws \Exception
*/
public function GetJsFilesUrlRecursively(bool $bAbsoluteUrl = false): array
{
$aJsFiles = array_merge(parent::GetJsFilesUrlRecursively($bAbsoluteUrl), $this->oPopupMenuItem->GetLinkedScripts());
return $aJsFiles;
}
}

View File

@@ -0,0 +1,164 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use ApplicationPopupMenuItem;
use Combodo\iTop\Application\UI\Base\UIBlock;
use utils;
/**
* Class PopoverMenuItem
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @internal
* @since 3.0.0
*/
class PopoverMenuItem extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-popover-menu--item';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/layout';
/** @var \ApplicationPopupMenuItem $oPopupMenuItem We decorate the class with the original \ApplicationPopupMenuItem as it is used among the application (backoffice, portal, extensions) and cannot be refactored without BC breaks */
protected $oPopupMenuItem;
/**
* PopoverMenuItem constructor.
*
* @param \ApplicationPopupMenuItem $oPopupMenuItem
*/
public function __construct(ApplicationPopupMenuItem $oPopupMenuItem)
{
$this->oPopupMenuItem = $oPopupMenuItem;
parent::__construct(/* ID will be generated from $oPopupMenuItem */);
}
/**
* @inheritDoc
*/
protected function GenerateId(): string
{
return parent::GenerateId().'--'.utils::GetSafeId($this->oPopupMenuItem->GetUID());
}
/**
* @see \ApplicationPopupMenuItem::GetLabel()
* @return string
*/
public function GetLabel()
{
return $this->oPopupMenuItem->GetLabel();
}
/**
* @param array $aCssClasses
*
* @return $this
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::SetCssClasses()
*/
public function SetMenuItemCssClasses(array $aCssClasses)
{
$this->oPopupMenuItem->SetCssClasses($aCssClasses);
return $this;
}
/**
* @param string $sCssClass
*
* @return $this
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::AddCssClass()
*/
public function AddMenuItemCssClass(string $sCssClass)
{
$this->oPopupMenuItem->AddCssClass($sCssClass);
return $this;
}
/**
* @return array
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::GetCssClasses()
*/
public function GetMenuItemCssClasses(): array
{
return $this->oPopupMenuItem->GetCssClasses();
}
/**
* @return string
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::GetIconClass()
*/
public function GetIconClass()
{
return $this->oPopupMenuItem->GetIconClass();
}
/**
* @return $this
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::SetIconClass()
*/
public function SetIconClass($sIconClas)
{
$this->oPopupMenuItem->SetIconClass($sIconClas);
return $this;
}
/**
* @return string
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::GetTooltip()
*/
public function GetTooltip()
{
return $this->oPopupMenuItem->GetTooltip();
}
/**
* @return $this
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::SetTooltip()
*/
public function SetTooltip($sTooltip)
{
$this->oPopupMenuItem->SetTooltip($sTooltip);
return $this;
}
/**
* @return string
* @uses oPopupMenuItem
* @uses \ApplicationPopupMenuItem::GetUID()
*/
public function GetUID()
{
return $this->oPopupMenuItem->GetUID();
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
use ApplicationPopupMenuItem;
use JSPopupMenuItem;
use SeparatorPopupMenuItem;
use URLPopupMenuItem;
/**
* Class PopupMenuItemFactory
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @internal
* @since 3.0.0
*/
class PopoverMenuItemFactory
{
/**
* Make a Pop*over*MenuItem (3.0 UI) from a Pop*up*MenuItem (Extensions API)
*
* @param \ApplicationPopupMenuItem $oItem
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem
*/
public static function MakeFromApplicationPopupMenuItem(ApplicationPopupMenuItem $oItem)
{
$sNamespace = 'Combodo\\iTop\\Application\\UI\\Base\\Component\\PopoverMenu\\PopoverMenuItem\\';
switch(true)
{
case $oItem instanceof URLPopupMenuItem:
$sTargetClass = 'UrlPopoverMenuItem';
break;
case $oItem instanceof JSPopupMenuItem:
$sTargetClass = 'JsPopoverMenuItem';
break;
case $oItem instanceof SeparatorPopupMenuItem:
$sTargetClass = 'SeparatorPopoverMenuItem';
break;
default:
$sTargetClass = 'PopoverMenuItem';
break;
}
$sTargetClass = $sNamespace.$sTargetClass;
return new $sTargetClass($oItem);
}
/**
* Make a PopoverMenuItem from an action data as return by {@see ApplicationPopupMenuItem::GetMenuItem()}
*
* @param string $sActionId
* @param array $aActionData
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItem
* @throws \Exception
*/
public static function MakeFromApplicationPopupMenuItemData(string $sActionId, array $aActionData)
{
$aRefactoredItem = [
'uid' => $sActionId,
'css_classes' => isset($aActionData['css_classes']) ? $aActionData['css_classes'] : [],
'on_click' => isset($aActionData['onclick']) ? $aActionData['onclick'] : '',
'target' => isset($aActionData['target']) ? $aActionData['target'] : '',
'url' => $aActionData['url'],
'label' => $aActionData['label'],
'icon_class' => isset($aActionData['icon_class']) ? $aActionData['icon_class'] : '',
'tooltip' => isset($aActionData['tooltip']) ? $aActionData['tooltip'] : '',
];
// Avoid meaningless tooltips which are identical to the label
if ($aRefactoredItem['tooltip'] == $aRefactoredItem['label']) {
$aRefactoredItem['tooltip'] = '';
}
if (!empty($aRefactoredItem['on_click'])) {
// JS
$oPopoverMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new JSPopupMenuItem(
$aRefactoredItem['uid'],
$aRefactoredItem['label'],
$aRefactoredItem['on_click'])
);
} elseif (!empty($aRefactoredItem['url'])) {
// URL
$oPopoverMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
new URLPopupMenuItem(
$aRefactoredItem['uid'],
$aRefactoredItem['label'],
$aRefactoredItem['url'],
$aRefactoredItem['target'])
);
} else {
// Separator
$oPopoverMenuItem = PopoverMenuItemFactory::MakeSeparator();
}
if (!empty($aRefactoredItem['css_classes'])) {
$oPopoverMenuItem->SetCssClasses($aRefactoredItem['css_classes']);
}
if (!empty($aRefactoredItem['icon_class'])) {
$oPopoverMenuItem->SetIconClass($aRefactoredItem['icon_class']);
}
if (!empty($aRefactoredItem['tooltip'])) {
$oPopoverMenuItem->SetTooltip($aRefactoredItem['tooltip']);
}
return $oPopoverMenuItem;
}
/**
* Make a separator item for the popover menu
*
* Note: You don't need to add separators manually if you put the items in dedicated sections of the menu
*
* @return \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem\SeparatorPopoverMenuItem
* @since 3.0.0
*/
public static function MakeSeparator()
{
return new SeparatorPopoverMenuItem(new SeparatorPopupMenuItem());
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
/**
* Class SeparatorPopoverMenuItem
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @property \SeparatorPopupMenuItem $oPopupMenuItem
* @since 3.0.0
*/
class SeparatorPopoverMenuItem extends PopoverMenuItem
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-popover-menu--item-separator';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/mode_separator';
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem;
/**
* Class UrlPopoverMenuItem
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenuItem
* @property \URLPopupMenuItem $oPopupMenuItem
* @since 3.0.0
*/
class UrlPopoverMenuItem extends PopoverMenuItem
{
// Overloaded constants
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/mode_url';
/**
* @see \URLPopupMenuItem::GetUrl()
* @return string
*/
public function GetUrl()
{
return $this->oPopupMenuItem->GetUrl();
}
/**
* @see \URLPopupMenuItem::GetTarget()
* @return string
*/
public function GetTarget()
{
return $this->oPopupMenuItem->GetTarget();
}
}