N°4621 Fix naming inconsistencies in sources/*

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

View File

@@ -0,0 +1,270 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Button;
use Combodo\iTop\Application\UI\Base\UIBlock;
/**
* Class Button
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Button
* @since 3.0.0
*/
class Button extends UIBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-button';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/button/layout';
// Specific constants
/** @var string ENUM_ACTION_TYPE_REGULAR */
public const ENUM_ACTION_TYPE_REGULAR = 'regular';
/** @var string ENUM_ACTION_TYPE_ALTERNATIVE */
public const ENUM_ACTION_TYPE_ALTERNATIVE = 'alternative';
/** @var string DEFAULT_ACTION_TYPE */
public const DEFAULT_ACTION_TYPE = self::ENUM_ACTION_TYPE_REGULAR;
/** @var string ENUM_COLOR_SCHEME_NEUTRAL */
public const ENUM_COLOR_SCHEME_NEUTRAL = 'neutral';
/** @var string ENUM_COLOR_SCHEME_VALIDATION */
public const ENUM_COLOR_SCHEME_VALIDATION = 'success';
/** @var string ENUM_COLOR_SCHEME_DESTRUCTIVE */
public const ENUM_COLOR_SCHEME_DESTRUCTIVE = 'danger';
/** @var string ENUM_COLOR_SCHEME_PRIMARY */
public const ENUM_COLOR_SCHEME_PRIMARY = 'primary';
/** @var string ENUM_COLOR_SCHEME_SECONDARY */
public const ENUM_COLOR_SCHEME_SECONDARY = 'secondary';
/** @var string ENUM_COLOR_SCHEME_GREEN */
public const ENUM_COLOR_SCHEME_GREEN = 'green';
/** @var string ENUM_COLOR_SCHEME_RED */
public const ENUM_COLOR_SCHEME_RED = 'red';
/** @var string ENUM_COLOR_SCHEME_CYAN */
public const ENUM_COLOR_SCHEME_CYAN = 'cyan';
/** @var string DEFAULT_COLOR_SCHEME */
public const DEFAULT_COLOR_SCHEME = self::ENUM_COLOR_SCHEME_NEUTRAL;
/** @var string $sLabel */
protected $sLabel;
/** @var string $sTooltip */
protected $sTooltip;
/** @var string $sIconClass */
protected $sIconClass;
/** @var string $sActionType The type of action, a 'regular' action or a 'misc' action */
protected $sActionType;
/** @var string $sColor */
protected $sColor;
/** @var string $sJsCode */
protected $sJsCode;
/** @var string $sOnClickJsCode */
protected $sOnClickJsCode;
/** @var bool $bIsDisabled */
protected $bIsDisabled;
/**
* Button constructor.
*
* @param string $sLabel
* @param string|null $sId
* @param string $sTooltip
* @param string $sIconClass
* @param string $sActionType
* @param string $sColorScheme
* @param string $sJsCode
* @param string $sOnClickJsCode
*/
public function __construct(string $sLabel, string $sId = null, string $sTooltip = '', string $sIconClass = '', string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColorScheme = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '', string $sOnClickJsCode = '')
{
// We only use resource ID (not sanitized) on button for now, but this might be reworked back into \UIBlock if needed
if (!is_null($sId)) {
$this->AddDataAttribute('resource-id', $sId);
}
parent::__construct($sId);
$this->sLabel = $sLabel;
$this->sTooltip = $sTooltip;
$this->sIconClass = $sIconClass;
$this->sActionType = $sActionType;
$this->sColor = $sColorScheme;
$this->sJsCode = $sJsCode;
$this->sOnClickJsCode = $sOnClickJsCode;
$this->aDataAttributes = ['role' => 'ibo-button'];
$this->bIsDisabled = false;
}
/**
* @return string
*/
public function GetLabel(): string
{
return $this->sLabel;
}
/**
* @param string $sLabel
*
* @return $this
*/
public function SetLabel(string $sLabel)
{
$this->sLabel = $sLabel;
return $this;
}
/**
* @return string
*/
public function GetTooltip(): string
{
return $this->sTooltip;
}
/**
* @param string $sTooltip
*
* @return $this
*/
public function SetTooltip(string $sTooltip)
{
$this->sTooltip = $sTooltip;
return $this;
}
/**
* @return string
*/
public function GetIconClass(): string
{
return $this->sIconClass;
}
/**
* @param string $sIconClass
*
* @return $this
*/
public function SetIconClass(string $sIconClass)
{
$this->sIconClass = $sIconClass;
return $this;
}
/**
* @return string
*/
public function GetActionType(): string
{
return $this->sActionType;
}
/**
* @param string $sActionType
*
* @return $this
*/
public function SetActionType(string $sActionType)
{
$this->sActionType = $sActionType;
return $this;
}
/**
* @return string
*/
public function GetColor(): string
{
return $this->sColor;
}
/**
* @param string $sColor
*
* @return $this
*/
public function SetColor(string $sColor)
{
$this->sColor = $sColor;
return $this;
}
/**
* @return string
*/
public function GetOnClickJsCode(): string
{
return $this->sOnClickJsCode;
}
/**
* @param string $sOnClickJsCode
*
* @return $this
*/
public function SetOnClickJsCode(string $sOnClickJsCode)
{
$this->sOnClickJsCode = $sOnClickJsCode;
return $this;
}
/**
* @return string
*/
public function GetJsCode(): string
{
return $this->sJsCode;
}
/**
* @param string $sJsCode
*
* @return $this
*/
public function SetJsCode(string $sJsCode)
{
$this->sJsCode = $sJsCode;
return $this;
}
/**
* @return bool
*/
public function IsDisabled(): bool
{
return $this->bIsDisabled;
}
/**
* @param bool $bIsDisabled
*
* @return $this
*/
public function SetIsDisabled(bool $bIsDisabled)
{
$this->bIsDisabled = $bIsDisabled;
return $this;
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Button;
/**
* Class Button
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Button
* @since 3.0.0
*/
class ButtonJS extends Button
{
// Overloaded constants
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/buttonjs';
// Specific constants
/** @var string ENUM_TYPE_BUTTON */
public const ENUM_TYPE_BUTTON = 'button';
/** @var string ENUM_TYPE_SUBMIT */
public const ENUM_TYPE_SUBMIT = 'submit';
/** @var string ENUM_TYPE_RESET */
public const ENUM_TYPE_RESET = 'reset';
/** @var string DEFAULT_TYPE */
public const DEFAULT_TYPE = self::ENUM_TYPE_BUTTON;
/** @var string The HTML type of the button (eg. 'submit', 'button', ...) */
protected $sType;
/** @var string The HTML name of the button, used by forms */
protected $sName;
/** @var string The HTML value of the button, used by forms */
protected $sValue;
/**
* ButtonJS constructor.
*
* @param string $sLabel
* @param string|null $sId
* @param string $sName
* @param string $sValue
* @param string $sType
* @param string $sTooltip
* @param string $sIconClass
* @param string $sActionType
* @param string $sColor
* @param string $sJsCode
* @param string $sOnClickJsCode
*/
public function __construct(
string $sLabel, string $sId = null, string $sName = '', string $sValue = '', string $sType = self::DEFAULT_TYPE,
string $sTooltip = '', string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
string $sOnClickJsCode = ''
) {
parent::__construct( $sLabel,$sId, $sTooltip, $sIconClass,
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
$this->sName = $sName;
$this->sValue = $sValue;
$this->sType = $sType;
}
/**
* @return string
*/
public function GetType(): string
{
return $this->sType;
}
/**
* @param string $sType
*
* @return $this
*/
public function SetType(string $sType)
{
$this->sType = $sType;
return $this;
}
/**
* @return string
*/
public function GetName(): string
{
return $this->sName;
}
/**
* @param string $sName
*
* @return $this
*/
public function SetName(string $sName)
{
$this->sName = $sName;
return $this;
}
/**
* @return string
*/
public function GetValue(): string
{
return $this->sValue;
}
/**
* @param string $sValue
*
* @return $this
*/
public function SetValue(string $sValue)
{
$this->sValue = $sValue;
return $this;
}
}

View File

@@ -0,0 +1,471 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Button;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
use Dict;
/**
* Class ButtonUIBlockFactory
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Button
* @since 3.0.0
* @api
*
* @link <itop_url>/test/VisualTest/Backoffice/RenderAllUiBlocks.php#title-buttons to see live examples
*/
class ButtonUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UIButton';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = Button::class;
//---------------------------------------------
// Regular action buttons, mostly used in forms
//---------------------------------------------
/**
* Make a basis Button component for any purpose
*
* @param string $sLabel
* @param string|null $sName See {@link Button::$sName}
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeNeutral(string $sLabel, string $sName = null, ?string $sId = null)
{
$oButton = new ButtonJS($sLabel, $sId);
$oButton->SetActionType(Button::ENUM_ACTION_TYPE_REGULAR)
->SetColor(Button::ENUM_COLOR_SCHEME_NEUTRAL);
if (!empty($sName)) {
$oButton->SetName($sName);
}
return $oButton;
}
/**
* Make a Button component for a primary action, should be used to tell the user this is the main choice
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForPrimaryAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_PRIMARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
}
/**
* Make a Button component for a secondary action, should be used to tell the user this is an second hand choice
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForSecondaryAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_SECONDARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
}
/**
* Make a Button component for a success action, should be used to tell the user he/she going to make a positive action/choice
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForPositiveAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_VALIDATION, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit, $sId);
}
/**
* Make a Button component for a destructive action, should be used to tell the user he/she going to make something that cannot be
* undone easily (deleting an object) or break something (link between objects)
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForDestructiveAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName,
$bIsSubmit, $sId);
}
//-------------------------------------------------
// Alternative action buttons, mostly used in forms
//-------------------------------------------------
/**
* Make a basis Button component for any purpose
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeAlternativeNeutral(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* Make a Button component for an alternative primary action, should be used to avoid the user to consider this action as the first
* choice
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForAlternativePrimaryAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_PRIMARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* Make a Button component for an alternative secondary action, should be used to avoid the user to focus on this
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForAlternativeSecondaryAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_SECONDARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* Make a Button component for a validation action, should be used to avoid the user to focus on this
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForAlternativeValidationAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_VALIDATION, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* Make a Button component for a destructive action, should be used to avoid the user to focus on this
*
* @param string $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForAlternativeDestructiveAction(
string $sLabel,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* Make a Button component for a cancel, should be used only for UI navigation, not destructive action
*
* @param string|null $sLabel
* @param string|null $sName See Button::$sName
* @param string|null $sValue See Button::$sValue
* @param bool $bIsSubmit See Button::$sType
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeForCancel(
string $sLabel = null,
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
$sLabel = $sLabel ?? Dict::S('UI:Button:Cancel');
$sName = $sName ?? 'cancel';
return static::MakeForAction($sLabel, Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
}
/**
* @param string $sIconClasses
* @param string $sTooltipText
* @param string|null $sName
* @param string|null $sValue
* @param bool $bIsSubmit
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonJS
*/
public static function MakeIconAction(
string $sIconClasses,
string $sTooltipText = '',
string $sName = null,
string $sValue = null,
bool $bIsSubmit = false,
?string $sId = null
) {
$oButton = static::MakeForAction('', Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName,
$bIsSubmit, $sId);
$oButton->SetIconClass($sIconClasses);
$oButton->SetTooltip($sTooltipText);
return $oButton;
}
//----------------------------------------------------------------------------------------------
// Link buttons, mostly used outside forms, to redirect somewhere whilst keeping a button aspect
//----------------------------------------------------------------------------------------------
/**
* Make a link Button component to open an URL instead of triggering a form action
*
* @param string $sURL
* @param string|null $sLabel
* @param string|null $sIconClasses
* @param string|null $sTarget
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeLinkNeutral(
string $sURL, ?string $sLabel = '', ?string $sIconClasses = null, ?string $sTarget = null,
?string $sId = null
) {
if (empty($sTarget)) {
$sTarget = ButtonURL::DEFAULT_TARGET;
}
$sType = empty($sIconClasses) ? Button::ENUM_ACTION_TYPE_REGULAR : Button::ENUM_ACTION_TYPE_ALTERNATIVE;
$oButton = static::MakeForLink($sLabel, $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, $sType, $sTarget, $sId);
if (!empty($sIconClasses)) {
$oButton->SetIconClass($sIconClasses);
}
return $oButton;
}
/**
* @param string $sIconClasses
* @param string $sTooltipText
* @param string|null $sURL
* @param string|null $sTarget
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonURL
*/
public static function MakeIconLink(
string $sIconClasses, string $sTooltipText, ?string $sURL = '', ?string $sTarget = null,
?string $sId = null
) {
if (empty($sTarget)) {
$sTarget = ButtonURL::DEFAULT_TARGET;
}
$oButton = static::MakeForLink('', $sURL,Button::ENUM_COLOR_SCHEME_NEUTRAL, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sTarget, $sId);
$oButton->SetIconClass($sIconClasses);
$oButton->SetTooltip($sTooltipText);
return $oButton;
}
/**
* @param string $sIconClasses
* @param string $sTooltipText
* @param string|null $sURL
* @param string|null $sName
* @param string|null $sTarget
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\Button
*/
public static function MakeDestructiveIconLink(
string $sIconClasses, string $sTooltipText, ?string $sURL = null, ?string $sName = null, ?string $sTarget = null,
?string $sId = null
) {
$oButton = static::MakeIconLink($sIconClasses, $sTooltipText, $sURL, $sTarget, $sId);
$oButton->SetColor(Button::ENUM_COLOR_SCHEME_DESTRUCTIVE);
$oButton->SetTooltip($sTooltipText);
return $oButton;
}
//--------
// Helpers
//--------
/**
* Internal helper
*
* @param string $sLabel
* @param string $sColor See Button::$sColor
* @param string $sActionType See Button::$sActionType
* @param string|null $sValue See Button::$sValue
* @param string|null $sName See Button::$sValue
* @param bool $bIsSubmit
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonJS
* @internal
*/
protected static function MakeForAction(
string $sLabel,
string $sColor,
string $sActionType,
string $sValue = null,
string $sName = null,
bool $bIsSubmit = false,
?string $sId = null
) {
$oButton = new ButtonJS($sLabel, $sId);
$oButton->SetActionType($sActionType)
->SetColor($sColor);
if (strlen($sValue) > 0) {
$oButton->SetValue($sValue);
}
if (strlen($sName) > 0) {
$oButton->SetName($sName);
}
// Set as submit button if necessary
if ($bIsSubmit === true) {
$oButton->SetType(ButtonJS::ENUM_TYPE_SUBMIT);
}
return $oButton;
}
/**
* Internal helper
*
* @internal
*
* @param string $sLabel
*
* @param string $sURL
* @param string $sColor See Button::$sColor
* @param string $sActionType See Button::$sActionType
* @param string|null $sTarget
* @param string|null $sId
*
* @return \Combodo\iTop\Application\UI\Base\Component\Button\ButtonURL
*/
protected static function MakeForLink(
string $sLabel,
string $sURL,
string $sColor,
string $sActionType,
string $sTarget = null,
?string $sId = null
) {
$oButton = new ButtonURL($sLabel, $sURL, $sId, $sTarget);
$oButton->SetActionType($sActionType)
->SetColor($sColor);
return $oButton;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Button;
/**
* Class Button
*
* @author Stephen Abello <stephen.abello@combodo.com>
* @package Combodo\iTop\Application\UI\Base\Component\Button
* @since 3.0.0
*/
class ButtonURL extends Button
{
// Overloaded constants
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/button/buttonurl';
// Specific constants
/** @var string ENUM_TARGET_BLANK */
public const ENUM_TARGET_BLANK = '_blank';
/** @var string ENUM_TARGET_SELF */
public const ENUM_TARGET_SELF= '_self';
/** @var string ENUM_TARGET_PARENT */
public const ENUM_TARGET_PARENT= '_parent';
/** @var string ENUM_TARGET_TOP */
public const ENUM_TARGET_TOP= '_top';
/** @var string DEFAULT_TARGET */
public const DEFAULT_TARGET = self::ENUM_TARGET_SELF;
/** @var string */
protected $sURL;
/** @var string */
protected $sTarget;
/**
* ButtonURL constructor.
*
* @param string $sLabel
* @param string $sURL
* @param string|null $sId
* @param string $sTarget
* @param string $sTooltip
* @param string $sIconClass
* @param string $sActionType
* @param string $sColor
* @param string $sJsCode
* @param string $sOnClickJsCode
*/
public function __construct(
string $sLabel, string $sURL, string $sId = null, string $sTarget = self::DEFAULT_TARGET, string $sTooltip = '', string $sIconClass = '',
string $sActionType = self::DEFAULT_ACTION_TYPE, string $sColor = self::DEFAULT_COLOR_SCHEME, string $sJsCode = '',
string $sOnClickJsCode = '')
{
parent::__construct($sLabel, $sId, $sTooltip, $sIconClass,
$sActionType, $sColor, $sJsCode, $sOnClickJsCode);
$this->sURL = $sURL;
$this->sTarget = $sTarget;
}
/**
* @return string
*/
public function GetURL(): string
{
return $this->sURL;
}
/**
* @param string $sURL
*
* @return $this
*/
public function SetURL(string $sURL)
{
$this->sURL = $sURL;
return $this;
}
/**
* @return string
*/
public function GetTarget(): string
{
return $this->sTarget;
}
/**
* @param string $sTarget
*
* @return $this
*/
public function SetTarget(string $sTarget)
{
$this->sTarget = $sTarget;
return $this;
}
}