mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°3123 - Refactor Directories
This commit is contained in:
166
sources/application/UI/Base/Component/Alert/Alert.php
Normal file
166
sources/application/UI/Base/Component/Alert/Alert.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Alert
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Alert
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Alert extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-alert';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/alert/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/alert/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/components/alert.js',
|
||||
];
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_COLOR_PRIMARY */
|
||||
public const ENUM_COLOR_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SECONDARY */
|
||||
public const ENUM_COLOR_SECONDARY = 'secondary';
|
||||
|
||||
/** @var string ENUM_COLOR_NEUTRAL */
|
||||
public const ENUM_COLOR_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_INFORMATION */
|
||||
public const ENUM_COLOR_INFORMATION = 'information';
|
||||
/** @var string ENUM_COLOR_SUCCESS */
|
||||
public const ENUM_COLOR_SUCCESS = 'success';
|
||||
/** @var string ENUM_COLOR_FAILURE */
|
||||
public const ENUM_COLOR_FAILURE = 'failure';
|
||||
/** @var string ENUM_COLOR_WARNING */
|
||||
public const ENUM_COLOR_WARNING = 'warning';
|
||||
/** @var string ENUM_COLOR_DANGER */
|
||||
public const ENUM_COLOR_DANGER = 'danger';
|
||||
|
||||
/** @var string ENUM_COLOR_GREY */
|
||||
public const ENUM_COLOR_GREY = 'grey';
|
||||
/** @var string ENUM_COLOR_BLUEGREY */
|
||||
public const ENUM_COLOR_BLUEGREY = 'blue-grey';
|
||||
/** @var string ENUM_COLOR_BLUE */
|
||||
public const ENUM_COLOR_BLUE = 'blue';
|
||||
/** @var string ENUM_COLOR_CYAN */
|
||||
public const ENUM_COLOR_CYAN = 'cyan';
|
||||
/** @var string ENUM_COLOR_GREEN */
|
||||
public const ENUM_COLOR_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_ORANGE */
|
||||
public const ENUM_COLOR_ORANGE = 'orange';
|
||||
/** @var string ENUM_COLOR_RED */
|
||||
public const ENUM_COLOR_RED = 'red';
|
||||
/** @var string ENUM_COLOR_PINK */
|
||||
public const ENUM_COLOR_PINK = 'pink';
|
||||
|
||||
/** @var string DEFAULT_COLOR */
|
||||
public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
|
||||
|
||||
/** @var string $sTitle */
|
||||
protected $sTitle;
|
||||
/** @var string $sContent The raw HTML content, must be already sanitized */
|
||||
protected $sContent;
|
||||
/** @var string $sColor */
|
||||
protected $sColor;
|
||||
|
||||
/**
|
||||
* Alert constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent
|
||||
* @param string $sColor
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sTitle = '', string $sContent = '', string $sColor = self::DEFAULT_COLOR, ?string $sId = null)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
$this->sContent = $sContent;
|
||||
$this->sColor = $sColor;
|
||||
parent::__construct($sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle()
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @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()
|
||||
{
|
||||
return $this->sContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw HTML content, must be already sanitized.
|
||||
*
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContent(string $sContent)
|
||||
{
|
||||
$this->sContent = $sContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor()
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColor(string $sColor)
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
136
sources/application/UI/Base/Component/Alert/AlertFactory.php
Normal file
136
sources/application/UI/Base/Component/Alert/AlertFactory.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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;
|
||||
|
||||
/**
|
||||
* Class AlertFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Alert
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-alerts to see live examples
|
||||
*/
|
||||
class AlertFactory
|
||||
{
|
||||
/**
|
||||
* Make a basis Alert component
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeNeutral(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_NEUTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for informational messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForInformation(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_INFORMATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for successful messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForSuccess(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for warning messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForWarning(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for danger messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForDanger(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_DANGER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component for failure messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForFailure(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_FAILURE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component with primary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingPrimaryColor(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_PRIMARY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an Alert component with secondary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sContent The raw HTML content, must be already sanitized
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingSecondaryColor(string $sTitle, string $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SECONDARY);
|
||||
}
|
||||
}
|
||||
42
sources/application/UI/Base/Component/Badge/Badge.php
Normal file
42
sources/application/UI/Base/Component/Badge/Badge.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Badge;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
class Badge extends UIContentBlock
|
||||
{
|
||||
/** @var string */
|
||||
protected $sColor;
|
||||
|
||||
public function __construct(string $sColor)
|
||||
{
|
||||
parent::__construct(null, "ibo-badge ibo-badge-is-{$sColor}");
|
||||
$this->SetColor($sColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor(): ?string
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor
|
||||
*
|
||||
* @return Badge
|
||||
*/
|
||||
public function SetColor(string $sColor): Badge
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
22
sources/application/UI/Base/Component/Badge/BadgeFactory.php
Normal file
22
sources/application/UI/Base/Component/Badge/BadgeFactory.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Badge;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Helper\UIHelper;
|
||||
|
||||
class BadgeFactory
|
||||
{
|
||||
|
||||
public static function MakeForState(string $sClass, string $sStateCode)
|
||||
{
|
||||
$sColor = UIHelper::GetColorFromStatus($sClass, $sStateCode);
|
||||
return new Badge($sColor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/breadcrumbs/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/breadcrumbs/layout';
|
||||
public const 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()
|
||||
{
|
||||
return $this->aNewEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function GetJsWidgetOptions()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
368
sources/application/UI/Base/Component/Button/Button.php
Normal file
368
sources/application/UI/Base/Component/Button/Button.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/button/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/button/layout';
|
||||
|
||||
// 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 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_NEUTRAL */
|
||||
public const ENUM_COLOR_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_VALIDATION */
|
||||
public const ENUM_COLOR_VALIDATION = 'success';
|
||||
/** @var string ENUM_COLOR_DESTRUCTIVE */
|
||||
public const ENUM_COLOR_DESTRUCTIVE = 'danger';
|
||||
/** @var string ENUM_COLOR_PRIMARY */
|
||||
public const ENUM_COLOR_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SECONDARY */
|
||||
public const ENUM_COLOR_SECONDARY = 'secondary';
|
||||
/** @var string ENUM_COLOR_GREEN */
|
||||
public const ENUM_COLOR_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_RED */
|
||||
public const ENUM_COLOR_RED = 'red';
|
||||
/** @var string ENUM_COLOR_CYAN */
|
||||
public const ENUM_COLOR_CYAN = 'cyan';
|
||||
/** @var string DEFAULT_COLOR */
|
||||
public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
|
||||
|
||||
/** @var string $sLabel */
|
||||
protected $sLabel;
|
||||
/** @var string $sType The HTML type of the button (eg. 'submit', 'button', ...) */
|
||||
protected $sType;
|
||||
/** @var string $sName The HTML name of the button, used by forms */
|
||||
protected $sName;
|
||||
/** @var string $sValue The HTML value of the button, used by forms */
|
||||
protected $sValue;
|
||||
/** @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 bool $bIsDisabled */
|
||||
protected $bIsDisabled;
|
||||
/** @var string $sJsCode */
|
||||
protected $sJsCode;
|
||||
/** @var string $sOnClickJsCode */
|
||||
protected $sOnClickJsCode;
|
||||
/** @var array */
|
||||
protected $aAdditionalCSSClasses;
|
||||
|
||||
/**
|
||||
* Button 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, string $sJsCode = '',
|
||||
string $sOnClickJsCode = ''
|
||||
) {
|
||||
$this->sLabel = $sLabel;
|
||||
$this->sName = $sName;
|
||||
$this->sValue = $sValue;
|
||||
$this->sType = $sType;
|
||||
$this->sTooltip = $sTooltip;
|
||||
$this->sIconClass = $sIconClass;
|
||||
$this->sActionType = $sActionType;
|
||||
$this->sColor = $sColor;
|
||||
$this->sJsCode = $sJsCode;
|
||||
$this->sOnClickJsCode = $sOnClickJsCode;
|
||||
$this->bIsDisabled = false;
|
||||
$this->aAdditionalCSSClasses = [];
|
||||
|
||||
parent::__construct($sId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel()
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel(string $sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetType()
|
||||
{
|
||||
return $this->sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetType(string $sType)
|
||||
{
|
||||
$this->sType = $sType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetName()
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetName(string $sName)
|
||||
{
|
||||
$this->sName = $sName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue()
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValue(string $sValue)
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTooltip()
|
||||
{
|
||||
return $this->sTooltip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTooltip
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTooltip(string $sTooltip)
|
||||
{
|
||||
$this->sTooltip = $sTooltip;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconClass()
|
||||
{
|
||||
return $this->sIconClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconClass
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIconClass(string $sIconClass)
|
||||
{
|
||||
$this->sIconClass = $sIconClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetActionType()
|
||||
{
|
||||
return $this->sActionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sActionType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetActionType(string $sActionType)
|
||||
{
|
||||
$this->sActionType = $sActionType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor()
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColor(string $sColor)
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDisabled()
|
||||
{
|
||||
return $this->bIsDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIsDisabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIsDisabled(bool $bIsDisabled)
|
||||
{
|
||||
$this->bIsDisabled = $bIsDisabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetOnClickJsCode()
|
||||
{
|
||||
return $this->sOnClickJsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sOnClickJsCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOnClickJsCode(string $sOnClickJsCode)
|
||||
{
|
||||
$this->sOnClickJsCode = $sOnClickJsCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetJsCode()
|
||||
{
|
||||
return $this->sJsCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sJsCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetJsCode(string $sJsCode)
|
||||
{
|
||||
$this->sJsCode = $sJsCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAdditionalCSSClass(): string
|
||||
{
|
||||
return implode(' ', $this->aAdditionalCSSClasses);
|
||||
}
|
||||
|
||||
public function AddCSSClasses(string $sCSSClasses): self
|
||||
{
|
||||
foreach (explode(' ', $sCSSClasses) as $sCSSClass) {
|
||||
if (!empty($sCSSClass)) {
|
||||
$this->aAdditionalCSSClasses[$sCSSClass] = $sCSSClass;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
370
sources/application/UI/Base/Component/Button/ButtonFactory.php
Normal file
370
sources/application/UI/Base/Component/Button/ButtonFactory.php
Normal file
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 ButtonFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Button
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-buttons to see live examples
|
||||
*/
|
||||
class ButtonFactory
|
||||
{
|
||||
//---------------------------------------------
|
||||
// Regular action buttons, mostly used in forms
|
||||
//---------------------------------------------
|
||||
|
||||
/**
|
||||
* Make a basis Button component for any purpose
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param string $sName See Button::$sName
|
||||
* @param string|null $sId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
|
||||
*/
|
||||
public static function MakeNeutral(string $sLabel, string $sName, ?string $sId = null): Button {
|
||||
$oButton = new Button($sLabel, $sId);
|
||||
$oButton->SetActionType(Button::ENUM_ACTION_TYPE_REGULAR)
|
||||
->SetColor(Button::ENUM_COLOR_NEUTRAL)
|
||||
->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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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 $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,
|
||||
string $sValue = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_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
|
||||
): Button {
|
||||
return static::MakeForAction($sLabel, Button::ENUM_COLOR_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
|
||||
$bIsSubmit, $sId);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// 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 $sName See Button::$sName
|
||||
* @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 = null, ?string $sIconClasses = null, ?string $sName = null, ?string $sTarget = null,
|
||||
?string $sId = null
|
||||
): Button
|
||||
{
|
||||
$sType = empty($sIconClasses) ? Button::ENUM_ACTION_TYPE_REGULAR : Button::ENUM_ACTION_TYPE_ALTERNATIVE;
|
||||
$oButton = static::MakeForAction($sLabel, Button::ENUM_COLOR_NEUTRAL, $sType, null, $sName, false, $sId);
|
||||
|
||||
if (!empty($sIconClasses)) {
|
||||
$oButton->SetIconClass($sIconClasses);
|
||||
}
|
||||
|
||||
if (!empty($sURL)) {
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = "_self";
|
||||
}
|
||||
$oButton->SetOnClickJsCode("window.open('{$sURL}', '{$sTarget}');");
|
||||
}
|
||||
|
||||
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 MakeIconLink(
|
||||
string $sIconClasses, string $sTooltipText, ?string $sURL = null, ?string $sName = null, ?string $sTarget = null,
|
||||
?string $sId = null
|
||||
)
|
||||
{
|
||||
$oButton = static::MakeForAction('', Button::ENUM_COLOR_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, null, $sName, false, $sId);
|
||||
$oButton->SetIconClass($sIconClasses);
|
||||
$oButton->SetTooltip($sTooltipText);
|
||||
|
||||
if (!empty($sURL)) {
|
||||
if (empty($sTarget)) {
|
||||
$sTarget = "_self";
|
||||
}
|
||||
$oButton->SetOnClickJsCode("window.open('{$sURL}', '{$sTarget}');");
|
||||
}
|
||||
|
||||
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\Button
|
||||
* @internal
|
||||
*/
|
||||
protected static function MakeForAction(
|
||||
string $sLabel,
|
||||
string $sColor,
|
||||
string $sActionType,
|
||||
string $sValue = null,
|
||||
string $sName = null,
|
||||
bool $bIsSubmit = false,
|
||||
?string $sId = null
|
||||
): Button {
|
||||
$oButton = new Button($sLabel, $sId);
|
||||
$oButton->SetActionType($sActionType)
|
||||
->SetColor($sColor);
|
||||
|
||||
if (empty($sValue) === false) {
|
||||
$oButton->SetValue($sValue);
|
||||
}
|
||||
|
||||
if (empty($sName) === false) {
|
||||
$oButton->SetName($sName);
|
||||
}
|
||||
|
||||
// Set as submit button if necessary
|
||||
if ($bIsSubmit === true) {
|
||||
$oButton->SetType(Button::ENUM_TYPE_SUBMIT);
|
||||
}
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
}
|
||||
168
sources/application/UI/Base/Component/Dashlet/DashletBadge.php
Normal file
168
sources/application/UI/Base/Component/Dashlet/DashletBadge.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
class DashletBadge extends DashletContainer
|
||||
{
|
||||
public const BLOCK_CODE = 'ibo-dashlet-badge';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashletbadge';
|
||||
|
||||
/** @var string */
|
||||
protected $sClassIconUrl;
|
||||
/** @var string */
|
||||
protected $sHyperlink;
|
||||
/** @var string */
|
||||
protected $iCount;
|
||||
/** @var string */
|
||||
protected $sClassLabel;
|
||||
|
||||
/** @var string */
|
||||
protected $sCreateActionUrl;
|
||||
/** @var string */
|
||||
protected $sCreateActionLabel;
|
||||
|
||||
/**
|
||||
* DashletBadge constructor.
|
||||
*
|
||||
* @param string $sClassIconUrl
|
||||
* @param string $sHyperlink
|
||||
* @param string $iCount
|
||||
* @param string $sClassLabel
|
||||
* @param string $sCreateActionUrl
|
||||
* @param string $sCreateActionLabel
|
||||
*/
|
||||
public function __construct(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->sClassIconUrl = $sClassIconUrl;
|
||||
$this->sHyperlink = $sHyperlink;
|
||||
$this->iCount = $iCount;
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
$this->sCreateActionUrl = $sCreateActionUrl;
|
||||
$this->sCreateActionLabel = $sCreateActionLabel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCreateActionUrl(): string
|
||||
{
|
||||
return $this->sCreateActionUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCreateActionUrl
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCreateActionUrl(string $sCreateActionUrl): DashletBadge
|
||||
{
|
||||
$this->sCreateActionUrl = $sCreateActionUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCreateActionLabel(): string
|
||||
{
|
||||
return $this->sCreateActionLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCreateActionLabel
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCreateActionLabel(string $sCreateActionLabel): DashletBadge
|
||||
{
|
||||
$this->sCreateActionLabel = $sCreateActionLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetClassIconUrl(): string
|
||||
{
|
||||
return $this->sClassIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sClassIconUrl
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetClassIconUrl(string $sClassIconUrl): DashletBadge
|
||||
{
|
||||
$this->sClassIconUrl = $sClassIconUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetHyperlink(): string
|
||||
{
|
||||
return $this->sHyperlink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sHyperlink
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetHyperlink(string $sHyperlink): DashletBadge
|
||||
{
|
||||
$this->sHyperlink = $sHyperlink;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetCount(): string
|
||||
{
|
||||
return $this->iCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iCount
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetCount(string $iCount): DashletBadge
|
||||
{
|
||||
$this->iCount = $iCount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetClassLabel(): string
|
||||
{
|
||||
return $this->sClassLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sClassLabel
|
||||
*
|
||||
* @return DashletBadge
|
||||
*/
|
||||
public function SetClassLabel(string $sClassLabel): DashletBadge
|
||||
{
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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 HTML_TEMPLATE_REL_PATH = 'base/layouts/content-block/layout';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
class DashletFactory
|
||||
{
|
||||
public static function MakeForDashletBadge(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
|
||||
{
|
||||
return new DashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel);
|
||||
}
|
||||
|
||||
public static function MakeForDashletHeaderStatic(string $sTitle, string $sIconUrl)
|
||||
{
|
||||
return new DashletHeaderStatic(null, $sTitle, $sIconUrl);
|
||||
}
|
||||
|
||||
public static function MakeForDashletText(string $sId, string $sText)
|
||||
{
|
||||
return new DashletHeaderStatic($sId, '', '', $sText);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
class DashletHeaderStatic extends DashletContainer
|
||||
{
|
||||
public const BLOCK_CODE = 'ibo-dashlet-header-static';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/dashlet/dashletheaderstatic';
|
||||
|
||||
/** @var string */
|
||||
protected $sTitle;
|
||||
/** @var string */
|
||||
protected $sIconUrl;
|
||||
/** @var string */
|
||||
protected $sText;
|
||||
|
||||
/**
|
||||
* DashletHeaderStatic constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sIconUrl
|
||||
* @param string $sText
|
||||
*/
|
||||
public function __construct(string $sId = null, string $sTitle, string $sIconUrl, string $sText = '')
|
||||
{
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->sTitle = $sTitle;
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
$this->sText = $sText;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle(): string
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return DashletHeaderStatic
|
||||
*/
|
||||
public function SetTitle(string $sTitle): DashletHeaderStatic
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconUrl(): string
|
||||
{
|
||||
return $this->sIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconUrl
|
||||
*
|
||||
* @return DashletHeaderStatic
|
||||
*/
|
||||
public function SetIconUrl(string $sIconUrl): DashletHeaderStatic
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetText(): string
|
||||
{
|
||||
return $this->sText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sText
|
||||
*
|
||||
* @return DashletHeaderStatic
|
||||
*/
|
||||
public function SetText(string $sText): DashletHeaderStatic
|
||||
{
|
||||
$this->sText = $sText;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
138
sources/application/UI/Base/Component/DataTable/DataTable.php
Normal file
138
sources/application/UI/Base/Component/DataTable/DataTable.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use DataTableConfig;
|
||||
|
||||
/**
|
||||
* Class DataTable
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\DataTable
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class DataTableBlock extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatable';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/datatable/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/datatable/layout';
|
||||
|
||||
protected $aOptions;//list of specific options for display datatable
|
||||
protected $sAjaxUrl;
|
||||
protected $sAjaxData;
|
||||
protected $aDisplayColumns;
|
||||
protected $aResultColumns;
|
||||
|
||||
/**
|
||||
* Panel constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->AddDeferredBlock(new DataTableConfig($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetAjaxUrl(): string
|
||||
{
|
||||
return $this->sAjaxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sAjaxUrl
|
||||
*/
|
||||
public function SetAjaxUrl(string $sAjaxUrl): void
|
||||
{
|
||||
$this->sAjaxUrl = $sAjaxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetAjaxData(): string
|
||||
{
|
||||
return $this->sAjaxData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sAjaxData
|
||||
*/
|
||||
public function SetAjaxData(string $sAjaxData): void
|
||||
{
|
||||
$this->sAjaxData = $sAjaxData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
class DataTableConfig extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatableconfig';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/datatable/config/layout';
|
||||
|
||||
/** @var DataTableBlock */
|
||||
private $oDataTable;
|
||||
|
||||
public function __construct(DataTableBlock $oDataTable, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->oDataTable = $oDataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableBlock
|
||||
*/
|
||||
private function GetDataTable(): DataTableBlock
|
||||
{
|
||||
return $this->oDataTable;
|
||||
}
|
||||
|
||||
public function GetOption(string $sOption)
|
||||
{
|
||||
return $this->GetDataTable()->GetOption($sOption);
|
||||
}
|
||||
|
||||
public function GetTableId()
|
||||
{
|
||||
return $this->GetDataTable()->GetId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,725 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
|
||||
|
||||
use ApplicationException;
|
||||
use appUserPreferences;
|
||||
use AttributeLinkedSet;
|
||||
use cmdbAbstractObject;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\FormTable\FormTable;
|
||||
use Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable\StaticTable;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Title\TitleFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use DBObjectSet;
|
||||
use Dict;
|
||||
use MenuBlock;
|
||||
use MetaModel;
|
||||
use UserRights;
|
||||
use utils;
|
||||
use WebPage;
|
||||
|
||||
/**
|
||||
* Class DataTableFactory
|
||||
*
|
||||
* @internal
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\DataTable
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class DataTableFactory
|
||||
{
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
* @param \DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
* @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())
|
||||
{
|
||||
$oPanel = PanelFactory::MakeForClass($oSet->GetClass(), "Result")->AddCSSClasses('ibo-datatable-panel');
|
||||
$oDataTable = DataTableFactory::MakeForRendering($sListId, $oSet, $aExtraParams);
|
||||
$oPanel->AddMainBlock($oDataTable);
|
||||
|
||||
$oMenuBlock = new MenuBlock($oSet->GetFilter(), 'list');
|
||||
$oBlock = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $sListId);
|
||||
$oBlockMenu = new UIContentBlock();
|
||||
$oBlockMenu->AddSubBlock($oBlock);
|
||||
$oPanel->AddToolbarBlock($oBlockMenu);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
* @param DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
* @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())
|
||||
{
|
||||
$oPanel = PanelFactory::MakeForClass($oSet->GetClass(), "Result");
|
||||
$oDataTable = DataTableFactory::MakeForRenderingObject($sListId, $oSet, $aExtraParams);
|
||||
$oPanel->AddMainBlock($oDataTable);
|
||||
|
||||
$oMenuBlock = new MenuBlock($oSet->GetFilter(), 'listInObject');
|
||||
$oBlock = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $sListId);
|
||||
$oBlockMenu = new UIContentBlock();
|
||||
$oBlockMenu->AddSubBlock($oBlock);
|
||||
$oPanel->AddToolbarBlock($oBlockMenu);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a basis Panel component
|
||||
*
|
||||
* @param string $sListId
|
||||
* @param \DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return DataTableBlock
|
||||
* @throws \ApplicationException
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function MakeForRendering(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = new DataTableBlock('datatable_'.$sListId);
|
||||
///////////////////////////////////////////////////
|
||||
/*TODO 3.0.0 PrintableVersion
|
||||
if ($oPage->IsPrintableVersion() || $oPage->is_pdf())
|
||||
{
|
||||
return self::GetDisplaySetForPrinting($oPage, $oSet, $aExtraParams);
|
||||
}
|
||||
*/
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->OptimizeColumnLoad($aColumnsToLoad);
|
||||
$aSortOrder=[];
|
||||
$aSortDatable=[];
|
||||
$aColumnDefinition = [];
|
||||
$iIndexColumn=0;
|
||||
if($sSelectMode!="") {
|
||||
$iIndexColumn++;
|
||||
}
|
||||
foreach ($aClassAliases as $sClassAlias => $sClassName) {
|
||||
foreach ($oCustomSettings->aColumns[$sClassAlias] as $sAttCode => $aData) {
|
||||
if ($aData['sort'] != 'none') {
|
||||
$sCode = ($aData['code'] == '_key_') ? 'friendlyname' : $aData['code'];
|
||||
$aSortOrder[$sAlias.$sCode] = ($aData['sort'] == 'asc'); // true for ascending, false for descending
|
||||
$aSortDatable=[$iIndexColumn,$aData['sort']];
|
||||
}
|
||||
if ($aData['checked']) {
|
||||
if ($sAttCode == '_key_') {
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $aData['label'],
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => $aData['alias'],
|
||||
"render" => "return '<a class=\'object-ref-link\' href= \'UI.php?operation=details&class=".$sClassName."&id='+data+'\'>'+row['".$sClassAlias."/friendlyname']+'</a>' ;",
|
||||
];
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
$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($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['iPageSize'] = 10;
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$aOptions['iPageSize'] = $oCustomSettings->iDefaultPageSize;
|
||||
}
|
||||
|
||||
$aOptions['sTableId'] = $sTableId;
|
||||
$aOptions['bUseCustomSettings'] = $bUseCustomSettings;
|
||||
$aOptions['bViewLink'] = $bViewLink;
|
||||
$aOptions['sListId'] = $sListId;
|
||||
$aOptions['oClassAliases'] = json_encode($aClassAliases);
|
||||
|
||||
$oDataTable->SetOptions($aOptions);
|
||||
$oDataTable->SetAjaxUrl(utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php");
|
||||
$oDataTable->SetAjaxData(json_encode([
|
||||
"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);
|
||||
|
||||
return $oDataTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sListId
|
||||
* @param DBObjectSet $oSet
|
||||
* @param array $aExtraParams
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableBlock
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public static function MakeForRenderingObject(string $sListId, DBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
$oDataTable = new DataTableBlock('datatable_'.$sListId);
|
||||
$aList = array();
|
||||
|
||||
// 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]);
|
||||
}
|
||||
}
|
||||
|
||||
$sSelectMode = 'none';
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oSet->OptimizeColumnLoad($aColumnsToLoad);
|
||||
|
||||
$aColumnDefinition = [];
|
||||
$aSortOrder = [];
|
||||
$iIndexColumn = 0;
|
||||
if ($sSelectMode != "") {
|
||||
$iIndexColumn++;
|
||||
}
|
||||
$aSortDatable = [];
|
||||
foreach ($aAuthorizedClasses as $sClassAlias => $sClassName) {
|
||||
foreach ($oCustomSettings->aColumns[$sClassAlias] as $sAttCode => $aData) {
|
||||
if ($aData['sort'] != 'none') {
|
||||
$sCode = ($aData['code'] == '_key_') ? 'friendlyname' : $aData['code'];
|
||||
$aSortOrder[$sAlias.$sCode] = ($aData['sort'] == 'asc'); // true for ascending, false for descending
|
||||
$aSortDatable = [$iIndexColumn, $aData['sort']];
|
||||
}
|
||||
if ($aData['checked']) {
|
||||
if ($sAttCode == '_key_') {
|
||||
$aColumnDefinition[] = [
|
||||
'description' => $aData['label'],
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => $aData['alias'],
|
||||
"render" => "return '<a class=\'object-ref-link\' href= \'UI.php?operation=details&class=".$sClassName."&id='+data+'\'>'+row['".$sClassAlias."/friendlyname']+'</a>' ;",
|
||||
];
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
$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['sort'] = $aSortDatable;
|
||||
|
||||
$aOptions['iPageSize'] = 10;
|
||||
if ($oCustomSettings->iDefaultPageSize > 0) {
|
||||
$aOptions['iPageSize'] = $oCustomSettings->iDefaultPageSize;
|
||||
}
|
||||
|
||||
$aOptions['sTableId'] = $sTableId;
|
||||
$aOptions['bUseCustomSettings'] = $bUseCustomSettings;
|
||||
$aOptions['bViewLink'] = $bViewLink;
|
||||
$aOptions['oClassAliases'] = json_encode($aClassAliases);
|
||||
|
||||
$oDataTable->SetOptions($aOptions);
|
||||
$oDataTable->SetAjaxUrl("ajax.render.php");
|
||||
$oDataTable->SetAjaxData(json_encode([
|
||||
"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);
|
||||
|
||||
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)
|
||||
{
|
||||
$aOptions = [];
|
||||
$sTableId=$aExtraParams["table_id"];
|
||||
$aColumnsDefinitions = [];
|
||||
$aColumnDefinition = [];
|
||||
|
||||
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);\" 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\" /></span>');";
|
||||
}
|
||||
else {
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"radio\" class=\"selectList".$sTableId."\" name=\"selectObject\" /></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_') {
|
||||
$aColumnDefinition["title"] = $aData['alias'];
|
||||
$aColumnDefinition['metadata'] = [
|
||||
'object_class' => $sClassName,
|
||||
'class_alias' => $sClassAlias,
|
||||
'attribute_code' => $sAttCode,
|
||||
'attribute_type' => '_key_',
|
||||
'attribute_label' => $aData['alias'],
|
||||
];
|
||||
$aColumnDefinition["data"] = $sClassAlias."/".$sAttCode;
|
||||
$aColumnDefinition["render"] = [
|
||||
"display" => "return '<a class=\'object-ref-link\' href=\'UI.php?operation=details&class=".$sClassName."&id='+data+'\'>'+row['".$sClassAlias."/friendlyname']+'</a>' ;",
|
||||
"_" => $sClassAlias."/".$sAttCode,
|
||||
];
|
||||
} else {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
|
||||
$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,
|
||||
];
|
||||
}
|
||||
array_push($aColumnsDefinitions, $aColumnDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aOptions['select'] = ["style"=>$sSelectMode];
|
||||
|
||||
$aOptions['pageLength'] = $iLength;
|
||||
|
||||
$sAjaxData = json_encode([
|
||||
"operation" => 'search',
|
||||
"filter" => $sFilter,
|
||||
"columns" => $aColumns,
|
||||
"extra_params" => $aExtraParams,
|
||||
"class_aliases" => $aClassAliases,
|
||||
"select_mode" => $sSelectMode,
|
||||
]);
|
||||
|
||||
|
||||
$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'pil>t<'ibo-datatable-toolbar'pil>",
|
||||
"ordering"=>true,
|
||||
"order" => [],
|
||||
"filter" => false,
|
||||
"processing" => true,
|
||||
"serverSide" => true,
|
||||
"columns" => $aColumnsDefinitions,
|
||||
"allColumns" => $aColumns,
|
||||
'ajax' => '$.fn.dataTable.pipeline( {
|
||||
"url": "ajax.render.php",
|
||||
"data": '.$sAjaxData.',
|
||||
"method": "post",
|
||||
"pages": 5 // number of pages to cache
|
||||
} )'
|
||||
]);
|
||||
|
||||
return $aOptions;
|
||||
}
|
||||
|
||||
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null)
|
||||
{
|
||||
$oBlock = new UIContentBlock();
|
||||
$oTitle = TitleFactory::MakeNeutral($sTitle, 3);
|
||||
$oBlock->AddSubBlock($oTitle);
|
||||
$oTable = new StaticTable($sId);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetData($aData);
|
||||
$oBlock->AddSubBlock($oTable);
|
||||
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
public Static function MakeForForm(string $sRef, array $aColumns): FormTable
|
||||
{
|
||||
$oTable = new FormTable($sRef);
|
||||
$oTable->SetColumns($aColumns);
|
||||
|
||||
return $oTable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
<?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();
|
||||
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' => true,
|
||||
'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,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtable/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtable/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
|
||||
/** @var iUIBlock[] */
|
||||
private $aRows;
|
||||
|
||||
public function __construct(string $sRef, string $sContainerCSSClass = '')
|
||||
{
|
||||
parent::__construct("dt_{$sRef}", $sContainerCSSClass);
|
||||
$this->SetRef($sRef);
|
||||
$this->aRows = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRef(): string
|
||||
{
|
||||
return $this->sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRef
|
||||
*/
|
||||
public function SetRef(string $sRef): void
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
}
|
||||
|
||||
public function GetRows(): array
|
||||
{
|
||||
return $this->aRows;
|
||||
}
|
||||
|
||||
public function AddRow(FormTableRow $oRow): self
|
||||
{
|
||||
$this->aRows[] = $oRow;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtablerow/layout';
|
||||
public const JS_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
|
||||
*/
|
||||
public function SetRef(string $sRef): void
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetColumns(): array
|
||||
{
|
||||
return $this->aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
*/
|
||||
public function SetColumns(array $aColumns): void
|
||||
{
|
||||
$this->aColumns = $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetData(): array
|
||||
{
|
||||
return $this->aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aData
|
||||
*/
|
||||
public function SetData(array $aData): void
|
||||
{
|
||||
$this->aData = $aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetRowId(): int
|
||||
{
|
||||
return $this->iRowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iRowId
|
||||
*/
|
||||
public function SetRowId(int $iRowId): void
|
||||
{
|
||||
$this->iRowId = $iRowId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tables with static data
|
||||
* Class StaticTable
|
||||
*/
|
||||
class StaticTable extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatable';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/datatable/static/layout';
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
public function __construct(string $sId = null, string $sContainerCSSClass = '')
|
||||
{
|
||||
parent::__construct($sId, $sContainerCSSClass);
|
||||
$this->aColumns = [];
|
||||
$this->aData = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetColumns(): array
|
||||
{
|
||||
return $this->aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
*/
|
||||
public function SetColumns(array $aColumns): void
|
||||
{
|
||||
$this->aColumns = $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetData(): array
|
||||
{
|
||||
return $this->aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aData
|
||||
*/
|
||||
public function SetData(array $aData): void
|
||||
{
|
||||
$this->aData = $aData;
|
||||
}
|
||||
|
||||
}
|
||||
46
sources/application/UI/Base/Component/Field/Field.php
Normal file
46
sources/application/UI/Base/Component/Field/Field.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Field;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Field
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Field
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @author Anne-Catherine Cognet <annecatherine.cognet@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class Field extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
/** @inheritdoc */
|
||||
public const BLOCK_CODE = 'ibo-field';
|
||||
/** @inheritdoc */
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/field/layout';
|
||||
|
||||
/** @var array Array of various parameters of the field. This should be exploded in dedicated properties instead of a grey array. */
|
||||
protected $aParams;
|
||||
|
||||
public function __construct(array $aParams, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->aParams = $aParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
public function GetParams(): array
|
||||
{
|
||||
return $this->aParams;
|
||||
}
|
||||
|
||||
}
|
||||
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-2020 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 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;
|
||||
}
|
||||
|
||||
}
|
||||
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-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/form/layout';
|
||||
|
||||
/** @var string */
|
||||
protected $sOnSubmitJsCode;
|
||||
/** @var string */
|
||||
protected $sAction;
|
||||
|
||||
public function __construct(string $sName = null)
|
||||
{
|
||||
parent::__construct($sName);
|
||||
$this->sOnSubmitJsCode = null;
|
||||
$this->sAction = null;
|
||||
}
|
||||
|
||||
public function SetOnSubmitJsCode(string $sJsCode): Form
|
||||
{
|
||||
$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): Form
|
||||
{
|
||||
$this->sAction = $sAction;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 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
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-global-search';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/global-search/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/global-search/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/components/global-search.js',
|
||||
];
|
||||
|
||||
public const DEFAULT_ENDPOINT_REL_URL = 'pages/UI.php?operation=full_text';
|
||||
|
||||
/** @var string $sEndpoint Absolute endpoint URL of the search form */
|
||||
protected $sEndpoint;
|
||||
/** @var array $aLastQueries */
|
||||
protected $aLastQueries;
|
||||
/** @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->SetLastQueries($aLastQueries);
|
||||
$this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.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()
|
||||
{
|
||||
return $this->sEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return $this->aLastQueries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxHistoryResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxHistoryResults(): int
|
||||
{
|
||||
return $this->iMaxHistoryResults;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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++)
|
||||
{
|
||||
// Add HTML label if missing
|
||||
if(!isset($aHistoryEntries[$iIdx]['label_html']))
|
||||
{
|
||||
$aHistoryEntries[$iIdx]['label_html'] = utils::HtmlEntities($aHistoryEntries[$iIdx]['query']);
|
||||
}
|
||||
|
||||
// Set absolute URL
|
||||
if(isset($aHistoryEntries[$iIdx]['icon_url']))
|
||||
{
|
||||
$aHistoryEntries[$iIdx]['icon_url'] = utils::GetAbsoluteUrlAppRoot().$aHistoryEntries[$iIdx]['icon_url'];
|
||||
}
|
||||
}
|
||||
|
||||
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-2020 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 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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
90
sources/application/UI/Base/Component/Input/Input.php
Normal file
90
sources/application/UI/Base/Component/Input/Input.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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;
|
||||
|
||||
/**
|
||||
* Class Input
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Input
|
||||
*/
|
||||
class Input extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-input';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/input/layout';
|
||||
|
||||
public const INPUT_HIDDEN = 'hidden';
|
||||
|
||||
/** @var string */
|
||||
protected $sType;
|
||||
/** @var string */
|
||||
protected $sName;
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetType(): string
|
||||
{
|
||||
return $this->sType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sType
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetType(string $sType): Input
|
||||
{
|
||||
$this->sType = $sType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetName(): string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetName(string $sName): Input
|
||||
{
|
||||
$this->sName = $sName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return Input
|
||||
*/
|
||||
public function SetValue(string $sValue): Input
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
56
sources/application/UI/Base/Component/Input/InputFactory.php
Normal file
56
sources/application/UI/Base/Component/Input/InputFactory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Component\Input\Select\Select;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOption;
|
||||
|
||||
class InputFactory
|
||||
{
|
||||
|
||||
public static function MakeForHidden(string $sName, string $sValue, ?string $sId = null): Input
|
||||
{
|
||||
$oInput = new Input($sId);
|
||||
|
||||
$oInput->SetType(Input::INPUT_HIDDEN)
|
||||
->SetName($sName)
|
||||
->SetValue($sValue);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
public static function MakeForSelectWithLabel(string $sName, string $sLabel, ?string $sId = null): InputWithLabel
|
||||
{
|
||||
$oInput = new Select();
|
||||
$oInput->SetName($sName);
|
||||
|
||||
$oInputWithLabel = new InputWithLabel($sLabel, $oInput, $sId);
|
||||
|
||||
return $oInputWithLabel;
|
||||
}
|
||||
public static function MakeForSelect(string $sName, ?string $sId = null): Select
|
||||
{
|
||||
$oInput = new Select($sId);
|
||||
$oInput->SetName($sName);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
public static function MakeForSelectOption(string $sValue, string $sLabel, bool $bSelected, ?string $sId = null): SelectOption
|
||||
{
|
||||
$oInput = new SelectOption($sId);
|
||||
|
||||
$oInput->SetValue($sValue)
|
||||
->SetLabel($sLabel)
|
||||
->SetSelected($bSelected);
|
||||
|
||||
return $oInput;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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;
|
||||
|
||||
class InputWithLabel extends UIBlock
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/input/inputwithlabel';
|
||||
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var \Combodo\iTop\Application\UI\Base\Component\Input\Input */
|
||||
protected $oInput;
|
||||
|
||||
/**
|
||||
* InputWithLabel constructor.
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput
|
||||
*/
|
||||
public function __construct(string $sLabel, \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput, ?string $sId)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sLabel = $sLabel;
|
||||
$this->oInput = $oInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Input\Input
|
||||
*/
|
||||
public function GetInput(): \Combodo\iTop\Application\UI\Base\Component\Input\Input
|
||||
{
|
||||
return $this->oInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetInput(\Combodo\iTop\Application\UI\Base\Component\Input\Input $oInput): InputWithLabel
|
||||
{
|
||||
$this->oInput = $oInput;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return InputWithLabel
|
||||
*/
|
||||
public function SetLabel(string $sLabel): InputWithLabel
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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;
|
||||
|
||||
/**
|
||||
* Class RichText
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\RichText
|
||||
*/
|
||||
class RichText extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-richtext';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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\Input;
|
||||
|
||||
class Select extends Input
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/input/select/select';
|
||||
|
||||
/** @var array */
|
||||
protected $aOptions;
|
||||
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->aOptions = [];
|
||||
}
|
||||
|
||||
public function AddOption(SelectOption $oOption)
|
||||
{
|
||||
$this->aOptions[$oOption->GetId()] = $oOption;
|
||||
}
|
||||
|
||||
public function GetSubBlocks()
|
||||
{
|
||||
return $this->aOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/input/select/selectoption';
|
||||
|
||||
/** @var string */
|
||||
protected $sValue;
|
||||
/** @var string */
|
||||
protected $sLabel;
|
||||
/** @var bool */
|
||||
protected $bSelected;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetValue(): string
|
||||
{
|
||||
return $this->sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetValue(string $sValue): SelectOption
|
||||
{
|
||||
$this->sValue = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel(): string
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLabel
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetLabel(string $sLabel): SelectOption
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSelected(): bool
|
||||
{
|
||||
return $this->bSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bSelected
|
||||
*
|
||||
* @return SelectOption
|
||||
*/
|
||||
public function SetSelected(bool $bSelected): SelectOption
|
||||
{
|
||||
$this->bSelected = $bSelected;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
355
sources/application/UI/Base/Component/Panel/Panel.php
Normal file
355
sources/application/UI/Base/Component/Panel/Panel.php
Normal file
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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;
|
||||
|
||||
/**
|
||||
* 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';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/panel/layout';
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_COLOR_PRIMARY */
|
||||
public const ENUM_COLOR_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SECONDARY */
|
||||
public const ENUM_COLOR_SECONDARY = 'secondary';
|
||||
|
||||
/** @var string ENUM_COLOR_NEUTRAL */
|
||||
public const ENUM_COLOR_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_INFORMATION */
|
||||
public const ENUM_COLOR_INFORMATION = 'information';
|
||||
/** @var string ENUM_COLOR_SUCCESS */
|
||||
public const ENUM_COLOR_SUCCESS = 'success';
|
||||
/** @var string ENUM_COLOR_FAILURE */
|
||||
public const ENUM_COLOR_FAILURE = 'failure';
|
||||
/** @var string ENUM_COLOR_WARNING */
|
||||
public const ENUM_COLOR_WARNING = 'warning';
|
||||
/** @var string ENUM_COLOR_DANGER */
|
||||
public const ENUM_COLOR_DANGER = 'danger';
|
||||
|
||||
/** @var string ENUM_COLOR_GREY */
|
||||
public const ENUM_COLOR_GREY = 'grey';
|
||||
/** @var string ENUM_COLOR_BLUEGREY */
|
||||
public const ENUM_COLOR_BLUEGREY = 'blue-grey';
|
||||
/** @var string ENUM_COLOR_BLUE */
|
||||
public const ENUM_COLOR_BLUE = 'blue';
|
||||
/** @var string ENUM_COLOR_CYAN */
|
||||
public const ENUM_COLOR_CYAN = 'cyan';
|
||||
/** @var string ENUM_COLOR_GREEN */
|
||||
public const ENUM_COLOR_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_ORANGE */
|
||||
public const ENUM_COLOR_ORANGE = 'orange';
|
||||
/** @var string ENUM_COLOR_RED */
|
||||
public const ENUM_COLOR_RED = 'red';
|
||||
/** @var string ENUM_COLOR_PINK */
|
||||
public const ENUM_COLOR_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 DEFAULT_COLOR */
|
||||
public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
|
||||
|
||||
/** @var string $sTitle */
|
||||
protected $sTitle;
|
||||
/** @var string $sColor */
|
||||
protected $sColor;
|
||||
|
||||
/**
|
||||
* Panel constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock[] $aSubBlocks
|
||||
* @param string $sColor
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(string $sTitle = '', array $aSubBlocks = [], string $sColor = self::DEFAULT_COLOR, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sTitle = $sTitle;
|
||||
$this->aSubBlocks = $aSubBlocks;
|
||||
$this->sColor = $sColor;
|
||||
$this->SetMainBlocks([]);
|
||||
$this->SetToolBlocks([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle()
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTitle(string $sTitle)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetColor()
|
||||
{
|
||||
return $this->sColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sColor
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetColor(string $sColor)
|
||||
{
|
||||
$this->sColor = $sColor;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$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,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Panel;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
|
||||
class PanelEnhanced extends Panel
|
||||
{
|
||||
public const BLOCK_CODE = 'ibo-panel-enhanced';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/panel/panelenhanced';
|
||||
|
||||
/** @var UIContentBlock */
|
||||
protected $sSubTitle;
|
||||
/** @var string */
|
||||
protected $sIconUrl;
|
||||
|
||||
/**
|
||||
* PanelEnhanced constructor.
|
||||
*
|
||||
* @param $sTitle
|
||||
* @param $sIconUrl
|
||||
*/
|
||||
public function __construct(string $sTitle, string $sIconUrl)
|
||||
{
|
||||
parent::__construct($sTitle);
|
||||
$this->sSubTitle = new UIContentBlock();
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UIContentBlock
|
||||
*/
|
||||
public function GetSubTitle(): UIContentBlock
|
||||
{
|
||||
return $this->sSubTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UIContentBlock $sSubTitle
|
||||
*
|
||||
* @return PanelEnhanced
|
||||
*/
|
||||
public function SetSubTitle(UIContentBlock $sSubTitle): PanelEnhanced
|
||||
{
|
||||
$this->sSubTitle = $sSubTitle;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetIconUrl(): string
|
||||
{
|
||||
return $this->sIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sIconUrl
|
||||
*
|
||||
* @return PanelEnhanced
|
||||
*/
|
||||
public function SetIconUrl(string $sIconUrl): PanelEnhanced
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
188
sources/application/UI/Base/Component/Panel/PanelFactory.php
Normal file
188
sources/application/UI/Base/Component/Panel/PanelFactory.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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;
|
||||
|
||||
/**
|
||||
* Class PanelFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Panel
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-panels to see live examples
|
||||
*/
|
||||
class PanelFactory
|
||||
{
|
||||
/**
|
||||
* Make a basis Panel component
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeNeutral(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
// TODO 3.0.0: Set this back to neutral when object details are done
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_BLUE);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for informational messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForInformation(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_INFORMATION);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for successful messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForSuccess(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_SUCCESS);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for warning messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForWarning(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_WARNING);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for danger messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForDanger(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_DANGER);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component for failure messages
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForFailure(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_FAILURE);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component with primary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeWithBrandingPrimaryColor(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_PRIMARY);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Panel component with secondary color scheme
|
||||
*
|
||||
* @param string $sTitle
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeWithBrandingSecondaryColor(string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_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
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeForClass(string $sClass, string $sTitle)
|
||||
{
|
||||
$oPanel = new Panel($sTitle);
|
||||
// TODO 3.0.0: Change this to class color when done
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_BLUE);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a basis Panel component
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param String $sIconUrl
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
|
||||
*/
|
||||
public static function MakeEnhancedNeutral(string $sTitle, string $sIconUrl)
|
||||
{
|
||||
$oPanel = new PanelEnhanced($sTitle, $sIconUrl);
|
||||
// TODO 3.0.0: Change this to class color when done
|
||||
$oPanel->SetColor(Panel::ENUM_COLOR_BLUE);
|
||||
|
||||
return $oPanel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/newsroom-menu/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/popover-menu/newsroom-menu/layout';
|
||||
public const 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()
|
||||
{
|
||||
return json_encode($this->aParams);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 Dict;
|
||||
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_message' => Dict::S('UI:Newsroom:NoNewMessage'),
|
||||
'mark_all_as_read' => Dict::S('UI:Newsroom:MarkAllAsRead'),
|
||||
'view_all' => Dict::S('UI:Newsroom:ViewAllMessages'),
|
||||
),
|
||||
);
|
||||
return $aParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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\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 HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/components/popover-menu.js',
|
||||
];
|
||||
|
||||
/** @var array $aSections */
|
||||
protected $aSections;
|
||||
|
||||
/**
|
||||
* PopoverMenu constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->aSections = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
return $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))
|
||||
{
|
||||
throw new Exception('Could not add an item to the "'.$sSectionId.'" section has it does not seem to exist in the "'.$this->GetId().'" menu.');
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks()
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
|
||||
foreach($this->aSections as $sSectionId => $aSectionData)
|
||||
{
|
||||
foreach($aSectionData['aItems'] as $sItemId => $oItem)
|
||||
{
|
||||
$aSubBlocks[$sItemId] = $oItem;
|
||||
}
|
||||
}
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 URLPopupMenuItem;
|
||||
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');
|
||||
|
||||
// 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());
|
||||
|
||||
// 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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: iPopupMenuExtension::MENU_USER_ACTIONS
|
||||
// Legacy code: utils::GetPopupMenuItems($this, iPopupMenuExtension::MENU_USER_ACTIONS, null, $aActions);
|
||||
|
||||
return $aItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public static function MakeMenuForActions(string $sId, array $aMenuItems): PopoverMenu
|
||||
{
|
||||
$oMenu = new PopoverMenu($sId);
|
||||
|
||||
$bFirst = true;
|
||||
foreach ($aMenuItems as $sSection => $aActions) {
|
||||
$aItems = [];
|
||||
|
||||
if (!$bFirst) {
|
||||
$aItems[] = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new \SeparatorPopupMenuItem()
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($aActions as $aAction) {
|
||||
if (!empty($aAction['on_click'])) {
|
||||
// JS
|
||||
$oPopoverMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new JSPopupMenuItem(
|
||||
$aAction['uid'],
|
||||
$aAction['label'],
|
||||
$aAction['on_click'])
|
||||
);
|
||||
} else {
|
||||
// URL
|
||||
$oPopoverMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new URLPopupMenuItem(
|
||||
$aAction['uid'],
|
||||
$aAction['label'],
|
||||
$aAction['url'],
|
||||
$aAction['target'])
|
||||
);
|
||||
}
|
||||
if (!empty($aAction['css_classes'])) {
|
||||
$oPopoverMenuItem->SetCssClasses($aAction['css_classes']);
|
||||
}
|
||||
$aItems[] = $oPopoverMenuItem;
|
||||
}
|
||||
|
||||
$oMenu->AddSection($sSection)
|
||||
->SetItems($sSection, $aItems);
|
||||
$bFirst = false;
|
||||
}
|
||||
|
||||
return $oMenu;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 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)
|
||||
{
|
||||
$aJsFiles = array_merge(parent::GetJsFilesUrlRecursively($bAbsoluteUrl), $this->oPopupMenuItem->GetLinkedScripts());
|
||||
|
||||
return $aJsFiles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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;
|
||||
|
||||
/**
|
||||
* 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 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()
|
||||
{
|
||||
return static::BLOCK_CODE.'-'.$this->oPopupMenuItem->GetUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ApplicationPopupMenuItem::GetLabel()
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel()
|
||||
{
|
||||
return $this->oPopupMenuItem->GetLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ApplicationPopupMenuItem::SetCssClasses()
|
||||
*
|
||||
* @param array $aCssClasses
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCssClasses(array $aCssClasses)
|
||||
{
|
||||
$this->oPopupMenuItem->SetCssClasses($aCssClasses);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ApplicationPopupMenuItem::AddCssClass()
|
||||
*
|
||||
* @param string $sCssClass
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddCssClass(string $sCssClass)
|
||||
{
|
||||
$this->oPopupMenuItem->AddCssClass($sCssClass);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ApplicationPopupMenuItem::GetCssClasses()
|
||||
* @return array
|
||||
*/
|
||||
public function GetCssClasses()
|
||||
{
|
||||
return $this->oPopupMenuItem->GetCssClasses();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 standard NavigationMenu layout for backoffice pages
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/popover-menu/item/mode_separator';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 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,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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 MetaModel;
|
||||
use UserRights;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-quick-create';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/quick-create/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'base/components/quick-create/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/selectize.min.js',
|
||||
'js/components/quick-create.js',
|
||||
];
|
||||
public const CSS_FILES_REL_PATH = [
|
||||
'css/selectize.default.css',
|
||||
];
|
||||
|
||||
// Specific constants
|
||||
public const DEFAULT_ENDPOINT_REL_URL = 'pages/UI.php';
|
||||
|
||||
/** @var array $aAvailableClasses */
|
||||
protected $aAvailableClasses;
|
||||
/** @var array $aLastClasses */
|
||||
protected $aLastClasses;
|
||||
/** @var int $iMaxAutocompleteResults Max. number of elements returned by the autocomplete */
|
||||
protected $iMaxAutocompleteResults;
|
||||
/** @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->aAvailableClasses = UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true);
|
||||
$this->aLastClasses = $aLastClasses;
|
||||
$this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results');
|
||||
$this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available classes (to create) for the current user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetAvailableClasses()
|
||||
{
|
||||
return $this->aAvailableClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return $this->aLastClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxAutocompleteResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxAutocompleteResults(): int
|
||||
{
|
||||
return $this->iMaxAutocompleteResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $iMaxHistoryResults
|
||||
* @return int
|
||||
*/
|
||||
public function GetMaxHistoryResults(): int
|
||||
{
|
||||
return $this->iMaxHistoryResults;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 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'];
|
||||
|
||||
// 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::HtmlEntities(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
sources/application/UI/Base/Component/Title/Title.php
Normal file
91
sources/application/UI/Base/Component/Title/Title.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Title;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
|
||||
/**
|
||||
* Class Title
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base\Component\Title
|
||||
*/
|
||||
class Title extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
/** @inheritDoc */
|
||||
public const BLOCK_CODE = 'ibo-title';
|
||||
/** @inheritDoc */
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/title/layout';
|
||||
|
||||
/** @var string Icon should cover all the space, best for icons with filled background */
|
||||
public const ENUM_ICON_COVER_METHOD_COVER = 'cover';
|
||||
/** @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 */
|
||||
public const DEFAULT_ICON_COVER_METHOD = self::ENUM_ICON_COVER_METHOD_COVER;
|
||||
|
||||
/** @var string */
|
||||
protected $sTitle;
|
||||
/** @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;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(string $sTitle = '', int $iLevel = 1, ?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->sTitle = $sTitle;
|
||||
$this->iLevel = $iLevel;
|
||||
$this->sIconUrl = null;
|
||||
$this->sIconCoverMethod = static::DEFAULT_ICON_COVER_METHOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetTitle(): string
|
||||
{
|
||||
return $this->sTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetLevel(): int
|
||||
{
|
||||
return $this->iLevel;
|
||||
}
|
||||
|
||||
public function SetIcon(string $sIconUrl, string $sIconCoverMethod = self::DEFAULT_ICON_COVER_METHOD)
|
||||
{
|
||||
$this->sIconUrl = $sIconUrl;
|
||||
$this->sIconCoverMethod = $sIconCoverMethod;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
74
sources/application/UI/Base/Component/Title/TitleFactory.php
Normal file
74
sources/application/UI/Base/Component/Title/TitleFactory.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Title;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Helper\UIHelper;
|
||||
use DBObject;
|
||||
use MetaModel;
|
||||
|
||||
class TitleFactory
|
||||
{
|
||||
|
||||
public static function MakeForPage(string $sTitle, ?string $sId = null)
|
||||
{
|
||||
return new Title($sTitle, 1, $sId);
|
||||
}
|
||||
|
||||
public static function MakeForObjectDetails(DBObject $oObject, ?string $sId = null)
|
||||
{
|
||||
// TODO 3.0.0: Refactor all of this
|
||||
$sObjClass = get_class($oObject);
|
||||
$sObjClassName = MetaModel::GetName($sObjClass);
|
||||
$sObjName = $oObject->GetName();
|
||||
|
||||
// Object icon
|
||||
// - Default icon is the class icon
|
||||
$sObjIconUrl = $oObject->GetIcon(false);
|
||||
// Note: Class icons are a square image with no margin around, so they need to be zoomed out in the medallion
|
||||
$sIconCoverMethod = Title::ENUM_ICON_COVER_METHOD_ZOOMOUT;
|
||||
// - Use object image from semantic attribute only if it's not the default image
|
||||
if(!$oObject->IsNew() && MetaModel::HasImageAttributeCode($sObjClass)){
|
||||
$sImageAttCode = MetaModel::GetImageAttributeCode($sObjClass);
|
||||
if(!empty($sImageAttCode)){
|
||||
/** @var \ormDocument $oImage */
|
||||
$oImage = $oObject->Get($sImageAttCode);
|
||||
if(!$oImage->IsEmpty()){
|
||||
$sObjIconUrl = $oImage->GetDisplayURL($sObjClass, $oObject->GetKey(), $sImageAttCode);
|
||||
$sIconCoverMethod = Title::ENUM_ICON_COVER_METHOD_COVER;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$oTitle = new TitleForObjectDetails($sObjClassName, $sObjName, $sId);
|
||||
|
||||
if(!empty($sObjIconUrl)) {
|
||||
$oTitle->SetIcon($sObjIconUrl, $sIconCoverMethod);
|
||||
}
|
||||
|
||||
if (MetaModel::HasStateAttributeCode($sObjClass)) {
|
||||
$sStateCode = $oObject->GetState();
|
||||
|
||||
// Protection against classes with no default state (in which case we don't display the status)
|
||||
if(!empty($sStateCode)) {
|
||||
$sStatusAttCode = MetaModel::GetStateAttributeCode($sObjClass);
|
||||
$sStatusLabel = $oObject->GetStateLabel();
|
||||
$sStatusColor = UIHelper::GetColorFromStatus(get_class($oObject), $sStateCode);
|
||||
$oTitle->SetStatus($sStatusAttCode, $sStatusLabel, $sStatusColor);
|
||||
}
|
||||
}
|
||||
|
||||
return $oTitle;
|
||||
}
|
||||
|
||||
public static function MakeNeutral(string $sTitle, int $iLevel = 1, ?string $sId = null)
|
||||
{
|
||||
return new Title($sTitle, $iLevel, $sId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Title;
|
||||
|
||||
|
||||
class TitleForObjectDetails extends Title
|
||||
{
|
||||
public const HTML_TEMPLATE_REL_PATH = 'base/components/title/titleforobjectdetails';
|
||||
|
||||
/** @var string */
|
||||
protected $sClassName;
|
||||
/** @var string */
|
||||
protected $sObjectName;
|
||||
protected $sStatusCode;
|
||||
protected $sStatusLabel;
|
||||
protected $sStatusColor;
|
||||
|
||||
public function __construct(string $sClassName, string $sObjectName, ?string $sId = null)
|
||||
{
|
||||
parent::__construct('', 2, $sId);
|
||||
$this->sClassName = $sClassName;
|
||||
$this->sObjectName = $sObjectName;
|
||||
$this->sStatusCode = null;
|
||||
$this->sStatusLabel = null;
|
||||
$this->sStatusColor = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetClassName(): string
|
||||
{
|
||||
return $this->sClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetObjectName(): string
|
||||
{
|
||||
return $this->sObjectName;
|
||||
}
|
||||
|
||||
public function SetStatus($sCode, $sLabel, $sColor)
|
||||
{
|
||||
$this->sStatusCode = $sColor;
|
||||
$this->sStatusLabel = $sLabel;
|
||||
$this->sStatusColor = $sColor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetStatusCode()
|
||||
{
|
||||
return $this->sStatusCode;
|
||||
}
|
||||
|
||||
public function GetStatusLabel()
|
||||
{
|
||||
return $this->sStatusLabel;
|
||||
}
|
||||
|
||||
public function GetStatusColor()
|
||||
{
|
||||
return $this->sStatusColor;
|
||||
}
|
||||
}
|
||||
22
sources/application/UI/Base/Component/Toolbar/Toolbar.php
Normal file
22
sources/application/UI/Base/Component/Toolbar/Toolbar.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 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 HTML_TEMPLATE_REL_PATH = 'base/components/toolbar/layout';
|
||||
}
|
||||
Reference in New Issue
Block a user