mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°4621 Fix naming inconsistencies in sources/*
This commit is contained in:
295
sources/Application/UI/Base/Component/Alert/Alert.php
Normal file
295
sources/Application/UI/Base/Component/Alert/Alert.php
Normal file
@@ -0,0 +1,295 @@
|
||||
<?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\Alert;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Alerts are the main component to give feedback to the user or communicate page specific to system wide messages.
|
||||
* Alerts are a rectangular component displaying a title and a message.
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Alert
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Alert extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-alert';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/alert/layout';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/alert/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/alert.js',
|
||||
];
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_COLOR_SCHEME_PRIMARY */
|
||||
public const ENUM_COLOR_SCHEME_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SCHEME_SECONDARY */
|
||||
public const ENUM_COLOR_SCHEME_SECONDARY = 'secondary';
|
||||
|
||||
/** @var string ENUM_COLOR_SCHEME_NEUTRAL */
|
||||
public const ENUM_COLOR_SCHEME_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_SCHEME_INFORMATION */
|
||||
public const ENUM_COLOR_SCHEME_INFORMATION = 'information';
|
||||
/** @var string ENUM_COLOR_SCHEME_SUCCESS */
|
||||
public const ENUM_COLOR_SCHEME_SUCCESS = 'success';
|
||||
/** @var string ENUM_COLOR_SCHEME_FAILURE */
|
||||
public const ENUM_COLOR_SCHEME_FAILURE = 'failure';
|
||||
/** @var string ENUM_COLOR_SCHEME_WARNING */
|
||||
public const ENUM_COLOR_SCHEME_WARNING = 'warning';
|
||||
/** @var string ENUM_COLOR_SCHEME_DANGER */
|
||||
public const ENUM_COLOR_SCHEME_DANGER = 'danger';
|
||||
|
||||
/** @var string ENUM_COLOR_SCHEME_GREY */
|
||||
public const ENUM_COLOR_SCHEME_GREY = 'grey';
|
||||
/** @var string ENUM_COLOR_SCHEME_BLUEGREY */
|
||||
public const ENUM_COLOR_SCHEME_BLUEGREY = 'blue-grey';
|
||||
/** @var string ENUM_COLOR_SCHEME_BLUE */
|
||||
public const ENUM_COLOR_SCHEME_BLUE = 'blue';
|
||||
/** @var string ENUM_COLOR_SCHEME_CYAN */
|
||||
public const ENUM_COLOR_SCHEME_CYAN = 'cyan';
|
||||
/** @var string ENUM_COLOR_SCHEME_GREEN */
|
||||
public const ENUM_COLOR_SCHEME_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_SCHEME_ORANGE */
|
||||
public const ENUM_COLOR_SCHEME_ORANGE = 'orange';
|
||||
/** @var string ENUM_COLOR_SCHEME_RED */
|
||||
public const ENUM_COLOR_SCHEME_RED = 'red';
|
||||
/** @var string ENUM_COLOR_SCHEME_PINK */
|
||||
public const ENUM_COLOR_SCHEME_PINK = 'pink';
|
||||
|
||||
/** @var string DEFAULT_COLOR_SCHEME */
|
||||
public const DEFAULT_COLOR_SCHEME = self::ENUM_COLOR_SCHEME_NEUTRAL;
|
||||
/** @var bool Default value for static::$bIsClosable */
|
||||
public const DEFAULT_IS_CLOSABLE = true;
|
||||
/** @var bool Default value for static::$bIsCollapsible */
|
||||
public const DEFAULT_IS_COLLAPSIBLE = true;
|
||||
/** @var bool Default value for static::$bIsOpenedByDefault */
|
||||
public const DEFAULT_IS_OPENED_BY_DEFAULT = true;
|
||||
|
||||
/** @var string $sTitle */
|
||||
protected $sTitle;
|
||||
/** @var string $sColor */
|
||||
protected $sColor;
|
||||
/** @var bool Whether the alert can be closed or not */
|
||||
protected $bIsClosable;
|
||||
/** @var bool Whether the alert can be collapsed or not */
|
||||
protected $bIsCollapsible;
|
||||
/** @var bool Whether the alert is opened by default or not, only works when $bIsCollapsible set to true */
|
||||
protected $bIsOpenedByDefault;
|
||||
/** @var boolean if true will store collapsible state */
|
||||
protected $bIsSaveCollapsibleStateEnabled = false;
|
||||
/** @var string localStorage key used to store collapsible state */
|
||||
protected $sSectionStateStorageKey;
|
||||
|
||||
/**
|
||||
* Alert constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent
|
||||
* @param string $sColorScheme
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sTitle = '', string $sContent = '', string $sColorScheme = self::DEFAULT_COLOR_SCHEME, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sTitle = $sTitle;
|
||||
$this->sColor = $sColorScheme;
|
||||
$this->bIsClosable = static::DEFAULT_IS_CLOSABLE;
|
||||
$this->bIsCollapsible = static::DEFAULT_IS_COLLAPSIBLE;
|
||||
$this->bIsOpenedByDefault = static::DEFAULT_IS_OPENED_BY_DEFAULT;
|
||||
if (!empty($sContent)) {
|
||||
$this->AddSubBlock(new Html($sContent));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSectionStateStorageKey
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function EnableSaveCollapsibleState(string $sSectionStateStorageKey)
|
||||
{
|
||||
$this->bIsSaveCollapsibleStateEnabled = true;
|
||||
$this->sSectionStateStorageKey = 'UI-Collapsible__'.$sSectionStateStorageKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle(): string
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle Title of the alert
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTitle(string $sTitle)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the raw HTML content, should be already sanitized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetContent(): string
|
||||
{
|
||||
return $this->sContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw HTML content, must be already sanitized.
|
||||
*
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContent(string $sContent)
|
||||
{
|
||||
$this->sContent = $sContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor(): string
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor Color of the alert (check CSS classes ibo-is-<color> for colors)
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColor(string $sColor)
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::$bIsClosable
|
||||
* @return bool
|
||||
*/
|
||||
public function IsClosable(): bool
|
||||
{
|
||||
return $this->bIsClosable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::$bIsClosable
|
||||
*
|
||||
* @param bool $bIsClosable Indicates if the user can remove the alert from the screen
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsClosable(bool $bIsClosable)
|
||||
{
|
||||
$this->bIsClosable = $bIsClosable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::$bIsCollapsible
|
||||
* @return bool
|
||||
*/
|
||||
public function IsCollapsible(): bool
|
||||
{
|
||||
if (empty($this->sTitle)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->bIsCollapsible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::$bIsCollapsible
|
||||
*
|
||||
* @param bool $bIsCollapsible Indicates if the user can collapse the alert to display only the title
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsCollapsible(bool $bIsCollapsible)
|
||||
{
|
||||
$this->bIsCollapsible = $bIsCollapsible;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsOpenedByDefault(): bool
|
||||
{
|
||||
if($this->IsCollapsible()) {
|
||||
return $this->bIsOpenedByDefault;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsOpenedByDefault Indicates if the alert is collapsed or not by default
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOpenedByDefault(bool $bIsOpenedByDefault)
|
||||
{
|
||||
$this->bIsOpenedByDefault = $bIsOpenedByDefault;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @see static::$bIsSaveCollapsibleStateEnabled
|
||||
*/
|
||||
public function IsSaveCollapsibleStateEnabled(): bool
|
||||
{
|
||||
return $this->bIsSaveCollapsibleStateEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @see static::$sSectionStateStorageKey
|
||||
*/
|
||||
public function GetSessionCollapsibleStateStorageKey(): string
|
||||
{
|
||||
return $this->sSectionStateStorageKey;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?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\Alert;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class AlertUIBlockFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Alert
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-alerts to see live examples
|
||||
*/
|
||||
class AlertUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIAlert';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Alert::class;
|
||||
|
||||
/**
|
||||
* Make a basis Alert component
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeNeutral(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_NEUTRAL, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for informational messages
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForInformation(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_INFORMATION, $sId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for successful messages
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForSuccess(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_SUCCESS, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for warning messages
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForWarning(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_WARNING, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for danger messages
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForDanger(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_DANGER, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for failure messages
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForFailure(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_FAILURE, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component with primary color scheme
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingPrimaryColor(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_PRIMARY, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component with secondary color scheme
|
||||
*
|
||||
* @param string $sTitle Title of the alert
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
* @param string|null $sId id of the html block
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingSecondaryColor(string $sTitle = '', string $sContent = '', ?string $sId = null)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SCHEME_SECONDARY, $sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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\Breadcrumbs;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class Breadcrumbs
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Breadcrumbs
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Breadcrumbs extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-breadcrumbs';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/breadcrumbs/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/breadcrumbs/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/breadcrumbs.js',
|
||||
];
|
||||
|
||||
/** @var array|null $aNewEntry */
|
||||
protected $aNewEntry;
|
||||
|
||||
/**
|
||||
* QuickCreate constructor.
|
||||
*
|
||||
* @param array|null $aNewEntry
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?array $aNewEntry = null, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->SetNewEntry($aNewEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* The new breadcrumbs entry
|
||||
*
|
||||
* @param array|null $aNewEntry
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetNewEntry(?array $aNewEntry)
|
||||
{
|
||||
$this->aNewEntry = $aNewEntry;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetNewEntry(): ?array
|
||||
{
|
||||
return $this->aNewEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetJsWidgetOptions(): array
|
||||
{
|
||||
$aJsWidgetOptions = [];
|
||||
|
||||
$iBreadCrumbMaxCount = utils::GetConfig()->Get('breadcrumb.max_count');
|
||||
if ($iBreadCrumbMaxCount > 1)
|
||||
{
|
||||
$oConfig = MetaModel::GetConfig();
|
||||
$siTopInstanceId = $oConfig->GetItopInstanceid();
|
||||
|
||||
$aJsWidgetOptions = [
|
||||
'itop_instance_id' => $siTopInstanceId,
|
||||
'max_count' => $iBreadCrumbMaxCount,
|
||||
'new_entry' => $this->GetNewEntry(),
|
||||
];
|
||||
}
|
||||
|
||||
return $aJsWidgetOptions;
|
||||
}
|
||||
}
|
||||
270
sources/Application/UI/Base/Component/Button/Button.php
Normal file
270
sources/Application/UI/Base/Component/Button/Button.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?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\Button;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Button
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Button extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-button';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/button/layout';
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_ACTION_TYPE_REGULAR */
|
||||
public const ENUM_ACTION_TYPE_REGULAR = 'regular';
|
||||
/** @var string ENUM_ACTION_TYPE_ALTERNATIVE */
|
||||
public const ENUM_ACTION_TYPE_ALTERNATIVE = 'alternative';
|
||||
/** @var string DEFAULT_ACTION_TYPE */
|
||||
public const DEFAULT_ACTION_TYPE = self::ENUM_ACTION_TYPE_REGULAR;
|
||||
|
||||
/** @var string ENUM_COLOR_SCHEME_NEUTRAL */
|
||||
public const ENUM_COLOR_SCHEME_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_SCHEME_VALIDATION */
|
||||
public const ENUM_COLOR_SCHEME_VALIDATION = 'success';
|
||||
/** @var string ENUM_COLOR_SCHEME_DESTRUCTIVE */
|
||||
public const ENUM_COLOR_SCHEME_DESTRUCTIVE = 'danger';
|
||||
/** @var string ENUM_COLOR_SCHEME_PRIMARY */
|
||||
public const ENUM_COLOR_SCHEME_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SCHEME_SECONDARY */
|
||||
public const ENUM_COLOR_SCHEME_SECONDARY = 'secondary';
|
||||
/** @var string ENUM_COLOR_SCHEME_GREEN */
|
||||
public const ENUM_COLOR_SCHEME_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_SCHEME_RED */
|
||||
public const ENUM_COLOR_SCHEME_RED = 'red';
|
||||
/** @var string ENUM_COLOR_SCHEME_CYAN */
|
||||
public const ENUM_COLOR_SCHEME_CYAN = 'cyan';
|
||||
/** @var string DEFAULT_COLOR_SCHEME */
|
||||
public const DEFAULT_COLOR_SCHEME = self::ENUM_COLOR_SCHEME_NEUTRAL;
|
||||
|
||||
/** @var string $sLabel */
|
||||
protected $sLabel;
|
||||
/** @var string $sTooltip */
|
||||
protected $sTooltip;
|
||||
/** @var string $sIconClass */
|
||||
protected $sIconClass;
|
||||
/** @var string $sActionType The type of action, a 'regular' action or a 'misc' action */
|
||||
protected $sActionType;
|
||||
/** @var string $sColor */
|
||||
protected $sColor;
|
||||
/** @var string $sJsCode */
|
||||
protected $sJsCode;
|
||||
/** @var string $sOnClickJsCode */
|
||||
protected $sOnClickJsCode;
|
||||
/** @var bool $bIsDisabled */
|
||||
protected $bIsDisabled;
|
||||
|
||||
/**
|
||||
* Button constructor.
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sId
|
||||
* @param string $sTooltip
|
||||
* @param string $sIconClass
|
||||
* @param string $sActionType
|
||||
* @param string $sColorScheme
|
||||
* @param string $sJsCode
|
||||
* @param string $sOnClickJsCode
|
||||
*/
|
||||
public function __construct(string $sLabel, string $sId = null, string $sTooltip = '', string $sIconClass = '', string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColorScheme = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '', string $sOnClickJsCode = '')
|
||||
{
|
||||
// We only use resource ID (not sanitized) on button for now, but this might be reworked back into \UIBlock if needed
|
||||
if (!is_null($sId)) {
|
||||
$this->AddDataAttribute('resource-id', $sId);
|
||||
}
|
||||
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sLabel = $sLabel;
|
||||
$this->sTooltip = $sTooltip;
|
||||
$this->sIconClass = $sIconClass;
|
||||
$this->sActionType = $sActionType;
|
||||
$this->sColor = $sColorScheme;
|
||||
$this->sJsCode = $sJsCode;
|
||||
$this->sOnClickJsCode = $sOnClickJsCode;
|
||||
$this->aDataAttributes = ['role' => 'ibo-button'];
|
||||
$this->bIsDisabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTooltip(): string
|
||||
{
|
||||
return $this->sTooltip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTooltip
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTooltip(string $sTooltip)
|
||||
{
|
||||
$this->sTooltip = $sTooltip;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconClass(): string
|
||||
{
|
||||
return $this->sIconClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClass
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIconClass(string $sIconClass)
|
||||
{
|
||||
$this->sIconClass = $sIconClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetActionType(): string
|
||||
{
|
||||
return $this->sActionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sActionType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetActionType(string $sActionType)
|
||||
{
|
||||
$this->sActionType = $sActionType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor(): string
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColor(string $sColor)
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetOnClickJsCode(): string
|
||||
{
|
||||
return $this->sOnClickJsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sOnClickJsCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOnClickJsCode(string $sOnClickJsCode)
|
||||
{
|
||||
$this->sOnClickJsCode = $sOnClickJsCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetJsCode(): string
|
||||
{
|
||||
return $this->sJsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sJsCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetJsCode(string $sJsCode)
|
||||
{
|
||||
$this->sJsCode = $sJsCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDisabled(): bool
|
||||
{
|
||||
return $this->bIsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsDisabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsDisabled(bool $bIsDisabled)
|
||||
{
|
||||
$this->bIsDisabled = $bIsDisabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
137
sources/Application/UI/Base/Component/Button/ButtonJS.php
Normal file
137
sources/Application/UI/Base/Component/Button/ButtonJS.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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\Button;
|
||||
|
||||
|
||||
/**
|
||||
* Class Button
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class ButtonJS extends Button
|
||||
{
|
||||
// Overloaded constants
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/buttonjs';
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_TYPE_BUTTON */
|
||||
public const ENUM_TYPE_BUTTON = 'button';
|
||||
/** @var string ENUM_TYPE_SUBMIT */
|
||||
public const ENUM_TYPE_SUBMIT = 'submit';
|
||||
/** @var string ENUM_TYPE_RESET */
|
||||
public const ENUM_TYPE_RESET = 'reset';
|
||||
/** @var string DEFAULT_TYPE */
|
||||
public const DEFAULT_TYPE = self::ENUM_TYPE_BUTTON;
|
||||
|
||||
/** @var string The HTML type of the button (eg. 'submit', 'button', ...) */
|
||||
protected $sType;
|
||||
/** @var string The HTML name of the button, used by forms */
|
||||
protected $sName;
|
||||
/** @var string The HTML value of the button, used by forms */
|
||||
protected $sValue;
|
||||
|
||||
/**
|
||||
* ButtonJS constructor.
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sId
|
||||
* @param string $sName
|
||||
* @param string $sValue
|
||||
* @param string $sType
|
||||
* @param string $sTooltip
|
||||
* @param string $sIconClass
|
||||
* @param string $sActionType
|
||||
* @param string $sColor
|
||||
* @param string $sJsCode
|
||||
* @param string $sOnClickJsCode
|
||||
*/
|
||||
public function __construct(
|
||||
string $sLabel, string $sId = null, string $sName = '', string $sValue = '', string $sType = self::DEFAULT_TYPE,
|
||||
string $sTooltip = '', string $sIconClass = '',
|
||||
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
|
||||
string $sOnClickJsCode = ''
|
||||
) {
|
||||
parent::__construct( $sLabel,$sId, $sTooltip, $sIconClass,
|
||||
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
|
||||
|
||||
$this->sName = $sName;
|
||||
$this->sValue = $sValue;
|
||||
$this->sType = $sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetType(): string
|
||||
{
|
||||
return $this->sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetType(string $sType)
|
||||
{
|
||||
$this->sType = $sType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetName(string $sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
<?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\Button;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Dict;
|
||||
|
||||
/**
|
||||
* Class ButtonUIBlockFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-buttons to see live examples
|
||||
*/
|
||||
class ButtonUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIButton';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Button::class;
|
||||
|
||||
//---------------------------------------------
|
||||
// Regular action buttons, mostly used in forms
|
||||
//---------------------------------------------
|
||||
|
||||
/**
|
||||
* Make a basis Button component for any purpose
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See {@link Button::$sName}
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeNeutral(string $sLabel, string $sName = null, ?string $sId = null)
|
||||
{
|
||||
$oButton = new ButtonJS($sLabel, $sId);
|
||||
$oButton->SetActionType(Button::ENUM_ACTION_TYPE_REGULAR)
|
||||
->SetColor(Button::ENUM_COLOR_SCHEME_NEUTRAL);
|
||||
|
||||
if (!empty($sName)) {
|
||||
$oButton->SetName($sName);
|
||||
}
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a primary action, should be used to tell the user this is the main choice
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForPrimaryAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_PRIMARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a secondary action, should be used to tell the user this is an second hand choice
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForSecondaryAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_SECONDARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a success action, should be used to tell the user he/she going to make a positive action/choice
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForPositiveAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_VALIDATION, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a destructive action, should be used to tell the user he/she going to make something that cannot be
|
||||
* undone easily (deleting an object) or break something (link between objects)
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForDestructiveAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// Alternative action buttons, mostly used in forms
|
||||
//-------------------------------------------------
|
||||
|
||||
/**
|
||||
* Make a basis Button component for any purpose
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeAlternativeNeutral(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for an alternative primary action, should be used to avoid the user to consider this action as the first
|
||||
* choice
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForAlternativePrimaryAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_PRIMARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for an alternative secondary action, should be used to avoid the user to focus on this
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForAlternativeSecondaryAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_SECONDARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a validation action, should be used to avoid the user to focus on this
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForAlternativeValidationAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_VALIDATION, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a destructive action, should be used to avoid the user to focus on this
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForAlternativeDestructiveAction(
|
||||
string $sLabel,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Button component for a cancel, should be used only for UI navigation, not destructive action
|
||||
*
|
||||
* @param string|null $sLabel
|
||||
* @param string|null $sName See Button::$sName
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param bool $bIsSubmit See Button::$sType
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeForCancel(
|
||||
string $sLabel = null,
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
$sLabel = $sLabel ?? Dict::S('UI:Button:Cancel');
|
||||
$sName = $sName ?? 'cancel';
|
||||
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClasses
|
||||
* @param string $sTooltipText
|
||||
* @param string|null $sName
|
||||
* @param string|null $sValue
|
||||
* @param bool $bIsSubmit
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonJS
|
||||
*/
|
||||
public static function MakeIconAction(
|
||||
string $sIconClasses,
|
||||
string $sTooltipText = '',
|
||||
string $sName = null,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
$oButton = static::MakeForAction('', Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
$oButton->SetIconClass($sIconClasses);
|
||||
$oButton->SetTooltip($sTooltipText);
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// Link buttons, mostly used outside forms, to redirect somewhere whilst keeping a button aspect
|
||||
//----------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Make a link Button component to open an URL instead of triggering a form action
|
||||
*
|
||||
* @param string $sURL
|
||||
* @param string|null $sLabel
|
||||
* @param string|null $sIconClasses
|
||||
* @param string|null $sTarget
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeLinkNeutral(
|
||||
string $sURL, ?string $sLabel = '', ?string $sIconClasses = null, ?string $sTarget = null,
|
||||
?string $sId = null
|
||||
) {
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = ButtonURL::DEFAULT_TARGET;
|
||||
}
|
||||
$sType = empty($sIconClasses) ? Button::ENUM_ACTION_TYPE_REGULAR : Button::ENUM_ACTION_TYPE_ALTERNATIVE;
|
||||
$oButton = static::MakeForLink($sLabel, $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, $sType, $sTarget, $sId);
|
||||
|
||||
if (!empty($sIconClasses)) {
|
||||
$oButton->SetIconClass($sIconClasses);
|
||||
}
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClasses
|
||||
* @param string $sTooltipText
|
||||
* @param string|null $sURL
|
||||
* @param string|null $sTarget
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonURL
|
||||
*/
|
||||
public static function MakeIconLink(
|
||||
string $sIconClasses, string $sTooltipText, ?string $sURL = '', ?string $sTarget = null,
|
||||
?string $sId = null
|
||||
) {
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = ButtonURL::DEFAULT_TARGET;
|
||||
}
|
||||
$oButton = static::MakeForLink('', $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sTarget, $sId);
|
||||
$oButton->SetIconClass($sIconClasses);
|
||||
$oButton->SetTooltip($sTooltipText);
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClasses
|
||||
* @param string $sTooltipText
|
||||
* @param string|null $sURL
|
||||
* @param string|null $sName
|
||||
* @param string|null $sTarget
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeDestructiveIconLink(
|
||||
string $sIconClasses, string $sTooltipText, ?string $sURL = null, ?string $sName = null, ?string $sTarget = null,
|
||||
?string $sId = null
|
||||
) {
|
||||
$oButton = static::MakeIconLink($sIconClasses, $sTooltipText, $sURL, $sTarget, $sId);
|
||||
$oButton->SetColor(Button::ENUM_COLOR_SCHEME_DESTRUCTIVE);
|
||||
$oButton->SetTooltip($sTooltipText);
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
//--------
|
||||
// Helpers
|
||||
//--------
|
||||
|
||||
/**
|
||||
* Internal helper
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string $sColor See Button::$sColor
|
||||
* @param string $sActionType See Button::$sActionType
|
||||
* @param string|null $sValue See Button::$sValue
|
||||
* @param string|null $sName See Button::$sValue
|
||||
* @param bool $bIsSubmit
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonJS
|
||||
* @internal
|
||||
*/
|
||||
protected static function MakeForAction(
|
||||
string $sLabel,
|
||||
string $sColor,
|
||||
string $sActionType,
|
||||
string $sValue = null,
|
||||
string $sName = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
) {
|
||||
$oButton = new ButtonJS($sLabel, $sId);
|
||||
$oButton->SetActionType($sActionType)
|
||||
->SetColor($sColor);
|
||||
|
||||
if (strlen($sValue) > 0) {
|
||||
$oButton->SetValue($sValue);
|
||||
}
|
||||
|
||||
if (strlen($sName) > 0) {
|
||||
$oButton->SetName($sName);
|
||||
}
|
||||
|
||||
// Set as submit button if necessary
|
||||
if ($bIsSubmit === true) {
|
||||
$oButton->SetType(ButtonJS::ENUM_TYPE_SUBMIT);
|
||||
}
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @param string $sURL
|
||||
* @param string $sColor See Button::$sColor
|
||||
* @param string $sActionType See Button::$sActionType
|
||||
* @param string|null $sTarget
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonURL
|
||||
*/
|
||||
protected static function MakeForLink(
|
||||
string $sLabel,
|
||||
string $sURL,
|
||||
string $sColor,
|
||||
string $sActionType,
|
||||
string $sTarget = null,
|
||||
?string $sId = null
|
||||
) {
|
||||
$oButton = new ButtonURL($sLabel, $sURL, $sId, $sTarget);
|
||||
$oButton->SetActionType($sActionType)
|
||||
->SetColor($sColor);
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
}
|
||||
115
sources/Application/UI/Base/Component/Button/ButtonURL.php
Normal file
115
sources/Application/UI/Base/Component/Button/ButtonURL.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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\Button;
|
||||
|
||||
|
||||
/**
|
||||
* Class Button
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class ButtonURL extends Button
|
||||
{
|
||||
// Overloaded constants
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/buttonurl';
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_TARGET_BLANK */
|
||||
public const ENUM_TARGET_BLANK = '_blank';
|
||||
/** @var string ENUM_TARGET_SELF */
|
||||
public const ENUM_TARGET_SELF= '_self';
|
||||
/** @var string ENUM_TARGET_PARENT */
|
||||
public const ENUM_TARGET_PARENT= '_parent';
|
||||
/** @var string ENUM_TARGET_TOP */
|
||||
public const ENUM_TARGET_TOP= '_top';
|
||||
/** @var string DEFAULT_TARGET */
|
||||
public const DEFAULT_TARGET = self::ENUM_TARGET_SELF;
|
||||
|
||||
|
||||
/** @var string */
|
||||
protected $sURL;
|
||||
/** @var string */
|
||||
protected $sTarget;
|
||||
|
||||
/**
|
||||
* ButtonURL constructor.
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string $sURL
|
||||
* @param string|null $sId
|
||||
* @param string $sTarget
|
||||
* @param string $sTooltip
|
||||
* @param string $sIconClass
|
||||
* @param string $sActionType
|
||||
* @param string $sColor
|
||||
* @param string $sJsCode
|
||||
* @param string $sOnClickJsCode
|
||||
*/
|
||||
public function __construct(
|
||||
string $sLabel, string $sURL, string $sId = null, string $sTarget = self::DEFAULT_TARGET, string $sTooltip = '', string $sIconClass = '',
|
||||
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
|
||||
string $sOnClickJsCode = '')
|
||||
{
|
||||
parent::__construct($sLabel, $sId, $sTooltip, $sIconClass,
|
||||
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
|
||||
$this->sURL = $sURL;
|
||||
$this->sTarget = $sTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetURL(): string
|
||||
{
|
||||
return $this->sURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sURL
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetURL(string $sURL)
|
||||
{
|
||||
$this->sURL = $sURL;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTarget(): string
|
||||
{
|
||||
return $this->sTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTarget
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTarget(string $sTarget)
|
||||
{
|
||||
$this->sTarget = $sTarget;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\ButtonGroup;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class ButtonGroup
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\ButtonGroup
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class ButtonGroup extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
/** @inheritDoc */
|
||||
public const BLOCK_CODE = 'ibo-button-group';
|
||||
/** @inheritDoc */
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button-group/layout';
|
||||
|
||||
/** @var \Combodo\iTop\Application\UI\Base\Component\Button\Button[] Buttons to be displayed as a group */
|
||||
protected $aButtons;
|
||||
/** @var \Combodo\iTop\Application\UI\Base\iUIBlock[] Extra blocks used in the group (eg. PopoverMenu toggled by one of the static::$aButtons) */
|
||||
protected $aExtraBlocks;
|
||||
|
||||
/**
|
||||
* Button constructor.
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string|null $sId
|
||||
* @param string $sTooltip
|
||||
* @param string $sIconClass
|
||||
* @param string $sActionType
|
||||
* @param string $sColor
|
||||
* @param string $sJsCode
|
||||
* @param string $sOnClickJsCode
|
||||
*/
|
||||
public function __construct(array $aButtons = [], ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->SetButtons($aButtons);
|
||||
$this->aExtraBlocks = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all existing buttons with $aButtons
|
||||
*
|
||||
* @param array $aButtons
|
||||
*
|
||||
* @return $this
|
||||
* @uses static::$aButtons
|
||||
*/
|
||||
public function SetButtons(array $aButtons)
|
||||
{
|
||||
$this->aButtons = [];
|
||||
$this->AddButtons($aButtons);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button[]
|
||||
* @use static::$aButtons
|
||||
*/
|
||||
public function GetButtons(): array
|
||||
{
|
||||
return $this->aButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add $oButton, replacing any button with the same ID
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\Button\Button $oButton
|
||||
*
|
||||
* @return $this
|
||||
* @uses static::$aButtons
|
||||
*/
|
||||
public function AddButton(Button $oButton)
|
||||
{
|
||||
$this->aButtons[$oButton->GetId()] = $oButton;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all $aButtons, replacing any button with the same IDs
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\Button\Button[] $aButtons
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddButtons(array $aButtons)
|
||||
{
|
||||
foreach ($aButtons as $oButton) {
|
||||
$this->AddButton($oButton);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the button with the $sId. if no button with that ID, proceed silently.
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveButton(string $sId)
|
||||
{
|
||||
if (array_key_exists($sId, $this->aButtons)) {
|
||||
unset($this->aButtons[$sId]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
* @uses static::$aExtraBlocks
|
||||
*/
|
||||
public function AddExtraBlock(iUIBlock $oBlock)
|
||||
{
|
||||
$this->aExtraBlocks[$oBlock->GetId()] = $oBlock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
|
||||
* @uses static::$aExtraBlocks
|
||||
*/
|
||||
public function GetExtraBlocks(): array
|
||||
{
|
||||
return $this->aExtraBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
return array_merge($this->GetButtons(), $this->GetExtraBlocks());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\ButtonGroup;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Button\Button;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonJS;
|
||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
|
||||
|
||||
/**
|
||||
* Class ButtonGroupUIBlockFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class ButtonGroupUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIButtonGroup';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = ButtonGroup::class;
|
||||
|
||||
/**
|
||||
* Make a button that has a primary action ($oButton) but also an options menu ($oMenu) on the side
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\Button\Button $oButton
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu $oMenu
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroup
|
||||
*/
|
||||
public static function MakeButtonWithOptionsMenu(Button $oButton, PopoverMenu $oMenu)
|
||||
{
|
||||
$oButtonGroup = new ButtonGroup();
|
||||
|
||||
// Add base button
|
||||
$oButtonGroup->AddButton($oButton);
|
||||
|
||||
// Add options menu
|
||||
$oMenuToggler = new ButtonJS('');
|
||||
$oMenuToggler->SetIconClass('fas fa-fw, fa-caret-down')
|
||||
->AddCSSClass('ibo-button-for-options-menu')
|
||||
->SetColor($oButton->GetColor())
|
||||
->SetActionType($oButton->GetActionType());
|
||||
|
||||
$oMenu->SetTogglerFromBlock($oMenuToggler);
|
||||
$oButtonGroup->AddButton($oMenuToggler)
|
||||
->AddExtraBlock($oMenu);
|
||||
|
||||
return $oButtonGroup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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\CollapsibleSection;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
|
||||
|
||||
/**
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\CollapsibleSection
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class CollapsibleSection extends UIContentBlock
|
||||
{
|
||||
use tUIContentAreas;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-collapsible-section';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/collapsible-section/layout';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/collapsible-section/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/collapsible-section.js',
|
||||
];
|
||||
|
||||
/** @var bool */
|
||||
protected $bIsOpenedByDefault = false;
|
||||
/** @var string */
|
||||
private $sTitle;
|
||||
/** @var boolean if true will store collapsible state */
|
||||
protected $bIsSaveCollapsibleStateEnabled = false;
|
||||
/** @var string localStorage key used to store collapsible state */
|
||||
protected $sSectionStateStorageKey;
|
||||
|
||||
public function __construct(string $sTitle, array $aSubBlocks = [], ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sTitle = $sTitle;
|
||||
$this->aSubBlocks = $aSubBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sSectionStateStorageKey
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function EnableSaveCollapsibleState($sSectionStateStorageKey)
|
||||
{
|
||||
$this->bIsSaveCollapsibleStateEnabled = true;
|
||||
$this->sSectionStateStorageKey = 'UI-Collapsible__'.$sSectionStateStorageKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function IsOpenedByDefault(): bool
|
||||
{
|
||||
return $this->bIsOpenedByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsOpenedByDefault
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOpenedByDefault(bool $bIsOpenedByDefault)
|
||||
{
|
||||
$this->bIsOpenedByDefault = $bIsOpenedByDefault;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetTitle(): string
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
public function IsSaveCollapsibleStateEnabled(): bool
|
||||
{
|
||||
return $this->bIsSaveCollapsibleStateEnabled;
|
||||
}
|
||||
|
||||
public function GetSessionCollapsibleStateStorageKey(): string
|
||||
{
|
||||
return $this->sSectionStateStorageKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\CollapsibleSection;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class CollapsibleSectionUIBlockFactory
|
||||
*
|
||||
* @author Pierre Goiffon <pierre.goiffon@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\CollapsibleSection
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class CollapsibleSectionUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UICollapsibleSection';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = CollapsibleSection::class;
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\CollapsibleSection\CollapsibleSection
|
||||
*/
|
||||
public static function MakeStandard(string $sTitle, ?string $sId = null)
|
||||
{
|
||||
return new CollapsibleSection($sTitle, [], $sId);
|
||||
}
|
||||
}
|
||||
201
sources/Application/UI/Base/Component/Dashlet/DashletBadge.php
Normal file
201
sources/Application/UI/Base/Component/Dashlet/DashletBadge.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
|
||||
|
||||
class DashletBadge extends DashletContainer
|
||||
{
|
||||
use tJSRefreshCallback;
|
||||
|
||||
public const BLOCK_CODE = 'ibo-dashlet-badge';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-badge';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-badge';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/dashlet/dashlet-badge.js',
|
||||
];
|
||||
|
||||
/** @var string */
|
||||
protected $sClassIconUrl;
|
||||
/** @var string */
|
||||
protected $sHyperlink;
|
||||
/** @var string */
|
||||
protected $iCount;
|
||||
/** @var string */
|
||||
protected $sClassLabel;
|
||||
|
||||
/** @var string */
|
||||
protected $sCreateActionUrl;
|
||||
/** @var string */
|
||||
protected $sCreateActionLabel;
|
||||
/** @var array */
|
||||
protected $aRefreshParams;
|
||||
|
||||
/**
|
||||
* DashletBadge constructor.
|
||||
*
|
||||
* @param string $sClassIconUrl
|
||||
* @param string $sHyperlink
|
||||
* @param string $iCount
|
||||
* @param string $sClassLabel
|
||||
* @param string|null $sCreateActionUrl
|
||||
* @param string|null $sCreateActionLabel
|
||||
* @param array $aRefreshParams
|
||||
*/
|
||||
public function __construct(
|
||||
string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, ?string $sCreateActionUrl = '',
|
||||
?string $sCreateActionLabel = '', array $aRefreshParams = []
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->sClassIconUrl = $sClassIconUrl;
|
||||
$this->sHyperlink = $sHyperlink;
|
||||
$this->iCount = $iCount;
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
$this->sCreateActionUrl = $sCreateActionUrl;
|
||||
$this->sCreateActionLabel = $sCreateActionLabel;
|
||||
$this->aRefreshParams = $aRefreshParams;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCreateActionUrl(): ?string
|
||||
{
|
||||
return $this->sCreateActionUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sCreateActionUrl
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCreateActionUrl(?string $sCreateActionUrl)
|
||||
{
|
||||
$this->sCreateActionUrl = $sCreateActionUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCreateActionLabel(): ?string
|
||||
{
|
||||
return $this->sCreateActionLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sCreateActionLabel
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCreateActionLabel(?string $sCreateActionLabel)
|
||||
{
|
||||
$this->sCreateActionLabel = $sCreateActionLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetClassIconUrl(): string
|
||||
{
|
||||
return $this->sClassIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sClassIconUrl
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetClassIconUrl(string $sClassIconUrl)
|
||||
{
|
||||
$this->sClassIconUrl = $sClassIconUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetHyperlink(): string
|
||||
{
|
||||
return $this->sHyperlink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sHyperlink
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetHyperlink(string $sHyperlink)
|
||||
{
|
||||
$this->sHyperlink = $sHyperlink;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCount(): string
|
||||
{
|
||||
return $this->iCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iCount
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCount(string $iCount)
|
||||
{
|
||||
$this->iCount = $iCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetClassLabel(): string
|
||||
{
|
||||
return $this->sClassLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sClassLabel
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetClassLabel(string $sClassLabel)
|
||||
{
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
return "$('#".$this->sId."').block();
|
||||
$.post('ajax.render.php?operation=refreshDashletCount&style=count',
|
||||
".json_encode($this->aRefreshParams).",
|
||||
function(data){
|
||||
$('#".$this->sId."').find('.ibo-dashlet-badge--action-list-count').html(data.count);
|
||||
$('#".$this->sId."').unblock();
|
||||
});
|
||||
|
||||
$('#".$this->sId."').unblock();";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
class DashletContainer extends UIContentBlock
|
||||
{
|
||||
public const BLOCK_CODE = 'ibo-dashlet';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/layouts/content-block/layout';
|
||||
|
||||
public function __construct(string $sId = null, array $aContainerClasses = [])
|
||||
{
|
||||
parent::__construct($sId, $aContainerClasses);
|
||||
|
||||
$this->AddDataAttribute('role', static::BLOCK_CODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
/**
|
||||
* Class DashletFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Dashlet
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class DashletFactory
|
||||
{
|
||||
public static function MakeForDashletBadge(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, ?string $sCreateActionUrl = '', ?string $sCreateActionLabel = '', array $aRefreshParams = []): DashletBadge
|
||||
{
|
||||
return new DashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel, $aRefreshParams);
|
||||
}
|
||||
|
||||
public static function MakeForDashletHeaderStatic(string $sTitle, string $sIconUrl, string $sId = null): DashletHeaderStatic
|
||||
{
|
||||
return new DashletHeaderStatic($sTitle, $sIconUrl, $sId);
|
||||
}
|
||||
|
||||
public static function MakeForDashletPlainText(string $sText, string $sId = null): DashletPlainText
|
||||
{
|
||||
return new DashletPlainText($sText, $sId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
/**
|
||||
* Class DashletHeaderStatic
|
||||
*
|
||||
* @internal
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Dashlet
|
||||
*/
|
||||
class DashletHeaderStatic extends DashletContainer
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-dashlet-header-static';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-header-static';
|
||||
|
||||
/** @var string */
|
||||
protected $sTitle;
|
||||
/** @var string */
|
||||
protected $sIconUrl;
|
||||
|
||||
/**
|
||||
* DashletHeaderStatic constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sIconUrl
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sTitle, string $sIconUrl, string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sTitle = $sTitle;
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle(): string
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTitle(string $sTitle)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconUrl(): string
|
||||
{
|
||||
return $this->sIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconUrl
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIconUrl(string $sIconUrl)
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
/**
|
||||
* Class DashletPlainText
|
||||
*
|
||||
* @internal
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Dashlet
|
||||
*/
|
||||
class DashletPlainText extends DashletContainer
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-dashlet-plain-text';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashlet-plain-text';
|
||||
|
||||
/** @var string */
|
||||
protected $sText;
|
||||
|
||||
/**
|
||||
* DashletPlainText constructor.
|
||||
*
|
||||
* @param string $sText
|
||||
*/
|
||||
public function __construct(string $sText, string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sText = $sText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetText(): string
|
||||
{
|
||||
return $this->sText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sText
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetText(string $sText)
|
||||
{
|
||||
$this->sText = $sText;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
253
sources/Application/UI/Base/Component/DataTable/DataTable.php
Normal file
253
sources/Application/UI/Base/Component/DataTable/DataTable.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
|
||||
|
||||
|
||||
use ApplicationContext;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
|
||||
use DataTableConfig;
|
||||
|
||||
/**
|
||||
* Class DataTable
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\DataTable
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class DataTable extends UIContentBlock
|
||||
{
|
||||
use tJSRefreshCallback;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatable';
|
||||
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/layout';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/datatable/layout';
|
||||
public const DEFAULT_JS_LIVE_TEMPLATE_REL_PATH = 'base/components/datatable/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'node_modules/datatables.net/js/jquery.dataTables.min.js',
|
||||
'node_modules/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js',
|
||||
'node_modules/datatables.net-responsive/js/dataTables.responsive.min.js',
|
||||
'node_modules/datatables.net-scroller/js/dataTables.scroller.min.js',
|
||||
'node_modules/datatables.net-select/js/dataTables.select.min.js',
|
||||
'js/field_sorter.js',
|
||||
'js/table-selectable-lines.js',
|
||||
'js/dataTables.main.js',
|
||||
'js/dataTables.settings.js',
|
||||
'js/dataTables.pipeline.js',
|
||||
];
|
||||
|
||||
protected $aOptions;//list of specific options for display datatable
|
||||
protected $sAjaxUrl;
|
||||
protected $aAjaxData;
|
||||
protected $aDisplayColumns;
|
||||
protected $aResultColumns;
|
||||
/*
|
||||
* array of data to display the first page
|
||||
*/
|
||||
protected $aInitDisplayData;
|
||||
|
||||
/**
|
||||
* Panel constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
// This block contains a form, so it has to be added later in the flow
|
||||
$this->AddDeferredBlock(new DataTableConfig($this));
|
||||
$this->aDisplayColumns = [];
|
||||
$this->aOptions = [];
|
||||
$this->aResultColumns = [];
|
||||
$this->sJsonData = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetAjaxUrl(): string
|
||||
{
|
||||
return $this->sAjaxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sAjaxUrl
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAjaxUrl(string $sAjaxUrl)
|
||||
{
|
||||
if (strlen($sAjaxUrl) > 0)
|
||||
{
|
||||
$oAppContext = new ApplicationContext();
|
||||
if(strpos ($sAjaxUrl,'?')) {
|
||||
$this->sAjaxUrl = $sAjaxUrl."&".$oAppContext->GetForLink();
|
||||
} else {
|
||||
$this->sAjaxUrl = $sAjaxUrl."?".$oAppContext->GetForLink();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sAjaxUrl = $sAjaxUrl;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetAjaxData(string $sName)
|
||||
{
|
||||
if (isset($this->aAjaxData[$sName])) {
|
||||
return $this->aAjaxData[$sName];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $aAjaxData as a JSON
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetJsonAjaxData(): string
|
||||
{
|
||||
return json_encode($this->aAjaxData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sAjaxData
|
||||
*/
|
||||
public function SetAjaxData(array $aAjaxData): void
|
||||
{
|
||||
$this->aAjaxData = $aAjaxData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetDisplayColumns(): array
|
||||
{
|
||||
return $this->aDisplayColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $aColumns
|
||||
*/
|
||||
public function SetDisplayColumns($aColumns): void
|
||||
{
|
||||
$this->aDisplayColumns = $aColumns;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetResultColumns(): array
|
||||
{
|
||||
return $this->aResultColumns;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetResultColumnsAsJson(): string
|
||||
{
|
||||
return json_encode($this->aResultColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $aColumns
|
||||
*/
|
||||
public function SetResultColumns($aColumns): void
|
||||
{
|
||||
$this->aResultColumns = $aColumns;
|
||||
}
|
||||
|
||||
public function GetOption(string $sOption)
|
||||
{
|
||||
if (isset($this->aOptions[$sOption])) {
|
||||
return $this->aOptions[$sOption];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetOptions(): array
|
||||
{
|
||||
return $this->aOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $aOptions
|
||||
*/
|
||||
public function SetOptions($aOptions): void
|
||||
{
|
||||
$this->aOptions = $aOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param mixed $sValue
|
||||
*/
|
||||
public function AddOption($sName, $sValue): void
|
||||
{
|
||||
$this->aOptions[$sName] = $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $aInitDisplayData as a JSON This is data of first page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetJsonInitDisplayData(): string
|
||||
{
|
||||
return json_encode($this->aInitDisplayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $aInitDisplayData
|
||||
* @return array
|
||||
*/
|
||||
public function GetInitDisplayData(): array
|
||||
{
|
||||
return $this->aInitDisplayData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $aData
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetInitDisplayData(array $aData)
|
||||
{
|
||||
$this->aInitDisplayData = $aData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
return "$('#".$this->sId."').DataTable().clearPipeline();
|
||||
$('#".$this->sId."').DataTable().ajax.reload(null, false);";
|
||||
}
|
||||
|
||||
public function GetDisabledSelect(): array
|
||||
{
|
||||
$aExtraParams = $this->aAjaxData['extra_params'];
|
||||
if (isset($aExtraParams['selection_enabled'])) {
|
||||
$aListDisabled = [];
|
||||
foreach ($aExtraParams['selection_enabled'] as $sKey => $bValue) {
|
||||
if ($bValue == false) {
|
||||
$aListDisabled[] = $sKey;
|
||||
}
|
||||
}
|
||||
|
||||
return $aListDisabled;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTable;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
class DataTableConfig extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatableconfig';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/config/layout';
|
||||
|
||||
/** @var DataTable */
|
||||
private $oDataTable;
|
||||
|
||||
public function __construct(DataTable $oDataTable, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->oDataTable = $oDataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\DataTable\DataTable
|
||||
*/
|
||||
private function GetDataTable()
|
||||
{
|
||||
return $this->oDataTable;
|
||||
}
|
||||
|
||||
public function GetOption(string $sOption)
|
||||
{
|
||||
return $this->GetDataTable()->GetOption($sOption);
|
||||
}
|
||||
|
||||
public function GetTableId()
|
||||
{
|
||||
return $this->GetDataTable()->GetId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
|
||||
|
||||
use appUserPreferences;
|
||||
use AttributeDashboard;
|
||||
use AttributeFriendlyName;
|
||||
use AttributeLinkedSet;
|
||||
use cmdbAbstract;
|
||||
use cmdbAbstractObject;
|
||||
use Dict;
|
||||
use Metamodel;
|
||||
use Serializable;
|
||||
|
||||
class DataTableSettings implements Serializable
|
||||
{
|
||||
public $aClassAliases;
|
||||
public $sTableId;
|
||||
public $iDefaultPageSize;
|
||||
public $aColumns;
|
||||
|
||||
|
||||
/**
|
||||
* DataTableSettings constructor.
|
||||
*
|
||||
* @param $aClassAliases
|
||||
* @param null $sTableId
|
||||
*/
|
||||
public function __construct($aClassAliases, $sTableId = null)
|
||||
{
|
||||
$this->aClassAliases = $aClassAliases;
|
||||
$this->sTableId = $sTableId;
|
||||
$this->iDefaultPageSize = 10;
|
||||
$this->aColumns = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iDefaultPageSize
|
||||
* @param $aSortOrder
|
||||
* @param $aColumns
|
||||
*/
|
||||
protected function Init($iDefaultPageSize, $aSortOrder, $aColumns)
|
||||
{
|
||||
$this->iDefaultPageSize = $iDefaultPageSize;
|
||||
$this->aColumns = $aColumns;
|
||||
$this->FixVisibleColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
// Save only the 'visible' columns
|
||||
$aColumns = array();
|
||||
foreach ($this->aClassAliases as $sAlias => $sClass) {
|
||||
$aColumns[$sAlias] = array();
|
||||
if (isset($this->aColumns[$sAlias])) {
|
||||
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
|
||||
unset($aData['label']); // Don't save the display name
|
||||
unset($aData['alias']); // Don't save the alias (redundant)
|
||||
unset($aData['code']); // Don't save the code (redundant)
|
||||
if ($aData['checked']) {
|
||||
$aColumns[$sAlias][$sAttCode] = $aData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return serialize(
|
||||
array(
|
||||
'iDefaultPageSize' => $this->iDefaultPageSize,
|
||||
'aColumns' => $aColumns,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sData
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function unserialize($sData)
|
||||
{
|
||||
$aData = unserialize($sData);
|
||||
$this->iDefaultPageSize = $aData['iDefaultPageSize'];
|
||||
$this->aColumns = $aData['aColumns'];
|
||||
foreach ($this->aClassAliases as $sAlias => $sClass) {
|
||||
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
|
||||
$aFieldData = false;
|
||||
if ($sAttCode == '_key_') {
|
||||
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, null, true /* bChecked */, $aData['sort']);
|
||||
} else if (MetaModel::isValidAttCode($sClass, $sAttCode)) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $aData['sort']);
|
||||
}
|
||||
|
||||
if ($aFieldData) {
|
||||
$this->aColumns[$sAlias][$sAttCode] = $aFieldData;
|
||||
} else {
|
||||
unset($this->aColumns[$sAlias][$sAttCode]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->FixVisibleColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $aClassAliases
|
||||
* @param $bViewLink
|
||||
* @param $aDefaultLists
|
||||
*
|
||||
* @return DataTableSettings
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public static function GetDataModelSettings($aClassAliases, $bViewLink, $aDefaultLists)
|
||||
{
|
||||
$oSettings = new DataTableSettings($aClassAliases);
|
||||
// Retrieve the class specific settings for each class/alias based on the 'list' ZList
|
||||
//TODO let the caller pass some other default settings (another Zlist, extre fields...)
|
||||
$aColumns = array();
|
||||
foreach ($aClassAliases as $sAlias => $sClass) {
|
||||
if ($aDefaultLists == null) {
|
||||
$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClass, 'list'));
|
||||
} else {
|
||||
$aList = $aDefaultLists[$sAlias];
|
||||
}
|
||||
|
||||
$aSortOrder = MetaModel::GetOrderByDefault($sClass);
|
||||
if ($bViewLink) {
|
||||
$sSort = 'none';
|
||||
if (array_key_exists('friendlyname', $aSortOrder)) {
|
||||
$sSort = $aSortOrder['friendlyname'] ? 'asc' : 'desc';
|
||||
}
|
||||
$sNormalizedFName = MetaModel::NormalizeFieldSpec($sClass, 'friendlyname');
|
||||
if (array_key_exists($sNormalizedFName, $aSortOrder)) {
|
||||
$sSort = $aSortOrder[$sNormalizedFName] ? 'asc' : 'desc';
|
||||
}
|
||||
$aColumns[$sAlias]['_key_'] = $oSettings->GetFieldData($sAlias, '_key_', null, true /* bChecked */, $sSort);
|
||||
}
|
||||
|
||||
foreach ($aList as $sAttCode) {
|
||||
$sSort = 'none';
|
||||
if (array_key_exists($sAttCode, $aSortOrder)) {
|
||||
$sSort = $aSortOrder[$sAttCode] ? 'asc' : 'desc';
|
||||
}
|
||||
$oAttDef = Metamodel::GetAttributeDef($sClass, $sAttCode);
|
||||
$aFieldData = $oSettings->GetFieldData($sAlias, $sAttCode, $oAttDef, true /* bChecked */, $sSort);
|
||||
if ($aFieldData) $aColumns[$sAlias][$sAttCode] = $aFieldData;
|
||||
}
|
||||
}
|
||||
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
|
||||
$oSettings->Init($iDefaultPageSize, $aSortOrder, $aColumns);
|
||||
return $oSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \CoreException
|
||||
*/
|
||||
protected function FixVisibleColumns()
|
||||
{
|
||||
foreach ($this->aClassAliases as $sAlias => $sClass) {
|
||||
if (!isset($this->aColumns[$sAlias])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->aColumns[$sAlias] as $sAttCode => $aData) {
|
||||
// Remove non-existent columns
|
||||
// TODO: check if the existing ones are still valid (in case their type changed)
|
||||
if (($sAttCode != '_key_') && (!MetaModel::IsValidAttCode($sClass, $sAttCode))) {
|
||||
unset($this->aColumns[$sAlias][$sAttCode]);
|
||||
}
|
||||
}
|
||||
$aList = MetaModel::ListAttributeDefs($sClass);
|
||||
|
||||
// Add the other (non visible ones), sorted in alphabetical order
|
||||
$aTempData = array();
|
||||
foreach ($aList as $sAttCode => $oAttDef) {
|
||||
if ((!array_key_exists($sAttCode, $this->aColumns[$sAlias])) && (!($oAttDef instanceof AttributeLinkedSet || $oAttDef instanceof AttributeDashboard))) {
|
||||
$aFieldData = $this->GetFieldData($sAlias, $sAttCode, $oAttDef, false /* bChecked */, 'none');
|
||||
if ($aFieldData) $aTempData[$aFieldData['label']] = $aFieldData;
|
||||
}
|
||||
}
|
||||
ksort($aTempData);
|
||||
foreach ($aTempData as $sLabel => $aFieldData) {
|
||||
$this->aColumns[$sAlias][$aFieldData['code']] = $aFieldData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $aClassAliases
|
||||
* @param null $sTableId
|
||||
* @param bool $bOnlyOnTable
|
||||
*
|
||||
* @return DataTableSettings|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
static public function GetTableSettings($aClassAliases, $sTableId = null, $bOnlyOnTable = false)
|
||||
{
|
||||
$pref = null;
|
||||
$oSettings = new DataTableSettings($aClassAliases, $sTableId);
|
||||
|
||||
if ($sTableId != null) {
|
||||
// An identified table, let's fetch its own settings (if any)
|
||||
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey($sTableId), null);
|
||||
}
|
||||
|
||||
if ($pref == null) {
|
||||
if (!$bOnlyOnTable) {
|
||||
// Try the global preferred values for this class / set of classes
|
||||
$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey(null), null);
|
||||
}
|
||||
if ($pref == null) {
|
||||
// no such settings, use the default values provided by the data model
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$oSettings->unserialize($pref);
|
||||
|
||||
return $oSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetSortOrder()
|
||||
{
|
||||
$aSortOrder = array();
|
||||
foreach ($this->aColumns as $sAlias => $aColumns) {
|
||||
foreach ($aColumns as $aColumn) {
|
||||
if ($aColumn['sort'] != 'none') {
|
||||
$sCode = ($aColumn['code'] == '_key_') ? 'friendlyname' : $aColumn['code'];
|
||||
$aSortOrder[$sCode] = ($aColumn['sort'] == 'asc'); // true for ascending, false for descending
|
||||
}
|
||||
}
|
||||
break; // TODO: For now the Set object supports only sorting on the first class of the set
|
||||
}
|
||||
return $aSortOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sTargetTableId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Save($sTargetTableId = null)
|
||||
{
|
||||
$sSaveId = is_null($sTargetTableId) ? $this->sTableId : $sTargetTableId;
|
||||
if ($sSaveId == null) return false; // Cannot save, the table is not identified, use SaveAsDefault instead
|
||||
|
||||
$sSettings = $this->serialize();
|
||||
appUserPreferences::SetPref($this->GetPrefsKey($sSaveId), $sSettings);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function SaveAsDefault()
|
||||
{
|
||||
$sSettings = $this->serialize();
|
||||
appUserPreferences::SetPref($this->GetPrefsKey(null), $sSettings);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the preferences for this particular table
|
||||
* @param $bResetAll boolean If true,the settings for all tables of the same class(es)/alias(es) are reset
|
||||
*/
|
||||
public function ResetToDefault($bResetAll)
|
||||
{
|
||||
if (($this->sTableId == null) && (!$bResetAll)) return false; // Cannot reset, the table is not identified, use force $bResetAll instead
|
||||
if ($bResetAll) {
|
||||
// Turn the key into a suitable PCRE pattern
|
||||
$sKey = $this->GetPrefsKey(null);
|
||||
$sPattern = str_replace(array('|'), array('\\|'), $sKey); // escape the | character
|
||||
$sPattern = '#^' . str_replace(array('*'), array('.*'), $sPattern) . '$#'; // Don't use slash as the delimiter since it's used in our key to delimit aliases
|
||||
appUserPreferences::UnsetPref($sPattern, true);
|
||||
} else {
|
||||
appUserPreferences::UnsetPref($this->GetPrefsKey($this->sTableId), false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sTableId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function GetPrefsKey($sTableId = null)
|
||||
{
|
||||
return static::GetAppUserPreferenceKey($this->aClassAliases, $sTableId);
|
||||
}
|
||||
|
||||
public static function GetAppUserPreferenceKey($aClassAliases, $sTableId)
|
||||
{
|
||||
if ($sTableId === null) {
|
||||
$sTableId = '*';
|
||||
}
|
||||
|
||||
$aKeys = array();
|
||||
foreach ($aClassAliases as $sAlias => $sClass) {
|
||||
$aKeys[] = $sAlias . '-' . $sClass;
|
||||
}
|
||||
return implode('/', $aKeys) . '|' . $sTableId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sAlias
|
||||
* @param $sAttCode
|
||||
* @param $oAttDef
|
||||
* @param $bChecked
|
||||
* @param $sSort
|
||||
*
|
||||
* @return array|bool
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
protected function GetFieldData($sAlias, $sAttCode, $oAttDef, $bChecked, $sSort)
|
||||
{
|
||||
$ret = false;
|
||||
if ($sAttCode == '_key_') {
|
||||
$sLabel = Dict::Format('UI:ExtKey_AsLink', MetaModel::GetName($this->aClassAliases[$sAlias]));
|
||||
$ret = array(
|
||||
'label' => $sLabel,
|
||||
'checked' => $bChecked,
|
||||
'disabled' => true,
|
||||
'alias' => $sAlias,
|
||||
'code' => $sAttCode,
|
||||
'sort' => $sSort,
|
||||
);
|
||||
} else if (!$oAttDef->IsLinkSet()) {
|
||||
$sLabel = $oAttDef->GetLabel();
|
||||
if ($oAttDef->IsExternalKey()) {
|
||||
$sLabel = Dict::Format('UI:ExtKey_AsLink', $oAttDef->GetLabel());
|
||||
} else if ($oAttDef->IsExternalField()) {
|
||||
if ($oAttDef->IsFriendlyName()) {
|
||||
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
|
||||
} else {
|
||||
$oExtAttDef = $oAttDef->GetExtAttDef();
|
||||
$sLabel = Dict::Format('UI:ExtField_AsRemoteField', $oAttDef->GetLabel(), $oExtAttDef->GetLabel());
|
||||
}
|
||||
} elseif ($oAttDef instanceof AttributeFriendlyName) {
|
||||
$sLabel = Dict::Format('UI:ExtKey_AsFriendlyName', $oAttDef->GetLabel());
|
||||
}
|
||||
$ret = array(
|
||||
'label' => $sLabel,
|
||||
'checked' => $bChecked,
|
||||
'disabled' => false,
|
||||
'alias' => $sAlias,
|
||||
'code' => $sAttCode,
|
||||
'sort' => $sSort,
|
||||
);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,993 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
|
||||
|
||||
use ApplicationException;
|
||||
use ApplicationContext;
|
||||
use appUserPreferences;
|
||||
use AttributeLinkedSet;
|
||||
use cmdbAbstractObject;
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\CollapsibleSection\CollapsibleSection;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTable\FormTable;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTableRow\FormTableRow;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\StaticTable;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\HtmlFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Title\TitleUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Controller\AjaxRenderController;
|
||||
use DBObjectSet;
|
||||
use Dict;
|
||||
use MenuBlock;
|
||||
use MetaModel;
|
||||
use UserRights;
|
||||
use utils;
|
||||
use WebPage;
|
||||
|
||||
/**
|
||||
* Class DataTableUIBlockFactory
|
||||
*
|
||||
* @author Anne-Catherine Cognet <anne-catherine.cognet@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\DataTable
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class DataTableUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIDataTable';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = DataTable::class;
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
* @param \DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\UIContentBlock
|
||||
* @throws \ApplicationException
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \MySQLException
|
||||
* @throws \MySQLHasGoneAwayException
|
||||
* @throws \OQLException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function MakeForResult(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = DataTableUIBlockFactory::MakeForRendering($sListId, $oSet, $aExtraParams);
|
||||
return self::RenderDataTable($oDataTable, 'list', $oPage, $sListId, $oSet, $aExtraParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
* @param DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\UIContentBlock
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \MySQLException
|
||||
* @throws \MySQLHasGoneAwayException
|
||||
* @throws \OQLException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function MakeForObject(WebPage $oPage, string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = DataTableUIBlockFactory::MakeForRenderingObject($sListId, $oSet, $aExtraParams);
|
||||
if ($oPage->IsPrintableVersion()) {
|
||||
$oDataTable->AddOption('printVersion', true);
|
||||
}
|
||||
|
||||
return self::RenderDataTable($oDataTable, 'listInObject', $oPage, $sListId, $oSet, $aExtraParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\DataTable\DataTable $oDataTable
|
||||
* @param string $sStyle
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
* @param \DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\UIContentBlock
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \MySQLException
|
||||
* @throws \MySQLHasGoneAwayException
|
||||
* @throws \OQLException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function RenderDataTable(DataTable $oDataTable, string $sStyle, WebPage $oPage, string $sListId, DBObjectSet $oSet, array $aExtraParams)
|
||||
{
|
||||
if (!isset($aExtraParams['menu']) || $aExtraParams['menu']) {
|
||||
$oMenuBlock = new MenuBlock($oSet->GetFilter(), $sStyle);
|
||||
$aExtraParams['refresh_action'] = $oDataTable->GetJSRefresh();
|
||||
$oBlockMenu = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $sListId);
|
||||
} else {
|
||||
$bToolkitMenu = true;
|
||||
if (isset($aExtraParams['toolkit_menu'])) {
|
||||
$bToolkitMenu = (bool)$aExtraParams['toolkit_menu'];
|
||||
}
|
||||
if (UserRights::IsPortalUser() || $oPage->IsPrintableVersion()) {
|
||||
// Portal users have a limited access to data, for now they can only see what's configured for them
|
||||
$bToolkitMenu = false;
|
||||
}
|
||||
if ($bToolkitMenu) {
|
||||
$aExtraParams['selection_mode'] = true;
|
||||
$oMenuBlock = new MenuBlock($oSet->GetFilter(), $sStyle);
|
||||
$oBlockMenu = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $sListId);
|
||||
} else {
|
||||
$oBlockMenu = new UIContentBlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($aExtraParams['surround_with_panel']) || $aExtraParams['surround_with_panel']) {
|
||||
if(!empty($oDataTable->GetInitDisplayData()) && isset($oDataTable->GetInitDisplayData()['recordsTotal'])){
|
||||
$iCount = $oDataTable->GetInitDisplayData()['recordsTotal'];
|
||||
} else {
|
||||
$iCount = $oSet->Count();
|
||||
}
|
||||
$oContainer = PanelUIBlockFactory::MakeForClass($oSet->GetClass(), '')->AddCSSClass('ibo-datatable-panel');
|
||||
if(isset($aExtraParams['panel_title'])){
|
||||
if(isset($aExtraParams['panel_title_is_html']) && $aExtraParams['panel_title_is_html'] === true) {
|
||||
$oContainer->AddTitleBlock(HtmlFactory::MakeRaw($aExtraParams['panel_title']));
|
||||
}
|
||||
else {
|
||||
$oContainer->SetTitle($aExtraParams['panel_title']);
|
||||
}
|
||||
}
|
||||
if ($oDataTable->GetOption("select_mode") == 'multiple')
|
||||
{
|
||||
$sSubTitle =Dict::Format('UI:Pagination:HeaderSelection', $iCount, '<span class="ibo-datatable--selected-count">0</span>');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSubTitle = Dict::Format('UI:Pagination:HeaderNoSelection', $iCount);
|
||||
}
|
||||
$oContainer->AddSubTitleBlock(new Html($sSubTitle));
|
||||
if(isset($aExtraParams["panel_icon"]) && strlen($aExtraParams["panel_icon"]) > 0){
|
||||
$oContainer->SetIcon($aExtraParams["panel_icon"]);
|
||||
}
|
||||
$oContainer->AddToolbarBlock($oBlockMenu);
|
||||
$oContainer->AddMainBlock($oDataTable);
|
||||
} else {
|
||||
$oContainer = new UIContentBlock();
|
||||
$oToolbar = ToolbarUIBlockFactory::MakeStandard();
|
||||
$oToolbar->AddSubBlock($oBlockMenu);
|
||||
$oContainer->AddSubBlock($oToolbar);
|
||||
$oContainer->AddSubBlock($oDataTable);
|
||||
}
|
||||
|
||||
return $oContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a basis Panel component
|
||||
*
|
||||
* @param string $sListId
|
||||
* @param \DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return DataTable
|
||||
* @throws \ApplicationException
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function MakeForRendering(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = new DataTable('datatable_'.$sListId);
|
||||
|
||||
$oAppRoot = utils::GetAbsoluteUrlAppRoot();
|
||||
|
||||
// Initialize and check the parameters
|
||||
$bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
|
||||
$sLinkageAttribute = isset($aExtraParams['link_attr']) ? $aExtraParams['link_attr'] : '';
|
||||
$iLinkedObjectId = isset($aExtraParams['object_id']) ? $aExtraParams['object_id'] : 0;
|
||||
$sTargetAttr = isset($aExtraParams['target_attr']) ? $aExtraParams['target_attr'] : '';
|
||||
if (!empty($sLinkageAttribute)) {
|
||||
if ($iLinkedObjectId == 0) {
|
||||
// if 'links' mode is requested the id of the object to link to must be specified
|
||||
throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_object_id'));
|
||||
}
|
||||
if ($sTargetAttr == '') {
|
||||
// if 'links' mode is requested the d of the object to link to must be specified
|
||||
throw new ApplicationException(Dict::S('UI:Error:MandatoryTemplateParameter_target_attr'));
|
||||
}
|
||||
}
|
||||
$bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
|
||||
$bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
|
||||
|
||||
$aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',',
|
||||
trim($aExtraParams['extra_fields'])) : array();
|
||||
$aExtraFields = array();
|
||||
foreach ($aExtraFieldsRaw as $sFieldName) {
|
||||
// Ignore attributes not of the main queried class
|
||||
if (preg_match('/^(.*)\.(.*)$/', $sFieldName, $aMatches)) {
|
||||
$sClassAlias = $aMatches[1];
|
||||
$sAttCode = $aMatches[2];
|
||||
if ($sClassAlias == $oSet->GetFilter()->GetClassAlias()) {//$oSet->GetFilter()->GetSelectedClasses()
|
||||
$aExtraFields[] = $sAttCode;
|
||||
}
|
||||
} else {
|
||||
$aExtraFields[] = $sFieldName;
|
||||
}
|
||||
}
|
||||
$sClassName = $oSet->GetFilter()->GetClass();
|
||||
$sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list';
|
||||
if ($sZListName !== false) {
|
||||
$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
|
||||
$aList = array_merge($aList, $aExtraFields);
|
||||
} else {
|
||||
$aList = $aExtraFields;
|
||||
}
|
||||
|
||||
// Filter the list to removed linked set since we are not able to display them here
|
||||
foreach ($aList as $index => $sAttCode) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
if ($oAttDef instanceof AttributeLinkedSet) {
|
||||
// Removed from the display list
|
||||
unset($aList[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($sLinkageAttribute)) {
|
||||
// The set to display is in fact a set of links between the object specified in the $sLinkageAttribute
|
||||
// and other objects...
|
||||
// The display will then group all the attributes related to the link itself:
|
||||
// | Link_attr1 | link_attr2 | ... || Object_attr1 | Object_attr2 | Object_attr3 | .. | Object_attr_n |
|
||||
$aDisplayList = array();
|
||||
$aAttDefs = MetaModel::ListAttributeDefs($sClassName);
|
||||
assert(isset($aAttDefs[$sLinkageAttribute]));
|
||||
$oAttDef = $aAttDefs[$sLinkageAttribute];
|
||||
assert($oAttDef->IsExternalKey());
|
||||
// First display all the attributes specific to the link record
|
||||
foreach ($aList as $sLinkAttCode) {
|
||||
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
|
||||
if ((!$oLinkAttDef->IsExternalKey()) && (!$oLinkAttDef->IsExternalField())) {
|
||||
$aDisplayList[] = $sLinkAttCode;
|
||||
}
|
||||
}
|
||||
// Then display all the attributes neither specific to the link record nor to the 'linkage' object (because the latter are constant)
|
||||
foreach ($aList as $sLinkAttCode) {
|
||||
$oLinkAttDef = $aAttDefs[$sLinkAttCode];
|
||||
if (($oLinkAttDef->IsExternalKey() && ($sLinkAttCode != $sLinkageAttribute))
|
||||
|| ($oLinkAttDef->IsExternalField() && ($oLinkAttDef->GetKeyAttCode() != $sLinkageAttribute))) {
|
||||
$aDisplayList[] = $sLinkAttCode;
|
||||
}
|
||||
}
|
||||
// First display all the attributes specific to the link
|
||||
// Then display all the attributes linked to the other end of the relationship
|
||||
$aList = $aDisplayList;
|
||||
}
|
||||
|
||||
$sSelectMode = '';
|
||||
if ($bSelectMode) {
|
||||
$sSelectMode = $bSingleSelectMode ? 'single' : 'multiple';
|
||||
}
|
||||
|
||||
$sClassAlias = $oSet->GetClassAlias();
|
||||
$bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
|
||||
|
||||
$sTableId = isset($aExtraParams['table_id']) ? $aExtraParams['table_id'] : null;
|
||||
$aClassAliases = array($sClassAlias => $sClassName);
|
||||
$oDefaultSettings = DataTableSettings::GetDataModelSettings($aClassAliases, $bViewLink, array($sClassAlias => $aList));
|
||||
|
||||
if ($bDisplayLimit) {
|
||||
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
|
||||
$oDefaultSettings->iDefaultPageSize = $iDefaultPageSize;
|
||||
} else {
|
||||
$oDefaultSettings->iDefaultPageSize = 0;
|
||||
}
|
||||
$oDefaultSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName);
|
||||
|
||||
$bUseCustomSettings = false;
|
||||
// Identified tables can have their own specific settings
|
||||
$oCustomSettings = DataTableSettings::GetTableSettings($aClassAliases, $sTableId);
|
||||
|
||||
if ($oCustomSettings != null) {
|
||||
// Custom settings overload the default ones
|
||||
$bUseCustomSettings = true;
|
||||
if ($oDefaultSettings->iDefaultPageSize == 0) {
|
||||
$oCustomSettings->iDefaultPageSize = 0;
|
||||
}
|
||||
} else {
|
||||
$oCustomSettings = $oDefaultSettings;
|
||||
}
|
||||
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$oSet->SetLimit($oCustomSettings->iDefaultPageSize);
|
||||
}
|
||||
|
||||
if (count($oCustomSettings->aColumns) == 0) {
|
||||
$oCustomSettings->aColumns = $oDefaultSettings->aColumns;
|
||||
}
|
||||
if (count($oCustomSettings->GetSortOrder()) == 0) {
|
||||
$oCustomSettings->aSortOrder = $oDefaultSettings->aSortOrder;
|
||||
}
|
||||
|
||||
$sIdName = isset($aExtraParams["id_for_select"]) ? $aExtraParams["id_for_select"] : "";
|
||||
// Load only the requested columns
|
||||
$aColumnsToLoad = array();
|
||||
foreach ($oCustomSettings->aColumns as $sAlias => $aColumnsInfo) {
|
||||
foreach ($aColumnsInfo as $sAttCode => $aData) {
|
||||
$bForceLoad = false;
|
||||
if ($aData['sort'] != 'none' || isset($oCustomSettings->aSortOrder[$sAttCode])) {
|
||||
$bForceLoad = true;
|
||||
}
|
||||
if ($sAttCode != '_key_') {
|
||||
if ($aData['checked'] || $bForceLoad) {
|
||||
$aColumnsToLoad[$sAlias][] = $sAttCode;
|
||||
} else {
|
||||
// See if this column is a must to load
|
||||
$sClass = $aClassAliases[$sAlias];
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
if ($oAttDef->AlwaysLoadInTables()) {
|
||||
$aColumnsToLoad[$sAlias][] = $sAttCode;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($sIdName == "") {
|
||||
$sIdName = $sAlias."/_key_";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->OptimizeColumnLoad($aColumnsToLoad);
|
||||
$aSortOrder=[];
|
||||
$aSortDatable=[];
|
||||
$aColumnDefinition = [];
|
||||
$iIndexColumn=0;
|
||||
if($sSelectMode!="") {
|
||||
$iIndexColumn++;
|
||||
}
|
||||
foreach ($aClassAliases as $sClassAlias => $sClassName) {
|
||||
foreach ($oCustomSettings->aColumns[$sClassAlias] as $sAttCode => $aData) {
|
||||
$sCode = ($aData['code'] == '_key_') ? 'friendlyname' : $aData['code'];
|
||||
if ($aData['sort'] != 'none') {
|
||||
$aSortOrder[$sAlias.'.'.$sCode] = ($aData['sort'] == 'asc'); // true for ascending, false for descending
|
||||
$aSortDatable=[$iIndexColumn,$aData['sort']];
|
||||
}
|
||||
elseif (isset($oCustomSettings->aSortOrder[$sAttCode])){
|
||||
$aSortOrder[$sAlias.'.'.$sCode] = $oCustomSettings->aSortOrder[$sAttCode]; // true for ascending, false for descending
|
||||
}
|
||||
|
||||
if ($aData['checked']) {
|
||||
if ($sAttCode == '_key_') {
|
||||
if ($bViewLink) {
|
||||
if (MetaModel::IsValidAttCode($sClassName, 'obsolescence_flag')) {
|
||||
$sDisplayFunction = "let displayField = '<span class=\"object-ref\" title=\"".$sClassAlias."::'+data+'\"><a class=\'object-ref-link\' href=\'".$oAppRoot."/pages/UI.php?operation=details&class=".$sClassName."&id='+data+'\'>'+row['".$sClassAlias."/friendlyname']+'</a></span>'; if (row['".$sClassAlias."/obsolescence_flag'].indexOf('no') == -1){displayField = '<span class=\"object-ref obsolete\" title=\"obsolete\"><a class=\'object-ref-link\' href=\'UI.php?operation=details&class=".$sClassName."&id='+data+'\'><span class=\"object-ref-icon text_decoration\"><span class=\"fas fa-eye-slash object-obsolete fa-1x fa-fw\"></span></span>'+row['".$sClassAlias."/friendlyname']+'</a></span>';} return displayField;";
|
||||
} else {
|
||||
$sDisplayFunction = "let displayField = '<span class=\"object-ref\" title=\"".$sClassAlias."::'+data+'\"><a class=\'object-ref-link\' href=\'".$oAppRoot."/pages/UI.php?operation=details&class=".$sClassName."&id='+data+'\'>'+row['".$sClassAlias."/friendlyname']+'</a></span>'; return displayField;";
|
||||
}
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $aData['label'],
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => MetaModel::GetName($sClassName),
|
||||
'render' => "return row['".$sClassAlias."/hyperlink'];",
|
||||
];
|
||||
|
||||
}
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
if ($oAttDef instanceof \AttributeCaseLog) {
|
||||
// Add JS files for display caselog
|
||||
// Dummy collapsible section created in order to get JS files
|
||||
$oCollapsibleSection = new CollapsibleSection('');
|
||||
$oDataTable->AddMultipleJsFilesRelPaths($oCollapsibleSection->GetJsFilesUrlRecursively());
|
||||
}
|
||||
$sAttDefClass = get_class($oAttDef);
|
||||
$sAttLabel = $oAttDef->GetLabel();
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $oAttDef->GetOrderByHint(),
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => $sAttDefClass,
|
||||
'attribute_label' => $sAttLabel,
|
||||
'render' => $oAttDef->GetRenderForDataTable($sClassAlias),
|
||||
];
|
||||
}
|
||||
$iIndexColumn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->SetOrderBy($aSortOrder);
|
||||
|
||||
$aOptions = [];
|
||||
if ($oDefaultSettings != null) {
|
||||
$aOptions['oDefaultSettings'] = json_encode(array('iDefaultPageSize' => $oDefaultSettings->iDefaultPageSize, 'oColumns' => $oDefaultSettings->aColumns));
|
||||
}
|
||||
$aOptions['sort'] = $aSortDatable;
|
||||
if ($sSelectMode == 'multiple') {
|
||||
$aOptions['select_mode'] = "multiple";
|
||||
} else {
|
||||
if ($sSelectMode == 'single') {
|
||||
$aOptions['select_mode'] = "single";
|
||||
}
|
||||
}
|
||||
$aOptions['selectionMode'] = $aExtraParams['selectionMode']?? 'positive';
|
||||
|
||||
if (isset($aExtraParams['cssCount'])) {
|
||||
$aOptions['sCountSelector'] = $aExtraParams['cssCount'];
|
||||
}
|
||||
|
||||
$aOptions['iPageSize'] = 10;
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$aOptions['iPageSize'] = $oCustomSettings->iDefaultPageSize;
|
||||
}
|
||||
|
||||
// Max height is only set if necessary, otherwise we want the list to occupy all the height it can depending on its pagination
|
||||
if (isset($aExtraParams['max_height'])) {
|
||||
$aOptions['sMaxHeight'] = $aExtraParams['max_height'];
|
||||
}
|
||||
|
||||
$aOptions['processing'] = true;
|
||||
$aOptions['sTableId'] = $sTableId;
|
||||
$aOptions['bUseCustomSettings'] = $bUseCustomSettings;
|
||||
$aOptions['bViewLink'] = $bViewLink;
|
||||
$aOptions['sListId'] = $sListId;
|
||||
$aOptions['oClassAliases'] = json_encode($aClassAliases);
|
||||
if (isset($aExtraParams['selected_rows']) && !empty($aExtraParams['selected_rows'])) {
|
||||
$aOptions['sSelectedRows'] = json_encode($aExtraParams['selected_rows']);
|
||||
} else {
|
||||
$aOptions['sSelectedRows'] = '[]';
|
||||
}
|
||||
$aExtraParams['table_id']=$sTableId;
|
||||
$aExtraParams['list_id']=$sListId;
|
||||
|
||||
|
||||
$oDataTable->SetOptions($aOptions);
|
||||
$oDataTable->SetAjaxUrl(utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php");
|
||||
$oDataTable->SetAjaxData([
|
||||
"operation" => 'search',
|
||||
"filter" => $oSet->GetFilter()->serialize(),
|
||||
"columns" => $oCustomSettings->aColumns,
|
||||
"extra_params" => $aExtraParams,
|
||||
"class_aliases" => $aClassAliases,
|
||||
"select_mode" => $sSelectMode,
|
||||
]);
|
||||
$oDataTable->SetDisplayColumns($aColumnDefinition);
|
||||
$oDataTable->SetResultColumns($oCustomSettings->aColumns);
|
||||
$oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams));
|
||||
|
||||
return $oDataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sListId
|
||||
* @param DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\DataTable\DataTable
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function MakeForRenderingObject(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = new DataTable('datatable_'.$sListId);
|
||||
$aList = array();
|
||||
$oAppRoot = utils::GetAbsoluteUrlAppRoot();
|
||||
|
||||
// Initialize and check the parameters
|
||||
$bViewLink = isset($aExtraParams['view_link']) ? $aExtraParams['view_link'] : true;
|
||||
// Check if there is a list of aliases to limit the display to...
|
||||
$aDisplayAliases = isset($aExtraParams['display_aliases']) ? explode(',',
|
||||
$aExtraParams['display_aliases']) : array();
|
||||
$sZListName = isset($aExtraParams['zlist']) ? ($aExtraParams['zlist']) : 'list';
|
||||
|
||||
$aExtraFieldsRaw = isset($aExtraParams['extra_fields']) ? explode(',',
|
||||
trim($aExtraParams['extra_fields'])) : array();
|
||||
$aExtraFields = array();
|
||||
$sAttCode = '';
|
||||
foreach ($aExtraFieldsRaw as $sFieldName) {
|
||||
// Ignore attributes not of the main queried class
|
||||
if (preg_match('/^(.*)\.(.*)$/', $sFieldName, $aMatches)) {
|
||||
$sClassAlias = $aMatches[1];
|
||||
$sAttCode = $aMatches[2];
|
||||
if (array_key_exists($sClassAlias, $oSet->GetSelectedClasses())) {
|
||||
$aExtraFields[$sClassAlias][] = $sAttCode;
|
||||
}
|
||||
} else {
|
||||
$aExtraFields['*'] = $sAttCode;
|
||||
}
|
||||
}
|
||||
|
||||
$aClassAliases = $oSet->GetFilter()->GetSelectedClasses();
|
||||
$aAuthorizedClasses = array();
|
||||
foreach ($aClassAliases as $sAlias => $sClassName) {
|
||||
if ((UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) &&
|
||||
((count($aDisplayAliases) == 0) || (in_array($sAlias, $aDisplayAliases)))) {
|
||||
$aAuthorizedClasses[$sAlias] = $sClassName;
|
||||
}
|
||||
}
|
||||
foreach ($aAuthorizedClasses as $sAlias => $sClassName) {
|
||||
if (array_key_exists($sAlias, $aExtraFields)) {
|
||||
$aList[$sAlias] = $aExtraFields[$sAlias];
|
||||
} else {
|
||||
$aList[$sAlias] = array();
|
||||
}
|
||||
if ($sZListName !== false) {
|
||||
$aDefaultList = MetaModel::FlattenZList(MetaModel::GetZListItems($sClassName, $sZListName));
|
||||
$aList[$sAlias] = array_merge($aDefaultList, $aList[$sAlias]);
|
||||
}
|
||||
|
||||
// Filter the list to removed linked set since we are not able to display them here
|
||||
foreach ($aList[$sAlias] as $index => $sAttCode) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
if ($oAttDef instanceof AttributeLinkedSet) {
|
||||
// Removed from the display list
|
||||
unset($aList[$sAlias][$index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($aList[$sAlias])) {
|
||||
unset($aList[$sAlias], $aAuthorizedClasses[$sAlias]);
|
||||
}
|
||||
}
|
||||
|
||||
$oDefaultSettings = DataTableSettings::GetDataModelSettings($aAuthorizedClasses, $bViewLink, $aList);
|
||||
|
||||
$bDisplayLimit = isset($aExtraParams['display_limit']) ? $aExtraParams['display_limit'] : true;
|
||||
if ($bDisplayLimit) {
|
||||
$iDefaultPageSize = appUserPreferences::GetPref('default_page_size',
|
||||
MetaModel::GetConfig()->GetMinDisplayLimit());
|
||||
$oDefaultSettings->iDefaultPageSize = $iDefaultPageSize;
|
||||
}
|
||||
|
||||
$sTableId = isset($aExtraParams['table_id']) ? $aExtraParams['table_id'] : null;
|
||||
$oDefaultSettings->aSortOrder = MetaModel::GetOrderByDefault($sClassName);
|
||||
|
||||
$bUseCustomSettings = false;
|
||||
// Identified tables can have their own specific settings
|
||||
$oCustomSettings = DataTableSettings::GetTableSettings($aClassAliases, $sTableId);
|
||||
|
||||
if ($oCustomSettings != null) {
|
||||
// Custom settings overload the default ones
|
||||
$bUseCustomSettings = true;
|
||||
if ($oDefaultSettings->iDefaultPageSize == 0) {
|
||||
$oCustomSettings->iDefaultPageSize = 0;
|
||||
}
|
||||
} else {
|
||||
$oCustomSettings = $oDefaultSettings;
|
||||
}
|
||||
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$oSet->SetLimit($oCustomSettings->iDefaultPageSize);
|
||||
}
|
||||
|
||||
$sIdName = isset($extraParams["id_for_select"]) ? $extraParams["id_for_select"] : "";
|
||||
// Load only the requested columns
|
||||
$aColumnsToLoad = array();
|
||||
foreach ($oCustomSettings->aColumns as $sAlias => $aColumnsInfo) {
|
||||
foreach ($aColumnsInfo as $sAttCode => $aData) {
|
||||
if ($sAttCode != '_key_') {
|
||||
if ($aData['checked']) {
|
||||
$aColumnsToLoad[$sAlias][] = $sAttCode;
|
||||
} else {
|
||||
// See if this column is a must to load
|
||||
$sClass = $aClassAliases[$sAlias];
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
if ($oAttDef->AlwaysLoadInTables()) {
|
||||
$aColumnsToLoad[$sAlias][] = $sAttCode;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($sIdName == "") {
|
||||
$sIdName = $sAlias."/_key_";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->OptimizeColumnLoad($aColumnsToLoad);
|
||||
|
||||
$aColumnDefinition = [];
|
||||
$iIndexColumn = 0;
|
||||
|
||||
$bSelectMode = isset($aExtraParams['selection_mode']) ? $aExtraParams['selection_mode'] == true : false;
|
||||
$bSingleSelectMode = isset($aExtraParams['selection_type']) ? ($aExtraParams['selection_type'] == 'single') : false;
|
||||
$sSelectMode = '';
|
||||
if ($bSelectMode) {
|
||||
$sSelectMode = $bSingleSelectMode ? 'single' : 'multiple';
|
||||
$iIndexColumn++;
|
||||
}
|
||||
|
||||
$aSortDatable = [];
|
||||
foreach ($aAuthorizedClasses as $sClassAlias => $sClassName) {
|
||||
if (isset($oCustomSettings->aColumns[$sClassAlias])) {
|
||||
foreach ($oCustomSettings->aColumns[$sClassAlias] as $sAttCode => $aData) {
|
||||
if ($aData['sort'] != 'none' && $aSortDatable == []) {
|
||||
$aSortDatable = [$index, $aData['sort']];
|
||||
}
|
||||
|
||||
if ($aData['checked']) {
|
||||
if ($sAttCode == '_key_') {
|
||||
if ($bViewLink) {
|
||||
$sAttLabel = MetaModel::GetName($sClassName);
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $aData['label'],
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => $sAttLabel,
|
||||
"render" => "return row['".$sClassAlias."/hyperlink'];",
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
if ($oAttDef instanceof \AttributeCaseLog) {
|
||||
// Removed from the display list
|
||||
// Dummy collapsible section created in order to get JS files
|
||||
$sCollapsibleSection = new CollapsibleSection('');
|
||||
$oDataTable->AddMultipleJsFilesRelPaths($sCollapsibleSection->GetJsFilesUrlRecursively());
|
||||
}
|
||||
$sAttDefClass = get_class($oAttDef);
|
||||
$sAttLabel = MetaModel::GetLabel($sClassName, $sAttCode);
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $oAttDef->GetOrderByHint(),
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => $sAttDefClass,
|
||||
'attribute_label' => $sAttLabel,
|
||||
"render" => $oAttDef->GetRenderForDataTable($sClassAlias),
|
||||
];
|
||||
}
|
||||
$iIndexColumn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->SetOrderBy($oCustomSettings->GetSortOrder());
|
||||
|
||||
$aOptions = [];
|
||||
if ($oDefaultSettings != null) {
|
||||
$aOptions['oDefaultSettings'] = json_encode(array('iDefaultPageSize' => $oDefaultSettings->iDefaultPageSize, 'oColumns' => $oDefaultSettings->aColumns));
|
||||
}
|
||||
|
||||
if ($sSelectMode == 'multiple') {
|
||||
$aOptions['select_mode'] = "multiple";
|
||||
} else {
|
||||
if ($sSelectMode == 'single') {
|
||||
$aOptions['select_mode'] = "single";
|
||||
}
|
||||
}
|
||||
$aOptions['selectionMode'] = $aExtraParams['selectionMode']?? 'positive';
|
||||
|
||||
$aOptions['sort'] = $aSortDatable;
|
||||
|
||||
$aOptions['iPageSize'] = 10;
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$aOptions['iPageSize'] = $oCustomSettings->iDefaultPageSize;
|
||||
}
|
||||
|
||||
// Max height is only set if necessary, otherwise we want the list to occupy all the height it can depending on its pagination
|
||||
if (isset($aExtraParams['max_height'])) {
|
||||
$aOptions['sMaxHeight'] = $aExtraParams['max_height'];
|
||||
}
|
||||
|
||||
$aOptions['sTableId'] = $sTableId;
|
||||
$aOptions['bUseCustomSettings'] = $bUseCustomSettings;
|
||||
$aOptions['bViewLink'] = $bViewLink;
|
||||
$aOptions['oClassAliases'] = json_encode($aClassAliases);
|
||||
|
||||
$oDataTable->SetOptions($aOptions);
|
||||
$oDataTable->SetAjaxUrl("ajax.render.php");
|
||||
$oDataTable->SetAjaxData([
|
||||
"operation" => 'search',
|
||||
"filter" => $oSet->GetFilter()->serialize(),
|
||||
"columns" => $oCustomSettings->aColumns,
|
||||
"extra_params" => $aExtraParams,
|
||||
"class_aliases" => $aClassAliases,
|
||||
"select_mode" => $sSelectMode,
|
||||
]);
|
||||
$oDataTable->SetDisplayColumns($aColumnDefinition);
|
||||
$oDataTable->SetResultColumns($oCustomSettings->aColumns);
|
||||
$oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams));
|
||||
|
||||
return $oDataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
* @param string $sSelectMode
|
||||
* @param string $sFilter
|
||||
* @param int $iLength
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetOptionsForRendering(array $aColumns, string $sSelectMode, string $sFilter, int $iLength, array $aClassAliases, array $aExtraParams, string $sTableId)
|
||||
{
|
||||
$oAppRoot = utils::GetAbsoluteUrlAppRoot();
|
||||
|
||||
$aOptions = [];
|
||||
$sListId = $aExtraParams["list_id"];
|
||||
$aColumnsDefinitions = [];
|
||||
$aColumnDefinition = [];
|
||||
|
||||
$sSortCol = utils::ReadParam('sort_col', '', false, 'raw_data');
|
||||
$sSortOrder = utils::ReadParam('sort_order', '', false, 'raw_data');
|
||||
$sOrder = [];
|
||||
$aJsFiles = [];
|
||||
if ($sSortCol != "") {
|
||||
$sOrder[] = [$sSortCol, $sSortOrder];
|
||||
}
|
||||
if ($sSelectMode != "") {
|
||||
$aColumnDefinition["width"] = "auto";
|
||||
$aColumnDefinition["searchable"] = false;
|
||||
$aColumnDefinition["sortable"] = false;
|
||||
if ($sSelectMode != "single") {
|
||||
$aColumnDefinition["title"] = "<span class=\"row_input\"><input type=\"checkbox\" onclick=\"checkAllDataTable('".$sTableId."',this.checked,'".$sListId."');\" class=\"checkAll\" id=\"field_".$sTableId."_check_all\" name=\"field_".$sTableId."_check_all\" title=\"".Dict::S('UI:SearchValue:CheckAll')." / ".Dict::S('UI:SearchValue:UncheckAll')."\" /></span>";
|
||||
} else {
|
||||
$aColumnDefinition["title"] = "";
|
||||
}
|
||||
$aColumnDefinition["type"] = "html";
|
||||
$aColumnDefinition["data"] = "";
|
||||
$aColumnDefinition["render"]["display"] = "";
|
||||
if ($sSelectMode != "single") {
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"checkbox\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+row.id+' /></span>');";
|
||||
}
|
||||
else {
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"radio\" class=\"selectList".$sTableId."\" name=\"selectObject[]\" value='+ row.id +' /></span>');";
|
||||
}
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " if (row.limited_access) { oCheckboxElem.html('-'); } else { oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id); }";
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]. " return oCheckboxElem.prop('outerHTML'); ";
|
||||
array_push($aColumnsDefinitions, $aColumnDefinition);
|
||||
}
|
||||
|
||||
foreach ($aColumns as $sClassAlias => $aClassColumns) {
|
||||
$sClassName=$aClassAliases[$sClassAlias];
|
||||
foreach ($aClassColumns as $sAttCode => $aData) {
|
||||
if ($aData['checked'] == "true") {
|
||||
$aColumnDefinition["width"] = "auto";
|
||||
$aColumnDefinition["searchable"] = false;
|
||||
$aColumnDefinition["sortable"] = true;
|
||||
$aColumnDefinition["defaultContent"] = "";
|
||||
$aColumnDefinition["type"] = "html";
|
||||
|
||||
if ($sAttCode == '_key_') {
|
||||
$sAttrLabel = $aData['alias'];
|
||||
$aColumnDefinition["title"] = $aData['alias'];
|
||||
$aColumnDefinition['metadata'] = [
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => $sAttrLabel,
|
||||
];
|
||||
$aColumnDefinition["data"] = $sClassAlias."/".$sAttCode;
|
||||
$aColumnDefinition["render"] = [
|
||||
"display" => "return row['".$sClassAlias."/hyperlink'];",
|
||||
"_" => $sClassAlias."/".$sAttCode,
|
||||
];
|
||||
$aColumnDefinition["createdCell"] = <<<JS
|
||||
$(td).attr('data-object-class', '$sClassName');
|
||||
$(td).attr('data-attribute-label', '$sAttrLabel');
|
||||
if (rowData["$sClassAlias/$sAttCode/raw"]) {
|
||||
$(td).attr('data-value-raw', rowData["$sClassAlias/$sAttCode/raw"]);
|
||||
}
|
||||
JS;
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
if ($oAttDef instanceof \AttributeCaseLog) {
|
||||
// Get JS files
|
||||
// Dummy collapsible section created in order to get JS files
|
||||
$oCollapsibleSection = new CollapsibleSection('');
|
||||
$aJsFiles = array_merge($aJsFiles, $oCollapsibleSection->GetJsFilesUrlRecursively());
|
||||
}
|
||||
$sAttDefClass = get_class($oAttDef);
|
||||
$sAttLabel = MetaModel::GetLabel($sClassName, $sAttCode);
|
||||
$aColumnDefinition["title"] = $sAttLabel;
|
||||
$aColumnDefinition['metadata'] = [
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => $sAttDefClass,
|
||||
'attribute_label' => $sAttLabel,
|
||||
];
|
||||
$aColumnDefinition["data"] = $sClassAlias."/".$sAttCode;
|
||||
$aColumnDefinition["render"] = [
|
||||
"display" => $oAttDef->GetRenderForDataTable($sClassAlias),
|
||||
"_" => $sClassAlias."/".$sAttCode,
|
||||
];
|
||||
$aColumnDefinition["createdCell"] = <<<JS
|
||||
$(td).attr('data-object-class', '$sClassName');
|
||||
$(td).attr('data-attribute-label', '$sAttrLabel');
|
||||
$(td).attr('data-attribute-code', '$sAttCode');
|
||||
$(td).attr('data-attribute-type', '$sAttDefClass');
|
||||
if (rowData["$sClassAlias/$sAttCode/raw"]) {
|
||||
$(td).attr('data-value-raw', rowData["$sClassAlias/$sAttCode/raw"]);
|
||||
}
|
||||
JS;
|
||||
}
|
||||
array_push($aColumnsDefinitions, $aColumnDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aOptions['select'] = ["style" => $sSelectMode, "info" => false];
|
||||
|
||||
$aOptions['pageLength'] = $iLength;
|
||||
|
||||
$sAjaxData = json_encode([
|
||||
"operation" => 'search',
|
||||
"filter" => $sFilter,
|
||||
"columns" => $aColumns,
|
||||
"extra_params" => $aExtraParams,
|
||||
"class_aliases" => $aClassAliases,
|
||||
"select_mode" => $sSelectMode,
|
||||
]);
|
||||
|
||||
$oAppContext = new ApplicationContext();
|
||||
$aOptions = array_merge($aOptions, [
|
||||
"language" =>
|
||||
[
|
||||
"processing" => Dict::Format('UI:Datatables:Language:Processing'),
|
||||
"search" => Dict::Format('UI:Datatables:Language:Search'),
|
||||
"lengthMenu" => Dict::Format('UI:Datatables:Language:LengthMenu'),
|
||||
"zeroRecords" => Dict::Format('UI:Datatables:Language:ZeroRecords'),
|
||||
"info" => Dict::Format('UI:Datatables:Language:Info'),
|
||||
"infoEmpty" => Dict::Format('UI:Datatables:Language:InfoEmpty'),
|
||||
"infoFiltered" => Dict::Format('UI:Datatables:Language:InfoFiltered'),
|
||||
"emptyTable" => Dict::Format('UI:Datatables:Language:EmptyTable'),
|
||||
"paginate" => [
|
||||
"first" => "<<",
|
||||
"previous" => "<",
|
||||
"next" => ">",
|
||||
"last" => ">>",
|
||||
],
|
||||
"aria" => [
|
||||
"sortAscending" => Dict::Format('UI:Datatables:Language:Sort:Ascending'),
|
||||
"sortDescending" => Dict::Format('UI:Datatables:Language:Sort:Descending'),
|
||||
],
|
||||
],
|
||||
"lengthMenu" => Dict::Format('Portal:Datatables:Language:DisplayLength:All'),
|
||||
"dom" => "<'ibo-datatable--toolbar'<'ibo-datatable--toolbar-left' pl><'ibo-datatable--toolbar-right' i>>t<'ibo-datatable--toolbar'<'ibo-datatable--toolbar-left' pl><'ibo-datatable--toolbar-right' i>>",
|
||||
"scrollX" => true,
|
||||
"scrollCollapse" => true,
|
||||
"ordering" => true,
|
||||
"order" => $sOrder,
|
||||
"filter" => false,
|
||||
"processing" => true,
|
||||
"serverSide" => true,
|
||||
"columns" => $aColumnsDefinitions,
|
||||
"allColumns" => $aColumns,
|
||||
'ajax' => '$.fn.dataTable.pipeline( {
|
||||
"url": "ajax.render.php?'.$oAppContext->GetForLink().'",
|
||||
"data": '.$sAjaxData.',
|
||||
"method": "post",
|
||||
"pages": 5 // number of pages to cache
|
||||
} )'
|
||||
]);
|
||||
if (count($aJsFiles) > 0) {
|
||||
foreach ($aJsFiles as $sJsFile) {
|
||||
$aUrlFiles[] = utils::GetAbsoluteUrlAppRoot().$sJsFile;
|
||||
}
|
||||
$aOptions['js_files'] = $aUrlFiles;
|
||||
$aOptions['js_files_param'] = 'itopversion';
|
||||
$aOptions['js_files_value'] = ITOP_VERSION;
|
||||
}
|
||||
return $aOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
* @param array $aColumns
|
||||
* @param array $aData
|
||||
* @param string|null $sId
|
||||
* @param array $aExtraParams
|
||||
* @param string $sFilter
|
||||
* @param array $aOptions
|
||||
* *
|
||||
* $aColumns =[
|
||||
* 'nameField1' => ['label' => labelFIeld1, 'description' => descriptionField1],
|
||||
* 'nameField2' => ['label' => labelFIeld2, 'description' => descriptionField2],
|
||||
* 'nameField3' => ['label' => labelFIeld3, 'description' => descriptionField3]];
|
||||
* $aData = [['nameField1' => valueField1, 'nameField2' => valueField2, 'nameField3' => valueField3],...]
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\UIContentBlock
|
||||
*/
|
||||
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null, array $aExtraParams = [], string $sFilter = "", array $aOptions = [])
|
||||
{
|
||||
$oBlock = new UIContentBlock();
|
||||
if ($sTitle != "") {
|
||||
$oTitle = TitleUIBlockFactory::MakeNeutral($sTitle, 3);
|
||||
$oBlock->AddSubBlock($oTitle);
|
||||
}
|
||||
$oTable = new StaticTable($sId, [], $aExtraParams);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetData($aData);
|
||||
$oTable->SetFilter($sFilter);
|
||||
$oTable->SetOptions($aOptions);
|
||||
|
||||
$oBlock->AddSubBlock($oTable);
|
||||
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRef
|
||||
* @param array $aColumns
|
||||
* @param array $aData
|
||||
* @param string $sFilter
|
||||
*
|
||||
* $aColumns =[
|
||||
* 'nameField1' => ['label' => labelFIeld1, 'description' => descriptionField1],
|
||||
* 'nameField2' => ['label' => labelFIeld2, 'description' => descriptionField2],
|
||||
* 'nameField3' => ['label' => labelFIeld3, 'description' => descriptionField3]];
|
||||
* $aData = [['nameField1' => valueField1, 'nameField2' => valueField2, 'nameField3' => valueField3],...]
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTable\FormTable
|
||||
*/
|
||||
public static function MakeForForm(string $sRef, array $aColumns, array $aData = [], string $sFilter = '')
|
||||
{
|
||||
$oTable = new FormTable("datatable_".$sRef);
|
||||
$oTable->SetRef($sRef);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetFilter($sFilter);
|
||||
|
||||
foreach ($aData as $iRowId => $aRow) {
|
||||
$oRow = new FormTableRow($sRef, $aColumns, $aRow, $iRowId);
|
||||
$oTable->AddRow($oRow);
|
||||
}
|
||||
|
||||
return $oTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function GetAllowedParams(): array
|
||||
{
|
||||
return [
|
||||
'surround_with_panel', /** bool embed table into a Panel */
|
||||
'menu', /** bool display table menu */
|
||||
'view_link', /** bool display the friendlyname column with links to the objects details */
|
||||
'link_attr', /** string link att code */
|
||||
'object_id', /** int Id of the object linked */
|
||||
'target_attr', /** string target att code of the link */
|
||||
'selection_mode', /** bool activate selection */
|
||||
'selection_type', /** string 'multiple' or 'single' */
|
||||
'extra_fields', /** string comma separated list of link att code to display ('alias.attcode')*/
|
||||
'zlist', /** string name of the zlist to display when 'extra_fields' is not set */
|
||||
'display_limit', /** bool if true pagination is used (default = true) */
|
||||
'table_id', /** string datatable id */
|
||||
'cssCount', /** string external counter (input hidden) js selector */
|
||||
'selected_rows', /** array list of Ids already selected when displaying the datatable */
|
||||
'display_aliases', /** string comma separated list of class aliases to display */
|
||||
'list_id', /** string list outer id */
|
||||
'selection_enabled', /** list of id in witch select is allowed, if not exists all lines are selectable */
|
||||
'id_for_select', /**give definition of id for select checkbox*/
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTable;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTableRow\FormTableRow;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\StaticTable;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
|
||||
/**
|
||||
* Class FormTable
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FormTable
|
||||
*/
|
||||
class FormTable extends StaticTable
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-formtable';
|
||||
public const REQUIRES_ANCESTORS_DEFAULT_JS_FILES = true;
|
||||
public const REQUIRES_ANCESTORS_DEFAULT_CSS_FILES = true;
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtable/layout';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtable/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
|
||||
/** @var iUIBlock[] */
|
||||
private $aRows;
|
||||
|
||||
public function __construct(string $sRef, array $aContainerCSSClasses = [])
|
||||
{
|
||||
parent::__construct($sRef, $aContainerCSSClasses);
|
||||
$this->SetRef($sRef);
|
||||
$this->aRows = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRef(): string
|
||||
{
|
||||
return $this->sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRef
|
||||
*/
|
||||
public function SetRef(string $sRef)
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetRows(): array
|
||||
{
|
||||
return $this->aRows;
|
||||
}
|
||||
|
||||
public function AddRow(FormTableRow $oRow)
|
||||
{
|
||||
$this->aRows[] = $oRow;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTableRow;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class FormTableRow
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FormTableRow
|
||||
*/
|
||||
class FormTableRow extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-formtablerow';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtablerow/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
/** @var int */
|
||||
private $iRowId;
|
||||
/**
|
||||
* @var array
|
||||
* [
|
||||
* 'entry name' => [
|
||||
* 'description' => tooltip,
|
||||
* 'label' => label to display,
|
||||
* 'class' => cell CSS class,
|
||||
* 'metadata' => [key => value] transformed into data-key="value"
|
||||
* ], ...
|
||||
* ]
|
||||
*/
|
||||
private $aColumns;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* [
|
||||
* 'entry name' => [
|
||||
* 'value_html' => value to display in the cell,
|
||||
* 'value_raw' => real value put into data-value-raw
|
||||
* ], ...
|
||||
* ]
|
||||
*/
|
||||
private $aData;
|
||||
|
||||
public function __construct(string $sRef, array $aColumns, array $aData, int $iRowId)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->SetRef($sRef);
|
||||
$this->SetColumns($aColumns);
|
||||
$this->SetData($aData);
|
||||
$this->SetRowId($iRowId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRef(): string
|
||||
{
|
||||
return $this->sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRef
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetRef(string $sRef)
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetColumns(): array
|
||||
{
|
||||
return $this->aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColumns(array $aColumns)
|
||||
{
|
||||
$this->aColumns = $aColumns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetData(): array
|
||||
{
|
||||
return $this->aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aData
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetData(array $aData)
|
||||
{
|
||||
$this->aData = $aData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetRowId(): int
|
||||
{
|
||||
return $this->iRowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iRowId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetRowId(int $iRowId)
|
||||
{
|
||||
$this->iRowId = $iRowId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tables with static data
|
||||
* Class StaticTable
|
||||
*/
|
||||
class StaticTable extends UIContentBlock
|
||||
{
|
||||
use tJSRefreshCallback;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatable';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/layout';
|
||||
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/datatable/static/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'node_modules/datatables.net/js/jquery.dataTables.min.js',
|
||||
'node_modules/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js',
|
||||
'node_modules/datatables.net-responsive/js/dataTables.responsive.min.js',
|
||||
'node_modules/datatables.net-scroller/js/dataTables.scroller.min.js',
|
||||
'node_modules/datatables.net-select/js/dataTables.select.min.js',
|
||||
'js/field_sorter.js',
|
||||
'js/table-selectable-lines.js',
|
||||
'js/dataTables.main.js',
|
||||
'js/dataTables.settings.js',
|
||||
'js/dataTables.pipeline.js',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array of 'entry name' => [
|
||||
* 'description' => tooltip,
|
||||
* 'label' => label to display,
|
||||
* 'class' => cell CSS class,
|
||||
* 'metadata' => [key => value] transformed into data-key="value"
|
||||
* ]
|
||||
*/
|
||||
private $aColumns;
|
||||
|
||||
/**
|
||||
* @var array of [
|
||||
* '@class' => css class of the row,
|
||||
* 'entry name' => [
|
||||
* 'value_html' => value to display in the cell,
|
||||
* 'value_raw' => real value put into data-value-raw
|
||||
* ], ...
|
||||
* ]
|
||||
*/
|
||||
private $aData;
|
||||
private $aExtraParams;
|
||||
/*@var string $sUrlForRefresh*/
|
||||
private $sFilter;
|
||||
/** @var array $aOptions
|
||||
* List of specific options for display datatable
|
||||
*/
|
||||
private $aOptions;
|
||||
|
||||
public function __construct(string $sId = null, array $aContainerCSSClasses = [], array $aExtraParams = [])
|
||||
{
|
||||
parent::__construct($sId, $aContainerCSSClasses);
|
||||
$this->aColumns = [];
|
||||
$this->aData = [];
|
||||
$this->aExtraParams = $aExtraParams;
|
||||
$this->aOptions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetColumns(): array
|
||||
{
|
||||
return $this->aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColumns(array $aColumns)
|
||||
{
|
||||
$this->aColumns = $aColumns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetData(): array
|
||||
{
|
||||
return $this->aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aData
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetData(array $aData)
|
||||
{
|
||||
$this->aData = $aData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sFilter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetFilter($sFilter)
|
||||
{
|
||||
$this->sFilter = $sFilter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
//$('#".$this->sId."').DataTable().clear().rows.add(data).draw()
|
||||
$aParams = [
|
||||
'style' => 'list',
|
||||
'filter' => $this->sFilter,
|
||||
'extra_params' => $this->aExtraParams,
|
||||
];
|
||||
|
||||
return "$.post('".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=refreshDashletList', ".json_encode($aParams).",
|
||||
function (data) {
|
||||
$('#".$this->sId."').DataTable().clear();
|
||||
$('#".$this->sId."').dataTable().fnAddData(data);
|
||||
});";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetOption(string $sOption)
|
||||
{
|
||||
if (isset($this->aOptions[$sOption])) {
|
||||
return $this->aOptions[$sOption];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetOptions(): array
|
||||
{
|
||||
return $this->aOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aOptions
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOptions($aOptions)
|
||||
{
|
||||
$this->aOptions = $aOptions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aOptions
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddOption($sName, $sValue)
|
||||
{
|
||||
$this->aOptions[$sName] = $sValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
357
sources/Application/UI/Base/Component/Field/Field.php
Normal file
357
sources/Application/UI/Base/Component/Field/Field.php
Normal file
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Field;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Field extends UIContentBlock
|
||||
{
|
||||
/** @inheritdoc */
|
||||
public const BLOCK_CODE = 'ibo-field';
|
||||
/** @inheritdoc */
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/field/layout';
|
||||
|
||||
public const ENUM_FIELD_LAYOUT_SMALL = 'small';
|
||||
public const ENUM_FIELD_LAYOUT_LARGE = 'large';
|
||||
|
||||
/** @var string */
|
||||
protected $sLayout;
|
||||
/** @var string */
|
||||
protected $sAttCode;
|
||||
/** @var string */
|
||||
protected $sAttType;
|
||||
/** @var string */
|
||||
protected $sAttLabel;
|
||||
/** @var bool */
|
||||
protected $bIsReadOnly = false;
|
||||
/** @var bool */
|
||||
protected $bIsMandatory = false;
|
||||
/** @var bool */
|
||||
protected $bMustChange = false;
|
||||
/** @var bool */
|
||||
protected $bMustPrompt = false;
|
||||
/** @var bool */
|
||||
protected $bIsSlave = false;
|
||||
/** @var string */
|
||||
protected $sValueRaw;
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var string */
|
||||
protected $sValueId;
|
||||
|
||||
/** @var string */
|
||||
protected $sComments;
|
||||
|
||||
public function __construct(string $sLabel, UIBlock $oValue = null, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sLabel = $sLabel;
|
||||
$this->sValueId = null;
|
||||
if (!is_null($oValue)) {
|
||||
$this->AddSubBlock($oValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLayout(): ?string
|
||||
{
|
||||
return $this->sLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLayout
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLayout(string $sLayout)
|
||||
{
|
||||
$this->sLayout = $sLayout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttCode(): ?string
|
||||
{
|
||||
return $this->sAttCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttCode(string $sAttCode)
|
||||
{
|
||||
$this->sAttCode = $sAttCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttType(): ?string
|
||||
{
|
||||
return $this->sAttType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttType(string $sAttType)
|
||||
{
|
||||
$this->sAttType = $sAttType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttLabel(): ?string
|
||||
{
|
||||
return $this->sAttLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAttLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttLabel(string $sAttLabel)
|
||||
{
|
||||
$this->sAttLabel = $sAttLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsReadOnly(): bool
|
||||
{
|
||||
return $this->bIsReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsReadOnly
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsReadOnly(bool $bIsReadOnly)
|
||||
{
|
||||
$this->bIsReadOnly = $bIsReadOnly;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMandatory(): bool
|
||||
{
|
||||
return $this->bIsMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMandatory
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsMandatory(bool $bIsMandatory)
|
||||
{
|
||||
$this->bIsMandatory = $bIsMandatory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMustChange(): bool
|
||||
{
|
||||
return $this->bMustChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMustChange
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustChange(bool $bIsMustChange)
|
||||
{
|
||||
$this->bMustChange = $bIsMustChange;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMustPrompt(): bool
|
||||
{
|
||||
return $this->bMustPrompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMustPrompt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustPrompt(bool $bIsMustPrompt)
|
||||
{
|
||||
$this->bMustPrompt = $bIsMustPrompt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSlave(): bool
|
||||
{
|
||||
return $this->bIsSlave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsSlave
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsSlave(bool $bIsSlave)
|
||||
{
|
||||
$this->bIsSlave = $bIsSlave;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValueRaw(): ?string
|
||||
{
|
||||
return $this->sValueRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValueRaw
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValueRaw(string $sValueRaw)
|
||||
{
|
||||
$this->sValueRaw = $sValueRaw;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\UIBlock
|
||||
*/
|
||||
public function GetValue()
|
||||
{
|
||||
return $this->oValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(UIBlock $oValue)
|
||||
{
|
||||
$this->oValue = $oValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetComments(): ?string
|
||||
{
|
||||
return $this->sComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sComments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetComments(string $sComments)
|
||||
{
|
||||
$this->sComments = $sComments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValueId(): ?string
|
||||
{
|
||||
return $this->sValueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sValueId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValueId(?string $sValueId)
|
||||
{
|
||||
$this->sValueId = $sValueId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetInputId(string $sInputId)
|
||||
{
|
||||
$this->AddDataAttribute('input-id', $sInputId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetInputType(string $sInputType)
|
||||
{
|
||||
$this->AddDataAttribute('input-type', $sInputType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Field;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class FieldUIBlockFactory
|
||||
*
|
||||
* Use it to make a "field" which is composed of a label and a value (which can be read-only or editable)
|
||||
*
|
||||
* @author Pierre Goiffon <pierre.goiffon@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class FieldUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIField';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Field::class;
|
||||
|
||||
public static function MakeFromParams($aParams)
|
||||
{
|
||||
$oValue = new Html($aParams['value']);
|
||||
$oField = new Field($aParams['label'], $oValue);
|
||||
|
||||
$aParamsMapping = [
|
||||
'layout' => 'SetLayout',
|
||||
'attcode' => 'SetAttCode',
|
||||
'atttype' => 'SetAttType',
|
||||
'attlabel' => 'SetAttLabel',
|
||||
'value_raw' => 'SetValueRaw',
|
||||
'comments' => 'SetComments',
|
||||
'input_id' => 'SetInputId',
|
||||
'input_type' => 'SetInputType',
|
||||
];
|
||||
foreach ($aParamsMapping as $sParamKey => $sFieldMethod) {
|
||||
self::UpdateFieldFromParams($oField, $sFieldMethod, $aParams, $sParamKey);
|
||||
}
|
||||
|
||||
if (isset($aParams['attflags'])) {
|
||||
$aParamsFlagsMapping = [
|
||||
OPT_ATT_HIDDEN => 'SetIsHidden',
|
||||
OPT_ATT_READONLY => 'SetIsReadOnly',
|
||||
OPT_ATT_MANDATORY => 'SetIsMandatory',
|
||||
OPT_ATT_MUSTCHANGE => 'SetMustChange',
|
||||
OPT_ATT_MUSTPROMPT => 'SetMustPrompt',
|
||||
OPT_ATT_SLAVE => 'SetIsSlave',
|
||||
];
|
||||
foreach ($aParamsFlagsMapping as $sConstant => $sFieldMethod) {
|
||||
self::UpdateFlagsFieldFromParams($oField, $sFieldMethod, $aParams['attflags'], $sConstant);
|
||||
}
|
||||
}
|
||||
|
||||
return $oField;
|
||||
}
|
||||
|
||||
private static function UpdateFieldFromParams($oField, $sMethodName, $aParams, $sKey): void
|
||||
{
|
||||
if (isset($aParams[$sKey])) {
|
||||
$oField->$sMethodName($aParams[$sKey]);
|
||||
}
|
||||
}
|
||||
|
||||
private static function UpdateFlagsFieldFromParams($oField, $sMethodName, $iParamsFlags, $iConstant): void
|
||||
{
|
||||
$oField->$sMethodName((($iParamsFlags & $iConstant) === $iConstant));
|
||||
}
|
||||
|
||||
public static function MakeFromObject(string $sLabel, UIBlock $oInput, ?string $sLayout = null)
|
||||
{
|
||||
$oField = new Field($sLabel, $oInput);
|
||||
|
||||
if (!is_null($sLayout)) {
|
||||
$oField->SetLayout($sLayout);
|
||||
}
|
||||
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeLarge(string $sLabel, string $sValueHtml = '')
|
||||
{
|
||||
$oField = new Field($sLabel, new Html($sValueHtml));
|
||||
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_LARGE);
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeSmall(string $sLabel, string $sValueHtml = '')
|
||||
{
|
||||
$oField = new Field($sLabel, new Html($sValueHtml));
|
||||
$oField->SetLayout(Field::ENUM_FIELD_LAYOUT_SMALL);
|
||||
return $oField;
|
||||
}
|
||||
|
||||
public static function MakeStandard(string $sLabel = '', string $sLayout = Field::ENUM_FIELD_LAYOUT_SMALL, ?string $sId = null)
|
||||
{
|
||||
$oField = new Field($sLabel, null, $sId);
|
||||
$oField->SetLayout($sLayout);
|
||||
return $oField;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\FieldBadge;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Class FieldBadge
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FieldBadge
|
||||
*/
|
||||
class FieldBadge extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-field-badge';
|
||||
|
||||
public function __construct(string $sId = null, array $aContainerClasses = [])
|
||||
{
|
||||
parent::__construct($sId, $aContainerClasses);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\FieldBadge;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use ormStyle;
|
||||
|
||||
/**
|
||||
* Class FieldBadgeUIBlockFactory
|
||||
*
|
||||
* @author Eric espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FieldBadge
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class FieldBadgeUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIFieldBadge';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = FieldBadge::class;
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
* @param \ormStyle|null $oStyle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\FieldBadge\FieldBadge
|
||||
*/
|
||||
public static function MakeForField(string $sValue, ?ormStyle $oStyle)
|
||||
{
|
||||
$oBadge = null;
|
||||
$sHtml = '';
|
||||
if ($oStyle) {
|
||||
$sStyleClass = $oStyle->GetStyleClass();
|
||||
$sPrimaryColor = $oStyle->GetMainColor();
|
||||
$sComplementaryColor = $oStyle->GetComplementaryColor();
|
||||
if (!is_null($sPrimaryColor) && !is_null($sComplementaryColor)) {
|
||||
$aCSSClasses = array_merge(explode(' ', $sStyleClass), ['ibo-field-badge']);
|
||||
$oBadge = new FieldBadge(null, $aCSSClasses);
|
||||
$sDecorationClasses = $oStyle->GetDecorationClasses();
|
||||
if (!is_null($sDecorationClasses) && !empty($sDecorationClasses)) {
|
||||
$sHtml .= "<span class=\"ibo-field-badge--decoration\"><i class=\"$sDecorationClasses\"></i></span>";
|
||||
}
|
||||
$sHtml .= "<span class=\"ibo-field-badge--label\">$sValue</span>";
|
||||
}
|
||||
}
|
||||
if (!$oBadge) {
|
||||
$oBadge = new FieldBadge();
|
||||
$sHtml .= "<span>$sValue</span>";
|
||||
}
|
||||
$oBadge->AddHtml($sHtml);
|
||||
return $oBadge;
|
||||
}
|
||||
}
|
||||
46
sources/Application/UI/Base/Component/FieldSet/FieldSet.php
Normal file
46
sources/Application/UI/Base/Component/FieldSet/FieldSet.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\FieldSet;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Class FieldSet
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FieldSet
|
||||
*/
|
||||
class FieldSet extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-fieldset';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/fieldset/layout';
|
||||
|
||||
/** @var string */
|
||||
protected $sLegend;
|
||||
|
||||
/**
|
||||
* FieldSet constructor.
|
||||
*
|
||||
* @param string $sLegend
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sLegend, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sLegend = $sLegend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLegend(): string
|
||||
{
|
||||
return $this->sLegend;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\FieldSet;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class FieldSetUIBlockFactory
|
||||
*
|
||||
* @author eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\FieldSet
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class FieldSetUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIFieldSet';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = FieldSet::class;
|
||||
|
||||
/**
|
||||
* @param string $sLegend
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSet A standard fieldset in which you can add UIBlocks
|
||||
*/
|
||||
public static function MakeStandard(string $sLegend, ?string $sId = null)
|
||||
{
|
||||
return new FieldSet($sLegend, $sId);
|
||||
}
|
||||
}
|
||||
68
sources/Application/UI/Base/Component/Form/Form.php
Normal file
68
sources/Application/UI/Base/Component/Form/Form.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Form;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Class Form
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Form
|
||||
*/
|
||||
class Form extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-form';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/form/layout';
|
||||
|
||||
/** @var string */
|
||||
protected $sOnSubmitJsCode;
|
||||
/** @var string */
|
||||
protected $sAction;
|
||||
|
||||
public function __construct(string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sOnSubmitJsCode = null;
|
||||
$this->sAction = null;
|
||||
}
|
||||
|
||||
public function SetOnSubmitJsCode(string $sJsCode)
|
||||
{
|
||||
$this->sOnSubmitJsCode = $sJsCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetOnSubmitJsCode(): ?string
|
||||
{
|
||||
return $this->sOnSubmitJsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAction(): ?string
|
||||
{
|
||||
return $this->sAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAction
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function SetAction(string $sAction)
|
||||
{
|
||||
$this->sAction = $sAction;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Form;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class FormUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Form
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class FormUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIForm';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Form::class;
|
||||
|
||||
/**
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Form\Form An HTML form in which you can add UIBlocks
|
||||
*/
|
||||
public static function MakeStandard(string $sId = null)
|
||||
{
|
||||
return new Form($sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?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\GlobalSearch;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use iKeyboardShortcut;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class GlobalSearch
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\GlobalSearch
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class GlobalSearch extends UIBlock implements iKeyboardShortcut
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-global-search';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/global-search/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/global-search/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/global-search.js',
|
||||
];
|
||||
|
||||
public const DEFAULT_ENDPOINT_REL_URL = 'pages/UI.php';
|
||||
|
||||
/** @var string $sEndpoint Absolute endpoint URL of the search form */
|
||||
protected $sEndpoint;
|
||||
/** @var string Query currently in the input */
|
||||
protected $sQuery;
|
||||
/** @var array $aLastQueries */
|
||||
protected $aLastQueries;
|
||||
/** @var bool $bShowHistory Whether or not to display the elements in the history */
|
||||
protected $bShowHistory;
|
||||
/** @var int $iMaxHistoryResults Max. number of elements in the history */
|
||||
protected $iMaxHistoryResults;
|
||||
|
||||
/**
|
||||
* GlobalSearch constructor.
|
||||
*
|
||||
* @param array $aLastQueries
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(array $aLastQueries = [], ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->SetEndpoint(static::DEFAULT_ENDPOINT_REL_URL);
|
||||
$this->SetQuery('');
|
||||
$this->SetLastQueries($aLastQueries);
|
||||
$this->bShowHistory = (bool)MetaModel::GetConfig()->Get('global_search.show_history');
|
||||
$this->iMaxHistoryResults = (int)MetaModel::GetConfig()->Get('global_search.max_history_results');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the search form endpoint URL.
|
||||
* If $bRelativeUrl is true, then $sEndpoint will be complete with the app_root_url
|
||||
*
|
||||
* @param string $sEndpoint URL to the endpoint
|
||||
* @param bool $bRelativeUrl Whether or not the $sEndpoint parameter is a relative URL
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function SetEndpoint(string $sEndpoint, bool $bRelativeUrl = true)
|
||||
{
|
||||
$this->sEndpoint = (($bRelativeUrl) ? utils::GetAbsoluteUrlAppRoot() : '').$sEndpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute URL of the search form
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetEndpoint(): string
|
||||
{
|
||||
return $this->sEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses $sQuery
|
||||
* @param string $sQuery
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetQuery(string $sQuery)
|
||||
{
|
||||
$this->sQuery = $sQuery;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses $sQuery
|
||||
* @return string
|
||||
*/
|
||||
public function GetQuery(): string
|
||||
{
|
||||
return $this->sQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses $sQuery
|
||||
* @return bool
|
||||
*/
|
||||
public function HasQuery(): bool
|
||||
{
|
||||
return !empty($this->sQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all the last queries at once
|
||||
*
|
||||
* @param array $aLastQueries
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLastQueries(array $aLastQueries)
|
||||
{
|
||||
$this->aLastQueries = $aLastQueries;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last queries (query itself, label as HTML)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetLastQueries(): array
|
||||
{
|
||||
return $this->aLastQueries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $bShowHistory
|
||||
* @return bool
|
||||
*/
|
||||
public function GetShowHistory(): bool
|
||||
{
|
||||
return $this->bShowHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxHistoryResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxHistoryResults(): int
|
||||
{
|
||||
return $this->iMaxHistoryResults;
|
||||
}
|
||||
|
||||
public static function GetShortcutKeys(): array
|
||||
{
|
||||
return [['id' => 'ibo-open-global-search', 'label' => 'UI:Component:GlobalSearch:KeyboardShortcut:OpenDrawer', 'key' => 'g', 'event' => 'open_drawer']];
|
||||
}
|
||||
|
||||
public static function GetShortcutTriggeredElementSelector(): string
|
||||
{
|
||||
return "[data-role='".static::BLOCK_CODE."']";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\GlobalSearch;
|
||||
|
||||
|
||||
/**
|
||||
* Class GlobalSearchFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\GlobalSearch
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class GlobalSearchFactory
|
||||
{
|
||||
/**
|
||||
* Make a GlobalSearch component with the history entries from the current user
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\GlobalSearch\GlobalSearch
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function MakeFromUserHistory()
|
||||
{
|
||||
$aLastClasses = GlobalSearchHelper::GetLastQueries();
|
||||
|
||||
return new GlobalSearch($aLastClasses, GlobalSearch::BLOCK_CODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?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\GlobalSearch;
|
||||
|
||||
|
||||
use appUserPreferences;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class GlobalSearchHelper
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\GlobalSearch
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class GlobalSearchHelper
|
||||
{
|
||||
/** @var string */
|
||||
public const USER_PREF_CODE = 'global_search_history';
|
||||
|
||||
/**
|
||||
* Add $sQuery to the history. History is limited to the static::MAX_HISTORY_SIZE last queries.
|
||||
*
|
||||
* @param string $sQuery Raw search query
|
||||
* @param string|null $sIconRelUrl Relative URL of the icon
|
||||
* @param string|null $sLabelAsHtml Alternate label for the query (eg. more human readable or with highlights), MUST be html entities
|
||||
* otherwise there can be XSS flaws
|
||||
*
|
||||
* @return void
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
* @noinspection PhpUnused Called by /pages/UI.php and extensions overloading the global search
|
||||
*/
|
||||
public static function AddQueryToHistory(string $sQuery, ?string $sIconRelUrl = null, ?string $sLabelAsHtml = null)
|
||||
{
|
||||
$aNewEntry = [
|
||||
'query' => $sQuery,
|
||||
];
|
||||
|
||||
// Set icon only when necessary
|
||||
if (!empty($sIconRelUrl))
|
||||
{
|
||||
//Ensure URL is relative to limit space in the preferences and avoid broken links in case app_root_url changes
|
||||
$aNewEntry['icon_url'] = str_replace(utils::GetAbsoluteUrlAppRoot(), '', $sIconRelUrl);
|
||||
}
|
||||
|
||||
// Set label only when necessary to avoid unnecessary space filling of the preferences in the DB
|
||||
if(!empty($sLabelAsHtml))
|
||||
{
|
||||
$aNewEntry['label_html'] = $sLabelAsHtml;
|
||||
}
|
||||
|
||||
/** @var array $aHistoryEntries */
|
||||
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
|
||||
|
||||
// Remove same query from history to avoid duplicates
|
||||
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
|
||||
{
|
||||
if($aHistoryEntries[$iIdx]['query'] === $sQuery)
|
||||
{
|
||||
unset($aHistoryEntries[$iIdx]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new entry
|
||||
array_unshift($aHistoryEntries, $aNewEntry);
|
||||
|
||||
// Truncate history
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of past queries, including the query itself and its HTML label
|
||||
*
|
||||
* @return array
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function GetLastQueries()
|
||||
{
|
||||
/** @var array $aHistoryEntries */
|
||||
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++){
|
||||
$sRawQuery = $aHistoryEntries[$iIdx]['query'];
|
||||
|
||||
// Make icon URL absolute
|
||||
if(isset($aHistoryEntries[$iIdx]['icon_url'])){
|
||||
$aHistoryEntries[$iIdx]['icon_url'] = utils::GetAbsoluteUrlAppRoot().$aHistoryEntries[$iIdx]['icon_url'];
|
||||
}
|
||||
|
||||
// Add HTML label if missing
|
||||
if(!isset($aHistoryEntries[$iIdx]['label_html'])) {
|
||||
$aHistoryEntries[$iIdx]['label_html'] = utils::EscapeHtml($sRawQuery);
|
||||
}
|
||||
|
||||
// Add URL
|
||||
if(!isset($aHistoryEntries[$iIdx]['target_url'])){
|
||||
$aHistoryEntries[$iIdx]['target_url'] = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=full_text&text='.urlencode($sRawQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return $aHistoryEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate $aHistoryEntries to 'global_search.max_history_results' entries
|
||||
*
|
||||
* @param array $aHistoryEntries
|
||||
*/
|
||||
protected static function TruncateHistory(array &$aHistoryEntries): void
|
||||
{
|
||||
$iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('global_search.max_history_results');
|
||||
if(count($aHistoryEntries) > $iMaxHistoryResults)
|
||||
{
|
||||
$aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
90
sources/Application/UI/Base/Component/Html/Html.php
Normal file
90
sources/Application/UI/Base/Component/Html/Html.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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\Html;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Html
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Html
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Html extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-html';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/html/layout';
|
||||
|
||||
/** @var string $sHtml The raw HTML, must be already sanitized */
|
||||
protected $sHtml;
|
||||
|
||||
/**
|
||||
* Html constructor.
|
||||
*
|
||||
* @param string $sHtml
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sHtml = '', ?string $sId = null)
|
||||
{
|
||||
$this->sHtml = $sHtml;
|
||||
parent::__construct($sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the raw HTML, should have been sanitized
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetHtml(): string
|
||||
{
|
||||
return $this->sHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw HTML, must be already sanitized
|
||||
*
|
||||
* @param string $sHtml
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetHtml(string $sHtml)
|
||||
{
|
||||
$this->sHtml = $sHtml;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add HTML, must be already sanitized
|
||||
*
|
||||
* @param string $sHtml
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddHtml(string $sHtml)
|
||||
{
|
||||
$this->sHtml .= $sHtml;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
65
sources/Application/UI/Base/Component/Html/HtmlFactory.php
Normal file
65
sources/Application/UI/Base/Component/Html/HtmlFactory.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Html;
|
||||
|
||||
|
||||
/**
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Html
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class HtmlFactory
|
||||
{
|
||||
/**
|
||||
* Make an HTML block without any extra markup.
|
||||
* The only purpose of this method is to enable devs to use only factories without instantiating base class directly.
|
||||
*
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Html\Html
|
||||
*/
|
||||
public static function MakeRaw(string $sContent): Html
|
||||
{
|
||||
return new Html($sContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an HTML paragraph with $sContent inside
|
||||
*
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Html\Html
|
||||
*/
|
||||
public static function MakeParagraph(string $sContent): Html
|
||||
{
|
||||
return new Html('<p>'.$sContent.'</p>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a container for contents having multiple HTML tags, for which we want to preserve style and don't apply minireset
|
||||
*
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Html\Html
|
||||
*/
|
||||
public static function MakeHtmlContent(string $sContent): Html
|
||||
{
|
||||
return new Html('<div class="ibo-is-html-content">'.$sContent.'</div>');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
abstract class AbstractInput extends UIBlock
|
||||
{
|
||||
public const BLOCK_CODE = 'ibo-input';
|
||||
/** @var string */
|
||||
protected $sName;
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
/**@var string */
|
||||
protected $sPlaceholder;
|
||||
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetName(string $sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetValue(): ?string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(?string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetPlaceholder(): ?string
|
||||
{
|
||||
return $this->sPlaceholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sPlaceholder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetPlaceholder(string $sPlaceholder)
|
||||
{
|
||||
$this->sPlaceholder = $sPlaceholder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\FileSelect;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use Dict;
|
||||
|
||||
class FileSelect extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-input-file-select';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/file-select/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/input/file-select/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sName;
|
||||
/** @var string */
|
||||
private $sFileName;
|
||||
/** @var string */
|
||||
private $sButtonText;
|
||||
/** @var bool */
|
||||
private $bShowFilename;
|
||||
|
||||
public function __construct(string $sName, string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sName = $sName;
|
||||
$this->sFileName = Dict::S('UI:InputFile:NoFileSelected');
|
||||
$this->sButtonText = Dict::S('UI:InputFile:SelectFile');
|
||||
$this->bShowFilename = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetFileName(): string
|
||||
{
|
||||
return $this->sFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sFileName
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetFileName($sFileName)
|
||||
{
|
||||
$this->sFileName = $sFileName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetButtonText(): string
|
||||
{
|
||||
return $this->sButtonText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sButtonText
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetButtonText(string $sButtonText)
|
||||
{
|
||||
$this->sButtonText = $sButtonText;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bShowFilename
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetShowFilename(bool $bShowFilename)
|
||||
{
|
||||
$this->bShowFilename = $bShowFilename;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function GetShowFilename(): bool
|
||||
{
|
||||
return $this->bShowFilename;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\FileSelect;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class FileSelectUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input\FileSelect
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class FileSelectUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIFileSelect';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = FileSelect::class;
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Input\FileSelect\FileSelect A styled file input selector
|
||||
*/
|
||||
public static function MakeStandard(string $sName, string $sId = null)
|
||||
{
|
||||
return new FileSelect($sName, $sId);
|
||||
}
|
||||
}
|
||||
131
sources/Application/UI/Base/Component/Input/Input.php
Normal file
131
sources/Application/UI/Base/Component/Input/Input.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
/**
|
||||
* Class Input
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
class Input extends AbstractInput
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-input';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/layout';
|
||||
|
||||
public const INPUT_HIDDEN = 'hidden';
|
||||
|
||||
protected $bIsChecked = false;
|
||||
|
||||
protected $bIsDisabled = false;
|
||||
protected $bIsReadonly = false;
|
||||
|
||||
protected $sLabel = null;
|
||||
|
||||
/** @var string */
|
||||
protected $sType;
|
||||
|
||||
public function GetType(): string
|
||||
{
|
||||
return $this->sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetType(string $sType)
|
||||
{
|
||||
$this->sType = $sType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bChecked
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsChecked($bIsChecked)
|
||||
{
|
||||
$this->bIsChecked = $bIsChecked;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsChecked(): bool
|
||||
{
|
||||
return $this->bIsChecked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDisabled(): bool
|
||||
{
|
||||
return $this->bIsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsDisabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsDisabled(bool $bIsDisabled)
|
||||
{
|
||||
$this->bIsDisabled = $bIsDisabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsReadonly(): bool
|
||||
{
|
||||
return $this->bIsReadonly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsReadonly
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsReadonly(bool $bIsReadonly)
|
||||
{
|
||||
$this->bIsReadonly = $bIsReadonly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetLabel(): ?string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel($sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function HasLabel(): bool
|
||||
{
|
||||
return !is_null($this->sLabel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Field\Field;
|
||||
|
||||
/**
|
||||
* Class InputUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class InputUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIInput';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Input::class;
|
||||
|
||||
public static function MakeForHidden(string $sName, string $sValue, ?string $sId = null)
|
||||
{
|
||||
$oInput = new Input($sId);
|
||||
|
||||
$oInput->SetType(Input::INPUT_HIDDEN)
|
||||
->SetName($sName)
|
||||
->SetValue($sValue);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
public static function MakeStandard(string $sType, string $sName, string $sValue, ?string $sId = null)
|
||||
{
|
||||
$oInput = new Input($sId);
|
||||
|
||||
$oInput->SetType($sType)
|
||||
->SetName($sName)
|
||||
->SetValue($sValue);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Field component that is better adapter when dealing with a standard iTop form
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string $sInputName
|
||||
* @param string|null $sInputValue
|
||||
* @param string|null $sInputId
|
||||
* @param string $sInputType
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Input\InputWithLabel
|
||||
*/
|
||||
public static function MakeForInputWithLabel(
|
||||
string $sLabel, string $sInputName, ?string $sInputValue = null,
|
||||
?string $sInputId = null, string $sInputType = 'type'
|
||||
)
|
||||
{
|
||||
$oInput = new Input($sInputId);
|
||||
$oInput->SetType($sInputType);
|
||||
$oInput->SetValue($sInputValue);
|
||||
|
||||
return static::MakeInputWithLabel($sInputName, $sLabel, $oInput, $sInputId);
|
||||
}
|
||||
|
||||
private static function MakeInputWithLabel(string $sName, string $sLabel, Input $oInput, ?string $sId = null)
|
||||
{
|
||||
$oInput->SetName($sName);
|
||||
|
||||
if (is_null($sId)) {
|
||||
$sId = $oInput->GetId();
|
||||
}
|
||||
|
||||
return new InputWithLabel($sLabel, $oInput, $sId);
|
||||
}
|
||||
}
|
||||
105
sources/Application/UI/Base/Component/Input/InputWithLabel.php
Normal file
105
sources/Application/UI/Base/Component/Input/InputWithLabel.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* You might want to use a {@link \Combodo\iTop\Application\UI\Base\Component\Field\Field} component instead...
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
class InputWithLabel extends UIBlock
|
||||
{
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/inputwithlabel';
|
||||
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var \Combodo\iTop\Application\UI\Base\UIBlock */
|
||||
protected $oInput;
|
||||
/** @var bool Label before input ? */
|
||||
protected $bBeforeInput;
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sLabel, UIBlock $oInput, ?string $sId)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sLabel = $sLabel;
|
||||
$this->oInput = $oInput;
|
||||
$this->bBeforeInput = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UIBlock
|
||||
*/
|
||||
public function GetInput()
|
||||
{
|
||||
return $this->oInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\UIBlock $oInput
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetInput(UIBlock $oInput)
|
||||
{
|
||||
$this->oInput = $oInput;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bBeforeInput
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetBeforeInput(bool $bBeforeInput)
|
||||
{
|
||||
$this->bBeforeInput = $bBeforeInput;
|
||||
if ($bBeforeInput) {
|
||||
$this->oInput->AddCSSClass('ibo-input--label-left');
|
||||
} else {
|
||||
$this->oInput->AddCSSClass('ibo-input--label-right');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsLabelBefore(): bool
|
||||
{
|
||||
return $this->bBeforeInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return InputWithLabel
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\RichText;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class RichText
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\RichText
|
||||
*/
|
||||
class RichText extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-richtext';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/ckeditor/ckeditor.js',
|
||||
'js/ckeditor/adapters/jquery.js',
|
||||
'js/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js',
|
||||
'js/ckeditor.on-init.js',
|
||||
];
|
||||
public const DEFAULT_CSS_FILES_REL_PATH = [
|
||||
'js/ckeditor/plugins/codesnippet/lib/highlight/styles/obsidian.css',
|
||||
];
|
||||
|
||||
/** @var string|null */
|
||||
protected $sValue;
|
||||
/** @var array Configuration parameters for the CKEditor instance used with Richtext block */
|
||||
protected $aConfig;
|
||||
|
||||
/**
|
||||
* RichText constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sValue = null;
|
||||
$this->aConfig = utils::GetCkeditorPref();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sValue
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetValue(): ?string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sValue
|
||||
* @see static::$sValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(?string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aConfig
|
||||
* @see static::$aConfig
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetConfig(array $aConfig)
|
||||
{
|
||||
$this->aConfig = $aConfig;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$aConfig
|
||||
* @return array
|
||||
*/
|
||||
public function GetConfig(): array
|
||||
{
|
||||
return $this->aConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Input\tInputLabel;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
class Select extends UIContentBlock
|
||||
{
|
||||
use tInputLabel;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-select';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/select/select';
|
||||
|
||||
/** @var string Input name for the form */
|
||||
protected $sName;
|
||||
/** @var bool if true submit the form as soon as a change is detected */
|
||||
protected $bSubmitOnChange = false;
|
||||
/** @var bool Allow multiple selection */
|
||||
protected $bIsMultiple = false;
|
||||
|
||||
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->bIsMultiple = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SelectOption $oOption Select option UIBlock
|
||||
*/
|
||||
public function AddOption(SelectOption $oOption)
|
||||
{
|
||||
$this->AddSubBlock($oOption);
|
||||
}
|
||||
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName {@see Select::$sName}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetName(string $sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool {@see Select::$bSubmitOnChange}
|
||||
*/
|
||||
public function GetSubmitOnChange(): bool
|
||||
{
|
||||
return $this->bSubmitOnChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bSubmitOnChange {@see Select::$bSubmitOnChange}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSubmitOnChange(bool $bSubmitOnChange)
|
||||
{
|
||||
$this->bSubmitOnChange = $bSubmitOnChange;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool {@see Select::$bIsMultiple}
|
||||
*/
|
||||
public function IsMultiple(): bool
|
||||
{
|
||||
return $this->bIsMultiple;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsMultiple {@see Select::$bIsMultiple}
|
||||
*/
|
||||
public function SetIsMultiple(bool $bIsMultiple)
|
||||
{
|
||||
$this->bIsMultiple = $bIsMultiple;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
class SelectOption extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-select-option';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/select/selectoption';
|
||||
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var bool */
|
||||
protected $bSelected;
|
||||
/** @var bool */
|
||||
protected $bDisabled;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetValue(string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSelected(): bool
|
||||
{
|
||||
return $this->bSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bSelected
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetSelected(bool $bSelected)
|
||||
{
|
||||
$this->bSelected = $bSelected;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDisabled(): bool
|
||||
{
|
||||
return $this->bDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bDisabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDisabled(bool $bDisabled)
|
||||
{
|
||||
$this->bDisabled = $bDisabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\Select;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class SelectOptionUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input\Select
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class SelectOptionUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UISelectOption';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = SelectOption::class;
|
||||
|
||||
public static function MakeForSelectOption(string $sValue, string $sLabel, bool $bSelected, ?string $sId = null)
|
||||
{
|
||||
$oInput = new SelectOption($sId);
|
||||
|
||||
$oInput->SetValue($sValue)
|
||||
->SetLabel($sLabel)
|
||||
->SetSelected($bSelected)
|
||||
->SetDisabled(false);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
|
||||
|
||||
/**
|
||||
* Class SelectUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class SelectUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UISelect';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Select::class;
|
||||
|
||||
/**
|
||||
* Create a default Select input
|
||||
*
|
||||
* @param string $sName {@see Select::$sName}
|
||||
* @param string|null $sId {@see UIBlock::$sId}
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\Select
|
||||
*/
|
||||
public static function MakeForSelect(string $sName, ?string $sId = null)
|
||||
{
|
||||
$oInput = new Select($sId);
|
||||
$oInput->SetName($sName);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Select input with a label
|
||||
*
|
||||
* If you need to have a real field with a label, you might use a {@link Field} component instead
|
||||
*
|
||||
* @param string $sName {@see Select::$sName}
|
||||
* @param string $sLabel {@see Select::$sLabel}
|
||||
* @param string|null $sId {@see UIBlock::$sId}
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Select\Select
|
||||
*/
|
||||
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null)
|
||||
{
|
||||
$oInput = new Select($sId);
|
||||
$oInput->SetName($sName);
|
||||
$oInput->SetLabel($sLabel);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
}
|
||||
92
sources/Application/UI/Base/Component/Input/TextArea.php
Normal file
92
sources/Application/UI/Base/Component/Input/TextArea.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
/**
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
class TextArea extends AbstractInput
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-textarea';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/input-textarea';
|
||||
|
||||
/** @var int */
|
||||
protected $iCols;
|
||||
/** @var int */
|
||||
protected $iRows;
|
||||
/** @var bool */
|
||||
protected $bIsDisabled;
|
||||
|
||||
public function __construct(string $sName, ?string $sValue, ?string $sId = null, ?int $iCols = null, ?int $iRows = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sName = $sName;
|
||||
$this->sValue = $sValue;
|
||||
$this->iCols = $iCols;
|
||||
$this->iRows = $iRows;
|
||||
$this->bIsDisabled = false;
|
||||
}
|
||||
|
||||
public function GetCols(): ?int
|
||||
{
|
||||
return $this->iCols;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iCols
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCols(int $iCols)
|
||||
{
|
||||
$this->iCols = $iCols;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetRows(): ?int
|
||||
{
|
||||
return $this->iRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iRows
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetRows(int $iRows)
|
||||
{
|
||||
$this->iRows = $iRows;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDisabled(): bool
|
||||
{
|
||||
return $this->bIsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsDisabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsDisabled(bool $bIsDisabled)
|
||||
{
|
||||
$this->bIsDisabled = $bIsDisabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
88
sources/Application/UI/Base/Component/Input/tInputLabel.php
Normal file
88
sources/Application/UI/Base/Component/Input/tInputLabel.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
/**
|
||||
* Trait tInputLabel Label for input
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
trait tInputLabel
|
||||
{
|
||||
/** @var bool If true the label will be positioned before the input */
|
||||
protected $bIsLabelBefore = true;
|
||||
/** @var string|null Label to display with the input (null for no label) */
|
||||
protected $sLabel = null;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsLabelBefore(): bool
|
||||
{
|
||||
return $this->bIsLabelBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsLabelBefore {@see tInputLabel::$bIsLabelBefore}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsLabelBefore(bool $bIsLabelBefore)
|
||||
{
|
||||
$this->bIsLabelBefore = $bIsLabelBefore;
|
||||
if ($this->bIsLabelBefore) {
|
||||
$this->AddCSSClass('ibo-input--label-left');
|
||||
$this->RemoveCSSClass('ibo-input--label-right');
|
||||
} else {
|
||||
$this->AddCSSClass('ibo-input--label-right');
|
||||
$this->RemoveCSSClass('ibo-input--label-left');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetLabel(): ?string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $sLabel {@see tInputLabel::$sLabel}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel(?string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
if (!is_null($sLabel)) {
|
||||
if ($this->bIsLabelBefore) {
|
||||
$this->AddCSSClass('ibo-input--label-left');
|
||||
$this->RemoveCSSClass('ibo-input--label-right');
|
||||
} else {
|
||||
$this->AddCSSClass('ibo-input--label-right');
|
||||
$this->RemoveCSSClass('ibo-input--label-left');
|
||||
}
|
||||
} else {
|
||||
$this->RemoveCSSClass('ibo-input--label-right');
|
||||
$this->RemoveCSSClass('ibo-input--label-left');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function HasLabel(): bool
|
||||
{
|
||||
return $this->sLabel != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\MedallionIcon;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class MedallionIcon
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\MedallionIcon
|
||||
*/
|
||||
class MedallionIcon extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-medallion-icon';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/medallion-icon/layout';
|
||||
|
||||
/** @var string $sImageUrl */
|
||||
private $sImageUrl;
|
||||
/** @var string $sIconClass */
|
||||
private $sIconClass;
|
||||
/** @var string $sDescription */
|
||||
private $sDescription;
|
||||
|
||||
/**
|
||||
* MedallionIcon constructor.
|
||||
*
|
||||
* @param string $sImageUrl
|
||||
* @param string $sIconClass
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sImageUrl = '', string $sIconClass = '', ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sImageUrl = $sImageUrl;
|
||||
$this->sIconClass= $sIconClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetImageUrl(): string
|
||||
{
|
||||
return $this->sImageUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sImageUrl
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\MedallionIcon\MedallionIcon
|
||||
*/
|
||||
public function SetImageUrl($sImageUrl)
|
||||
{
|
||||
$this->sImageUrl = $sImageUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconClass(): string
|
||||
{
|
||||
return $this->sIconClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClass
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\MedallionIcon\MedallionIcon
|
||||
*/
|
||||
public function SetIconClass($sIconClass)
|
||||
{
|
||||
$this->sIconClass = $sIconClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDescription(): string
|
||||
{
|
||||
return $this->sDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDescription
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\MedallionIcon\MedallionIcon
|
||||
*/
|
||||
public function SetDescription(string $sDescription)
|
||||
{
|
||||
$this->sDescription = $sDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
751
sources/Application/UI/Base/Component/Panel/Panel.php
Normal file
751
sources/Application/UI/Base/Component/Panel/Panel.php
Normal file
@@ -0,0 +1,751 @@
|
||||
<?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\Panel;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
|
||||
use MetaModel;
|
||||
use ormStyle;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class Panel
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Panel
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Panel extends UIContentBlock
|
||||
{
|
||||
use tUIContentAreas;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-panel';
|
||||
/** @inheritDoc */
|
||||
public const REQUIRES_ANCESTORS_DEFAULT_JS_FILES = true;
|
||||
/** @inheritDoc */
|
||||
public const REQUIRES_ANCESTORS_DEFAULT_CSS_FILES = true;
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/panel/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/panel/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/components/panel.js',
|
||||
];
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_COLOR_SCHEME_PRIMARY */
|
||||
public const ENUM_COLOR_SCHEME_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SCHEME_SECONDARY */
|
||||
public const ENUM_COLOR_SCHEME_SECONDARY = 'secondary';
|
||||
|
||||
/** @var string ENUM_COLOR_SCHEME_NEUTRAL */
|
||||
public const ENUM_COLOR_SCHEME_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_SCHEME_INFORMATION */
|
||||
public const ENUM_COLOR_SCHEME_INFORMATION = 'information';
|
||||
/** @var string ENUM_COLOR_SCHEME_SUCCESS */
|
||||
public const ENUM_COLOR_SCHEME_SUCCESS = 'success';
|
||||
/** @var string ENUM_COLOR_SCHEME_FAILURE */
|
||||
public const ENUM_COLOR_SCHEME_FAILURE = 'failure';
|
||||
/** @var string ENUM_COLOR_SCHEME_WARNING */
|
||||
public const ENUM_COLOR_SCHEME_WARNING = 'warning';
|
||||
/** @var string ENUM_COLOR_SCHEME_DANGER */
|
||||
public const ENUM_COLOR_SCHEME_DANGER = 'danger';
|
||||
|
||||
/** @var string ENUM_COLOR_SCHEME_GREY */
|
||||
public const ENUM_COLOR_SCHEME_GREY = 'grey';
|
||||
/** @var string ENUM_COLOR_SCHEME_BLUEGREY */
|
||||
public const ENUM_COLOR_SCHEME_BLUEGREY = 'blue-grey';
|
||||
/** @var string ENUM_COLOR_SCHEME_BLUE */
|
||||
public const ENUM_COLOR_SCHEME_BLUE = 'blue';
|
||||
/** @var string ENUM_COLOR_SCHEME_CYAN */
|
||||
public const ENUM_COLOR_SCHEME_CYAN = 'cyan';
|
||||
/** @var string ENUM_COLOR_SCHEME_GREEN */
|
||||
public const ENUM_COLOR_SCHEME_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_SCHEME_ORANGE */
|
||||
public const ENUM_COLOR_SCHEME_ORANGE = 'orange';
|
||||
/** @var string ENUM_COLOR_SCHEME_RED */
|
||||
public const ENUM_COLOR_SCHEME_RED = 'red';
|
||||
/** @var string ENUM_COLOR_SCHEME_PINK */
|
||||
public const ENUM_COLOR_SCHEME_PINK = 'pink';
|
||||
|
||||
/** @var string ENUM_CONTENT_AREA_MAIN The main content area (panel body) */
|
||||
public const ENUM_CONTENT_AREA_MAIN = 'main';
|
||||
/** @var string ENUM_CONTENT_AREA_TOOLBAR The toolbar content area (for actions) */
|
||||
public const ENUM_CONTENT_AREA_TOOLBAR = 'toolbar';
|
||||
|
||||
/** @var string Icon should be contained (boxed) in the medallion, best for icons with transparent background and some margin around */
|
||||
public const ENUM_ICON_COVER_METHOD_CONTAIN = 'contain';
|
||||
/** @var string Icon should be a litte zoomed out to cover almost all space, best for icons with transparent background and no margin around (eg. class icons) */
|
||||
public const ENUM_ICON_COVER_METHOD_ZOOMOUT = 'zoomout';
|
||||
/** @var string Icon should cover all the space, best for icons with filled background */
|
||||
public const ENUM_ICON_COVER_METHOD_COVER = 'cover';
|
||||
|
||||
/** @var string DEFAULT_COLOR_SCHEME */
|
||||
public const DEFAULT_COLOR_SCHEME = self::ENUM_COLOR_SCHEME_NEUTRAL;
|
||||
/** @var string Default color for a panel displaying info about a datamodel class */
|
||||
public const DEFAULT_COLOR_SCHEME_FOR_CLASS = self::ENUM_COLOR_SCHEME_BLUE;
|
||||
/** @var null */
|
||||
public const DEFAULT_ICON_URL = null;
|
||||
/** @var string */
|
||||
public const DEFAULT_ICON_COVER_METHOD = self::ENUM_ICON_COVER_METHOD_CONTAIN;
|
||||
/** @var bool */
|
||||
public const DEFAULT_ICON_AS_MEDALLION = false;
|
||||
/**
|
||||
* @var bool
|
||||
* @see static::$bIsHeaderVisibleOnScroll
|
||||
*/
|
||||
public const DEFAULT_IS_HEADER_VISIBLE_ON_SCROLL = false;
|
||||
|
||||
/** @var iUIContentBlock $oTitleBlock */
|
||||
protected $oTitleBlock;
|
||||
/** @var iUIContentBlock */
|
||||
protected $oSubTitleBlock;
|
||||
/** @var null|string $sIconUrl */
|
||||
protected $sIconUrl;
|
||||
/** @var string How the icon should cover its container, see static::ENUM_ICON_COVER_METHOD_XXX */
|
||||
protected $sIconCoverMethod;
|
||||
/** @var bool Whether the icon should be rendered as a medallion (rounded with border) or a standalone image */
|
||||
protected $bIconAsMedallion;
|
||||
/** @var string $sCSSColorClass CSS class that will be used on the block to define its accent color */
|
||||
protected $sCSSColorClass;
|
||||
/** @var bool $bIsCollapsible */
|
||||
protected $bIsCollapsible;
|
||||
/** @var bool $bIsHeaderVisibleOnScroll True if the header of the panel should remain visible when scrolling */
|
||||
protected $bIsHeaderVisibleOnScroll;
|
||||
|
||||
/**
|
||||
* Panel constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aSubBlocks
|
||||
* @param string $sColorScheme Color scheme code such as "success", "failure", "active", ... {@see css/backoffice/components/_panel.scss}
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sTitle = '', array $aSubBlocks = [], string $sColorScheme = self::DEFAULT_COLOR_SCHEME, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
if (empty($sTitle)) {
|
||||
$this->oTitleBlock = new UIContentBlock();
|
||||
} else {
|
||||
$this->SetTitle($sTitle);
|
||||
}
|
||||
|
||||
$this->oSubTitleBlock = new UIContentBlock();
|
||||
$this->aSubBlocks = $aSubBlocks;
|
||||
$this->sIconUrl = static::DEFAULT_ICON_URL;
|
||||
$this->sIconCoverMethod = static::DEFAULT_ICON_COVER_METHOD;
|
||||
$this->bIconAsMedallion = static::DEFAULT_ICON_AS_MEDALLION;
|
||||
$this->SetColorFromColorSemantic($sColorScheme);
|
||||
$this->SetMainBlocks([]);
|
||||
$this->SetToolBlocks([]);
|
||||
$this->bIsCollapsible = false;
|
||||
$this->bIsHeaderVisibleOnScroll = static::DEFAULT_IS_HEADER_VISIBLE_ON_SCROLL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$oTitleBlock
|
||||
* @return bool
|
||||
*/
|
||||
public function HasTitle(): bool
|
||||
{
|
||||
return $this->oTitleBlock->HasSubBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$oTitleBlock
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
|
||||
*/
|
||||
public function GetTitleBlock()
|
||||
{
|
||||
return $this->oTitleBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title from the $oBlock, replacing any existing content
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTitleBlock(iUIContentBlock $oBlock)
|
||||
{
|
||||
$this->oTitleBlock = $oBlock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to set the title from a simple text ($sTitle), replacing any existnig block
|
||||
*
|
||||
* @see static::$oTitleBlock
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTitle(string $sTitle)
|
||||
{
|
||||
$this->oTitleBlock = new UIContentBlock();
|
||||
$this->oTitleBlock->AddHtml(utils::EscapeHtml($sTitle));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a UIBlock to the title
|
||||
*
|
||||
* @see static::$oTitleBlock
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddTitleBlock(iUIBlock $oBlock)
|
||||
{
|
||||
$this->oTitleBlock->AddSubBlock($oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all $aBlocks to the title
|
||||
*
|
||||
* @see static::$oTitleBlock
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddTitleBlocks(array $aBlocks)
|
||||
{
|
||||
foreach ($aBlocks as $oBlock) {
|
||||
$this->AddTitleBlock($oBlock);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$oSubTitleBlock
|
||||
* @return bool
|
||||
*/
|
||||
public function HasSubTitle(): bool
|
||||
{
|
||||
return $this->oSubTitleBlock->HasSubBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$oSubTitleBlock
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
|
||||
*/
|
||||
public function GetSubTitleBlock()
|
||||
{
|
||||
return $this->oSubTitleBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle from the $oBlock, replacing any existing content
|
||||
*
|
||||
* @see static::$oSubTitleBlock
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSubTitleBlock(iUIContentBlock $oBlock)
|
||||
{
|
||||
$this->oSubTitleBlock = $oBlock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to set the subtitle from a simple text ($sSubTitle), replacing any existing block
|
||||
*
|
||||
* @see static::$oSubTitleBlock
|
||||
*
|
||||
* @param string $sSubTitle
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSubTitle(string $sSubTitle)
|
||||
{
|
||||
$this->oSubTitleBlock = new UIContentBlock();
|
||||
$this->oSubTitleBlock->AddHtml(utils::EscapeHtml($sSubTitle));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a UIBlock to the subtitle
|
||||
*
|
||||
* @see static::$oSubTitleBlock
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddSubTitleBlock(iUIBlock $oBlock)
|
||||
{
|
||||
$this->oSubTitleBlock->AddSubBlock($oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all $aBlocks to the subtitle
|
||||
*
|
||||
* @see static::$oSubTitleBlock
|
||||
*
|
||||
* @param iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddSubTitleBlocks(array $aBlocks)
|
||||
{
|
||||
foreach ($aBlocks as $oBlock) {
|
||||
$this->AddSubTitleBlock($oBlock);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sIconUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function HasIcon(): bool
|
||||
{
|
||||
return !empty($this->sIconUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sIconUrl
|
||||
* @return null|string
|
||||
*/
|
||||
public function GetIconUrl(): ?string
|
||||
{
|
||||
return $this->sIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sIconCoverMethod
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconCoverMethod(): string
|
||||
{
|
||||
return $this->sIconCoverMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True if the icon should be displayed as a medallion (round with a border) or as-is.
|
||||
*/
|
||||
public function IsIconAsMedallion(): bool
|
||||
{
|
||||
return $this->HasIcon() && $this->bIconAsMedallion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sIconUrl
|
||||
* @see static::$sIconCoverMethod
|
||||
* @see static::$bIconAsMedallion
|
||||
*
|
||||
* @param string $sIconUrl
|
||||
* @param string $sIconCoverMethod
|
||||
* @param bool $bIconAsMedallion
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIcon(string $sIconUrl, string $sIconCoverMethod = self::DEFAULT_ICON_COVER_METHOD, bool $bIconAsMedallion = self::DEFAULT_ICON_AS_MEDALLION)
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
$this->sIconCoverMethod = $sIconCoverMethod;
|
||||
$this->bIconAsMedallion = $bIconAsMedallion;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sCSSColorClass
|
||||
* @return string
|
||||
*/
|
||||
public function GetCSSColorClass(): string
|
||||
{
|
||||
return $this->sCSSColorClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCSSColorClass
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCSSColorClass(string $sCSSColorClass)
|
||||
{
|
||||
$this->sCSSColorClass = $sCSSColorClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSemanticColor
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColorFromColorSemantic(string $sSemanticColor)
|
||||
{
|
||||
$this->SetCSSColorClass("ibo-is-$sSemanticColor");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the panel's accent color from an ormStyle directly.
|
||||
*
|
||||
* Use cases:
|
||||
* - Display information about a particular enum value (linked objects)
|
||||
*
|
||||
* @param \ormStyle $oStyle
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColorFromOrmStyle(ormStyle $oStyle)
|
||||
{
|
||||
if ($oStyle->HasStyleClass()) {
|
||||
$this->SetCSSColorClass($oStyle->GetStyleClass());
|
||||
} else {
|
||||
$this->SetColorFromColorSemantic(static::DEFAULT_COLOR_SCHEME);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the panel's accent color to the one corresponding to the $sClass datamodel class
|
||||
*
|
||||
* Use cases:
|
||||
* - Display information about a specific datamodel class
|
||||
*
|
||||
* @param string $sClass
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColorFromClass(string $sClass)
|
||||
{
|
||||
$oStyle = MetaModel::GetClassStyle($sClass);
|
||||
if (empty($oStyle)) {
|
||||
$this->SetColorFromColorSemantic(static::DEFAULT_COLOR_SCHEME_FOR_CLASS);
|
||||
} else {
|
||||
$this->SetColorFromOrmStyle($oStyle);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsCollapsible(): bool
|
||||
{
|
||||
return $this->bIsCollapsible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsCollapsible
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsCollapsible(bool $bIsCollapsible)
|
||||
{
|
||||
$this->bIsCollapsible = $bIsCollapsible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$bIsHeaderVisibleOnScroll
|
||||
* @return bool
|
||||
*/
|
||||
public function IsHeaderVisibleOnScroll(): bool
|
||||
{
|
||||
return $this->bIsHeaderVisibleOnScroll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$bIsHeaderVisibleOnScroll
|
||||
*
|
||||
* @param bool $bIsHeaderVisibleOnScroll
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsHeaderVisibleOnScroll(bool $bIsHeaderVisibleOnScroll)
|
||||
{
|
||||
$this->bIsHeaderVisibleOnScroll = $bIsHeaderVisibleOnScroll;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//----------------------
|
||||
// Specific content area
|
||||
//----------------------
|
||||
|
||||
/**
|
||||
* Set all main blocks at once.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMainBlocks(array $aBlocks) {
|
||||
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the main blocks
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetMainBlocks(): array {
|
||||
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_MAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oBlock to the main blocks.
|
||||
* Note that if a block with the same ID already exists, it will be replaced.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddMainBlock(iUIBlock $oBlock)
|
||||
{
|
||||
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_MAIN, $oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all $aBlocks to the main blocks
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
* @uses static::AddBlocksToContentArea()
|
||||
*/
|
||||
public function AddMainBlocks(array $aBlocks)
|
||||
{
|
||||
$this->AddBlocksToContentArea(static::ENUM_CONTENT_AREA_MAIN, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the main block identified by $sBlockId.
|
||||
* Note that if no block with that ID exists, it will proceed silently.
|
||||
*
|
||||
* @param string $sBlockId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveMainBlock(string $sBlockId)
|
||||
{
|
||||
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_MAIN, $sBlockId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all toolbar blocks at once.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetToolBlocks(array $aBlocks) {
|
||||
$this->SetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the toolbar blocks
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\iUIBlock[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetToolbarBlocks(): array {
|
||||
return $this->GetContentAreaBlocks(static::ENUM_CONTENT_AREA_TOOLBAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oBlock to the toolbar blocks.
|
||||
* Note that if a block with the same ID already exists, it will be replaced.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddToolbarBlock(iUIBlock $oBlock)
|
||||
{
|
||||
$this->AddBlockToContentArea(static::ENUM_CONTENT_AREA_TOOLBAR, $oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all $aBlocks to the toolbar blocks
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aBlocks
|
||||
*
|
||||
* @return $this
|
||||
* @uses static::AddBlocksToContentArea()
|
||||
*/
|
||||
public function AddToolbarBlocks(array $aBlocks)
|
||||
{
|
||||
$this->AddBlocksToContentArea(static::ENUM_CONTENT_AREA_TOOLBAR, $aBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the toolbar block identified by $sBlockId.
|
||||
* Note that if no block with that ID exists, it will proceed silently.
|
||||
*
|
||||
* @param string $sBlockId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveToolbarBlock(string $sBlockId)
|
||||
{
|
||||
$this->RemoveBlockFromContentArea(static::ENUM_CONTENT_AREA_TOOLBAR, $sBlockId);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// iUIContentBlock implementation
|
||||
//-------------------------------
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function AddHtml(string $sHtml) {
|
||||
$oBlock = new Html($sHtml);
|
||||
$this->AddMainBlock($oBlock);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the $oSubBlock directly in the main area
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function AddSubBlock(?iUIBlock $oSubBlock) {
|
||||
if ($oSubBlock) {
|
||||
$this->AddMainBlock($oSubBlock);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specified subBlock from all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveSubBlock(string $sId) {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oContentArea->RemoveSubBlock($sId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified subBlock is within one of all the areas
|
||||
*
|
||||
* @param string $sId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasSubBlock(string $sId): bool {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
if ($oContentArea->HasSubBlock($sId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific subBlock within all the areas
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlock(string $sId): ?iUIBlock {
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$oSubBlock = $oContentArea->GetSubBlock($sId);
|
||||
if (!is_null($oSubBlock)) {
|
||||
return $oSubBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAIN AREA subBlocks
|
||||
*
|
||||
* @inheritDoc
|
||||
* @return $this|\Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock
|
||||
*/
|
||||
public function SetSubBlocks(array $aSubBlocks): iUIContentBlock {
|
||||
$this->SetMainBlocks($aSubBlocks);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ALL the blocks in all the areas
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetSubBlocks());
|
||||
}
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
<?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\Panel;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class PanelUIBlockFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Panel
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-panels to see live examples
|
||||
*/
|
||||
class PanelUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIPanel';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Panel::class;
|
||||
|
||||
/**
|
||||
* Make a basis Panel component
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeNeutral(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_NEUTRAL);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for informational messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForInformation(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_INFORMATION);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for successful messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForSuccess(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_SUCCESS);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for warning messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForWarning(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_WARNING);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for danger messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForDanger(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_DANGER);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for failure messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForFailure(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_FAILURE);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component with primary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeWithBrandingPrimaryColor(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_PRIMARY);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component with secondary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeWithBrandingSecondaryColor(string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromColorSemantic(Panel::ENUM_COLOR_SCHEME_SECONDARY);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component with the specific $sClass color scheme
|
||||
*
|
||||
* @param string $sClass Class of the object the panel is for
|
||||
* @param string $sTitle
|
||||
* @param string|null $sSubTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForClass(string $sClass, string $sTitle, string $sSubTitle = null)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
if (!is_null($sSubTitle)) {
|
||||
$oPanel->SetSubTitle($sSubTitle);
|
||||
}
|
||||
$oPanel->SetColorFromClass($sClass);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
}
|
||||
145
sources/Application/UI/Base/Component/Pill/Pill.php
Normal file
145
sources/Application/UI/Base/Component/Pill/Pill.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Pill;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Class Pill
|
||||
*
|
||||
* @internal
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Pill
|
||||
*/
|
||||
class Pill extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-pill';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/pill/layout';
|
||||
|
||||
/** @var null|string CSS class that will be used on the block to define its color scheme */
|
||||
protected $sCSSColorClass;
|
||||
/** @var null|string URL to go to if the pill is clicked */
|
||||
protected $sUrl;
|
||||
/** @var null|string Text to display as a tooltip */
|
||||
protected $sTooltip;
|
||||
|
||||
/**
|
||||
* Pill constructor.
|
||||
*
|
||||
* @param string|null $sSemanticColor Semantic color code such as "success", "failure", "active", ... {@see css/backoffice/components/_pill.scss}
|
||||
*/
|
||||
public function __construct(?string $sSemanticColor = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (is_null($sSemanticColor) === false) {
|
||||
$this->SetSemanticColor($sSemanticColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sCSSColorClass
|
||||
* @return string
|
||||
*/
|
||||
public function GetCSSColorClass(): ?string
|
||||
{
|
||||
return $this->sCSSColorClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCSSColorClass
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCSSColorClass(string $sCSSColorClass)
|
||||
{
|
||||
$this->sCSSColorClass = $sCSSColorClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSemanticColor Semantic color code such as "success", "failure", "active", ... {@see css/backoffice/components/_pill.scss}
|
||||
*
|
||||
* @see static::$sCSSColorClass
|
||||
* @return Pill
|
||||
*/
|
||||
public function SetSemanticColor(string $sSemanticColor)
|
||||
{
|
||||
$this->sCSSColorClass = 'ibo-is-'.$sSemanticColor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sUrl
|
||||
* @return null|string
|
||||
*/
|
||||
public function GetUrl(): ?string
|
||||
{
|
||||
return $this->sUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUrl
|
||||
*
|
||||
* @see static::$sUrl
|
||||
* @return $this
|
||||
*/
|
||||
public function SetUrl(string $sUrl)
|
||||
{
|
||||
$this->sUrl = $sUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sUrl
|
||||
* @return bool
|
||||
*/
|
||||
public function HasUrl(): bool
|
||||
{
|
||||
return !empty($this->sUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sTooltip
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetTooltip(): ?string
|
||||
{
|
||||
return $this->sTooltip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sTooltip
|
||||
*
|
||||
* @param string|null $sTooltip
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTooltip(?string $sTooltip)
|
||||
{
|
||||
$this->sTooltip = $sTooltip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see static::$sTooltip
|
||||
* @return bool
|
||||
*/
|
||||
public function HasTooltip(): bool
|
||||
{
|
||||
return !empty($this->sTooltip);
|
||||
}
|
||||
}
|
||||
45
sources/Application/UI/Base/Component/Pill/PillFactory.php
Normal file
45
sources/Application/UI/Base/Component/Pill/PillFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Pill;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Helper\UIHelper;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Class PillFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Pill
|
||||
*/
|
||||
class PillFactory
|
||||
{
|
||||
/**
|
||||
* @param string $sClass
|
||||
* @param string $sStateCode
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Pill\Pill
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public static function MakeForState(string $sClass, string $sStateCode)
|
||||
{
|
||||
$oPill = new Pill();
|
||||
|
||||
// First we try to apply style defined in the DM if any, otherwise we fallback on the default colors
|
||||
$oStyle = MetaModel::GetEnumStyle($sClass, MetaModel::GetStateAttributeCode($sClass), $sStateCode);
|
||||
if ($oStyle !== null) {
|
||||
$oPill->SetCSSColorClass($oStyle->GetStyleClass());
|
||||
} else {
|
||||
$oPill->SetSemanticColor(UIHelper::GetColorNameFromStatusCode($sStateCode));
|
||||
}
|
||||
|
||||
return $oPill;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?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\QuickCreate;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use iKeyboardShortcut;
|
||||
use MetaModel;
|
||||
use UserRights;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class QuickCreate
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\QuickCreate
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class QuickCreate extends UIBlock implements iKeyboardShortcut
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-quick-create';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/quick-create/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/quick-create/layout';
|
||||
public const DEFAULT_JS_FILES_REL_PATH = [
|
||||
'js/selectize.min.js',
|
||||
'js/components/quick-create.js',
|
||||
];
|
||||
public const DEFAULT_CSS_FILES_REL_PATH = [
|
||||
'css/selectize.default.css',
|
||||
];
|
||||
|
||||
// Specific constants
|
||||
public const DEFAULT_ENDPOINT_REL_URL = 'pages/UI.php';
|
||||
|
||||
/** @var string $sEndpoint Absolute endpoint URL of the creation form */
|
||||
protected $sEndpoint;
|
||||
/** @var array $aAvailableClasses */
|
||||
protected $aAvailableClasses;
|
||||
/** @var array $aLastClasses */
|
||||
protected $aLastClasses;
|
||||
/** @var int $iMaxAutocompleteResults Max. number of elements returned by the autocomplete */
|
||||
protected $iMaxAutocompleteResults;
|
||||
/** @var bool $bShowHistory Whether or not to display the elements in the history */
|
||||
protected $bShowHistory;
|
||||
/** @var int $iMaxHistoryResults Max. number of elements in the history */
|
||||
protected $iMaxHistoryResults;
|
||||
|
||||
/**
|
||||
* QuickCreate constructor.
|
||||
*
|
||||
* @param array $aLastClasses
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public function __construct(array $aLastClasses = [], ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->SetEndpoint(static::DEFAULT_ENDPOINT_REL_URL);
|
||||
$this->aAvailableClasses = $this->FilterAvailableClasses(UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true));
|
||||
$this->aLastClasses = $aLastClasses;
|
||||
$this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results');
|
||||
$this->bShowHistory = (bool) MetaModel::GetConfig()->Get('quick_create.show_history');
|
||||
$this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the creation form endpoint URL.
|
||||
* If $bRelativeUrl is true, then $sEndpoint will be complete with the app_root_url
|
||||
*
|
||||
* @param string $sEndpoint URL to the endpoint
|
||||
* @param bool $bRelativeUrl Whether or not the $sEndpoint parameter is a relative URL
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function SetEndpoint(string $sEndpoint, bool $bRelativeUrl = true)
|
||||
{
|
||||
$this->sEndpoint = (($bRelativeUrl) ? utils::GetAbsoluteUrlAppRoot() : '').$sEndpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute URL of the creation form
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetEndpoint(): string
|
||||
{
|
||||
return $this->sEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available classes (to create) for the current user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetAvailableClasses(): array
|
||||
{
|
||||
return $this->aAvailableClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the $aClasses array of DM classes minus the classes that should not be proposed in the autocomplete:
|
||||
* - not derivating from cmdbAbstractObject
|
||||
* - n:n classes
|
||||
*
|
||||
* @param array $aClasses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function FilterAvailableClasses(array $aClasses): array
|
||||
{
|
||||
$aFilteredClasses = [];
|
||||
|
||||
foreach ($aClasses as $sClassName => $sClassLabel){
|
||||
// Skip not derivating from cmdbAbstractObject
|
||||
if(false === is_a($sClassName, '\cmdbAbstractObject', true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip n:n classes
|
||||
if(MetaModel::IsLinkClass($sClassName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$aFilteredClasses[$sClassName] = $sClassLabel;
|
||||
}
|
||||
|
||||
return $aFilteredClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all the last classes at once
|
||||
*
|
||||
* @param array $aLastClasses
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLastClasses(array $aLastClasses)
|
||||
{
|
||||
$this->aLastClasses = $aLastClasses;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last classes (class name, label as HTML, icon URL, ...)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetLastClasses(): array
|
||||
{
|
||||
return $this->aLastClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxAutocompleteResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxAutocompleteResults(): int
|
||||
{
|
||||
return $this->iMaxAutocompleteResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $bShowHistory
|
||||
* @return bool
|
||||
*/
|
||||
public function GetShowHistory(): bool
|
||||
{
|
||||
return $this->bShowHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxHistoryResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxHistoryResults(): int
|
||||
{
|
||||
return $this->iMaxHistoryResults;
|
||||
}
|
||||
|
||||
public static function GetShortcutKeys(): array
|
||||
{
|
||||
return [['id' => 'ibo-open-quick-create', 'label' => 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer', 'key' => 'c', 'event' => 'open_drawer']];
|
||||
}
|
||||
|
||||
public static function GetShortcutTriggeredElementSelector(): string
|
||||
{
|
||||
return "[data-role='".static::BLOCK_CODE."']";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\QuickCreate;
|
||||
|
||||
|
||||
/**
|
||||
* Class QuickCreateFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\QuickCreate
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class QuickCreateFactory
|
||||
{
|
||||
/**
|
||||
* Make a QuickCreate component with the last classes from the current user
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\QuickCreate\QuickCreate
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function MakeFromUserHistory()
|
||||
{
|
||||
$aLastClasses = QuickCreateHelper::GetLastClasses();
|
||||
|
||||
return new QuickCreate($aLastClasses, QuickCreate::BLOCK_CODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?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\QuickCreate;
|
||||
|
||||
|
||||
use appUserPreferences;
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class QuickCreateHelper
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\QuickCreate
|
||||
* @internal
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class QuickCreateHelper
|
||||
{
|
||||
/** @var string */
|
||||
public const USER_PREF_CODE = 'quick_create_history';
|
||||
|
||||
/**
|
||||
* Add $sQuery to the history. History is limited to the static::MAX_HISTORY_SIZE last classes.
|
||||
*
|
||||
* @param string $sClass Class of the created object
|
||||
*
|
||||
* @return void
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function AddClassToHistory(string $sClass)
|
||||
{
|
||||
$aNewEntry = [
|
||||
'class' => $sClass,
|
||||
];
|
||||
|
||||
/** @var array $aHistoryEntries */
|
||||
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
|
||||
|
||||
// Remove same entry from history to avoid duplicates
|
||||
for ($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
|
||||
{
|
||||
if ($aHistoryEntries[$iIdx]['class'] === $sClass)
|
||||
{
|
||||
unset($aHistoryEntries[$iIdx]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new entry
|
||||
array_unshift($aHistoryEntries, $aNewEntry);
|
||||
|
||||
// Truncate history
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
appUserPreferences::SetPref(static::USER_PREF_CODE, $aHistoryEntries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of past created object classes
|
||||
*
|
||||
* @return array
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function GetLastClasses()
|
||||
{
|
||||
/** @var array $aHistoryEntries */
|
||||
$aHistoryEntries = appUserPreferences::GetPref(static::USER_PREF_CODE, []);
|
||||
static::TruncateHistory($aHistoryEntries);
|
||||
|
||||
for($iIdx = 0; $iIdx < count($aHistoryEntries); $iIdx++)
|
||||
{
|
||||
$sClass = $aHistoryEntries[$iIdx]['class'];
|
||||
|
||||
if (!MetaModel::IsValidClass($sClass)) {
|
||||
continue;
|
||||
}
|
||||
// Add class icon
|
||||
if(!isset($aHistoryEntries[$iIdx]['icon_url']))
|
||||
{
|
||||
$sClassIconUrl = MetaModel::GetClassIcon($sClass, false);
|
||||
// Mind that some classes don't have an icon
|
||||
if(!empty($sClassIconUrl))
|
||||
{
|
||||
$aHistoryEntries[$iIdx]['icon_url'] = $sClassIconUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// Add class label
|
||||
if(!isset($aHistoryEntries[$iIdx]['label_html']))
|
||||
{
|
||||
$aHistoryEntries[$iIdx]['label_html'] = utils::EscapeHtml(MetaModel::GetName($sClass));
|
||||
}
|
||||
|
||||
// Add URL
|
||||
if(!isset($aHistoryEntries[$iIdx]['target_url']))
|
||||
{
|
||||
$aHistoryEntries[$iIdx]['target_url'] = DBObject::ComputeStandardUIPage($sClass).'?operation=new&class='.$sClass;
|
||||
}
|
||||
}
|
||||
|
||||
return $aHistoryEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate $aHistoryEntries to 'global_search.max_history_results' entries
|
||||
*
|
||||
* @param array $aHistoryEntries
|
||||
*/
|
||||
protected static function TruncateHistory(array &$aHistoryEntries): void
|
||||
{
|
||||
$iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results');
|
||||
if(count($aHistoryEntries) > $iMaxHistoryResults)
|
||||
{
|
||||
$aHistoryEntries = array_slice($aHistoryEntries, 0, $iMaxHistoryResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
sources/Application/UI/Base/Component/Spinner/Spinner.php
Normal file
27
sources/Application/UI/Base/Component/Spinner/Spinner.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Spinner;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Spinner
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Spinner
|
||||
*/
|
||||
class Spinner extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-spinner';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/spinner/layout';
|
||||
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Spinner;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class SpinnerUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Spinner
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class SpinnerUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UISpinner';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Spinner::class;
|
||||
|
||||
public static function MakeStandard(?string $sId = null)
|
||||
{
|
||||
return new Spinner($sId);
|
||||
}
|
||||
}
|
||||
46
sources/Application/UI/Base/Component/Text/Text.php
Normal file
46
sources/Application/UI/Base/Component/Text/Text.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Text;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Text
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Text
|
||||
*/
|
||||
class Text extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-text';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/text/layout';
|
||||
|
||||
/**@var string */
|
||||
protected $sText;
|
||||
|
||||
/**
|
||||
* Text constructor.
|
||||
*
|
||||
* @param string $sText
|
||||
*/
|
||||
public function __construct(string $sText, ?string $sId = null)
|
||||
{
|
||||
$this->sText = $sText;
|
||||
parent::__construct($sId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetText(): string
|
||||
{
|
||||
return $this->sText;
|
||||
}
|
||||
|
||||
}
|
||||
96
sources/Application/UI/Base/Component/Title/Title.php
Normal file
96
sources/Application/UI/Base/Component/Title/Title.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Title;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Title
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Title
|
||||
*/
|
||||
class Title extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
/** @inheritDoc */
|
||||
public const BLOCK_CODE = 'ibo-title';
|
||||
/** @inheritDoc */
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/title/layout';
|
||||
|
||||
/** @var string Icon should be contained (boxed) in the medallion, best for icons with transparent background and some margin around */
|
||||
public const ENUM_ICON_COVER_METHOD_CONTAIN = 'contain';
|
||||
/** @var string Icon should be a litte zoomed out to cover almost all space, best for icons with transparent background and no margin around (eg. class icons) */
|
||||
public const ENUM_ICON_COVER_METHOD_ZOOMOUT = 'zoomout';
|
||||
/** @var string Icon should cover all the space, best for icons with filled background */
|
||||
public const ENUM_ICON_COVER_METHOD_COVER = 'cover';
|
||||
/** @var string */
|
||||
public const DEFAULT_ICON_COVER_METHOD = self::ENUM_ICON_COVER_METHOD_CONTAIN;
|
||||
|
||||
/** @var int */
|
||||
protected $iLevel;
|
||||
/** @var string */
|
||||
protected $sIconUrl;
|
||||
/** @var string How the icon should cover the medallion, see static::ENUM_ICON_COVER_METHOD_COVER, static::ENUM_ICON_COVER_METHOD_ZOOMOUT */
|
||||
protected $sIconCoverMethod;
|
||||
protected $bIsMedallion;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(UIBlock $oTitle, int $iLevel = 1, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->iLevel = $iLevel;
|
||||
$this->sIconUrl = null;
|
||||
$this->sIconCoverMethod = static::DEFAULT_ICON_COVER_METHOD;
|
||||
$this->bIsMedallion = true;
|
||||
$this->AddSubBlock($oTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetLevel(): int
|
||||
{
|
||||
return $this->iLevel;
|
||||
}
|
||||
|
||||
public function SetIcon(string $sIconUrl, string $sIconCoverMethod = self::DEFAULT_ICON_COVER_METHOD, bool $bIsMedallion = true)
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
$this->sIconCoverMethod = $sIconCoverMethod;
|
||||
$this->bIsMedallion = $bIsMedallion;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetIconUrl(): string
|
||||
{
|
||||
return $this->sIconUrl;
|
||||
}
|
||||
|
||||
public function GetIconCoverMethod(): string
|
||||
{
|
||||
return $this->sIconCoverMethod;
|
||||
}
|
||||
|
||||
public function HasIcon(): string
|
||||
{
|
||||
return !is_null($this->sIconUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsMedallion(): bool
|
||||
{
|
||||
return $this->bIsMedallion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Title;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Text\Text;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class TitleUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Title
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class TitleUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UITitle';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Title::class;
|
||||
|
||||
public static function MakeForPage(string $sTitle, ?string $sId = null)
|
||||
{
|
||||
return new Title(new Text($sTitle), 1, $sId);
|
||||
}
|
||||
|
||||
public static function MakeForPageWithIcon(
|
||||
string $sTitle, string $sIconUrl, string $sIconCoverMethod = Title::DEFAULT_ICON_COVER_METHOD, bool $bIsMedallion = true,
|
||||
?string $sId = null
|
||||
)
|
||||
{
|
||||
$oTitle = new Title(new Text($sTitle), 1, $sId);
|
||||
$oTitle->SetIcon($sIconUrl, $sIconCoverMethod, $bIsMedallion);
|
||||
|
||||
return $oTitle;
|
||||
}
|
||||
|
||||
public static function MakeNeutral(string $sTitle, int $iLevel = 1, ?string $sId = null)
|
||||
{
|
||||
return new Title(new Text($sTitle), $iLevel, $sId);
|
||||
}
|
||||
|
||||
public static function MakeStandard(UIBlock $oTitle, int $iLevel = 1, ?string $sId = null)
|
||||
{
|
||||
return new Title($oTitle, $iLevel, $sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class AbstractSeparator
|
||||
*
|
||||
* The only purpose of this class is tho be referenced in the factory
|
||||
*
|
||||
* @used-by \Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator\ToolbarSeparatorUIBlockFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class AbstractSeparator extends UIBlock
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class ToolbarSeparatorUIBlockFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator
|
||||
* @since 3.0.0
|
||||
* @api
|
||||
*/
|
||||
class ToolbarSeparatorUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIToolbarSeparator';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Toolbar::class;
|
||||
|
||||
/**
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator\VerticalSeparator
|
||||
*/
|
||||
public static function MakeVertical(string $sId = null)
|
||||
{
|
||||
return new VerticalSeparator($sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator;
|
||||
|
||||
|
||||
/**
|
||||
* Class ToolbarSpacer
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar\Separator
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class VerticalSeparator extends AbstractSeparator
|
||||
{
|
||||
// Overloaded constants
|
||||
/** @inheritDoc */
|
||||
public const BLOCK_CODE = 'ibo-toolbar-vertical-separator';
|
||||
/** @inheritDoc */
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/toolbar/separator/vertical-separator/layout';
|
||||
|
||||
/** @inheritDoc */
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
}
|
||||
}
|
||||
27
sources/Application/UI/Base/Component/Toolbar/Toolbar.php
Normal file
27
sources/Application/UI/Base/Component/Toolbar/Toolbar.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* Class Toolbar
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar
|
||||
*/
|
||||
class Toolbar extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-toolbar';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/toolbar/layout';
|
||||
|
||||
public function __construct(string $sId = null, array $aContainerClasses = [])
|
||||
{
|
||||
parent::__construct($sId, $aContainerClasses);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarSpacer;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class ButtonToolbarSpacer
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\ButtonToolbarSpacer
|
||||
*/
|
||||
class ToolbarSpacer extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-toolbar-spacer';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/toolbar/toolbar-spacer/layout';
|
||||
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarSpacer;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class ToolbarSpacerUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarSpacer
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class ToolbarSpacerUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIToolbarSpacer';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = ToolbarSpacer::class;
|
||||
|
||||
/**
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarSpacer\ToolbarSpacer
|
||||
*/
|
||||
public static function MakeStandard(string $sId = null)
|
||||
{
|
||||
return new ToolbarSpacer($sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Toolbar;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
|
||||
|
||||
/**
|
||||
* Class ToolbarUIBlockFactory
|
||||
*
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Toolbar
|
||||
* @since 3.0.0
|
||||
* @internal
|
||||
*/
|
||||
class ToolbarUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public const TWIG_TAG_NAME = 'UIToolbar';
|
||||
/** @inheritDoc */
|
||||
public const UI_BLOCK_CLASS_NAME = Toolbar::class;
|
||||
|
||||
public static function MakeForAction(string $sId = null)
|
||||
{
|
||||
return new Toolbar($sId, ['ibo-toolbar--action']);
|
||||
}
|
||||
|
||||
public static function MakeStandard(string $sId = null, array $aContainerClasses = [])
|
||||
{
|
||||
return new Toolbar($sId, $aContainerClasses);
|
||||
}
|
||||
|
||||
public static function MakeForButton(string $sId = null, array $aContainerClasses = [])
|
||||
{
|
||||
return new Toolbar($sId, array_merge($aContainerClasses, ['ibo-toolbar--button']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user