mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°2847 - Alert: Add factory and color constants
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Alert\Alert;
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\Alert;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
@@ -27,7 +26,7 @@ use Combodo\iTop\Application\UI\UIBlock;
|
||||
* Class Alert
|
||||
*
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Component\Alert\Alert
|
||||
* @package Combodo\iTop\Application\UI\Component\Alert
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class Alert extends UIBlock
|
||||
@@ -37,10 +36,47 @@ class Alert extends UIBlock
|
||||
const HTML_TEMPLATE_REL_PATH = 'components/alert/layout';
|
||||
const JS_TEMPLATE_REL_PATH = 'components/alert/layout';
|
||||
|
||||
// Specific constants
|
||||
/** @var string ENUM_COLOR_PRIMARY */
|
||||
const ENUM_COLOR_PRIMARY = 'primary';
|
||||
/** @var string ENUM_COLOR_SECONDARY */
|
||||
const ENUM_COLOR_SECONDARY = 'secondary';
|
||||
|
||||
/** @var string ENUM_COLOR_NEUTRAL */
|
||||
const ENUM_COLOR_NEUTRAL = 'neutral';
|
||||
/** @var string ENUM_COLOR_SUCCESS */
|
||||
const ENUM_COLOR_SUCCESS = 'success';
|
||||
/** @var string ENUM_COLOR_WARNING */
|
||||
const ENUM_COLOR_WARNING = 'warning';
|
||||
/** @var string ENUM_COLOR_DANGER */
|
||||
const ENUM_COLOR_DANGER = 'danger';
|
||||
/** @var string ENUM_COLOR_FAILURE */
|
||||
const ENUM_COLOR_FAILURE = 'failure';
|
||||
|
||||
/** @var string ENUM_COLOR_GREY */
|
||||
const ENUM_COLOR_GREY = 'grey';
|
||||
/** @var string ENUM_COLOR_BLUEGREY */
|
||||
const ENUM_COLOR_BLUEGREY = 'blue-grey';
|
||||
/** @var string ENUM_COLOR_BLUE */
|
||||
const ENUM_COLOR_BLUE = 'blue';
|
||||
/** @var string ENUM_COLOR_CYAN */
|
||||
const ENUM_COLOR_CYAN = 'cyan';
|
||||
/** @var string ENUM_COLOR_GREEN */
|
||||
const ENUM_COLOR_GREEN = 'green';
|
||||
/** @var string ENUM_COLOR_ORANGE */
|
||||
const ENUM_COLOR_ORANGE = 'orange';
|
||||
/** @var string ENUM_COLOR_RED */
|
||||
const ENUM_COLOR_RED = 'red';
|
||||
/** @var string ENUM_COLOR_PINK */
|
||||
const ENUM_COLOR_PINK = 'pink';
|
||||
|
||||
/** @var string DEFAULT_COLOR */
|
||||
const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
|
||||
|
||||
/** @var string $sTitle */
|
||||
protected $sTitle;
|
||||
/** @var array $sMainText */
|
||||
protected $sMainText;
|
||||
/** @var string $sContent The raw HTML content, must be already sanitized */
|
||||
protected $sContent;
|
||||
/** @var string $sColor */
|
||||
protected $sColor;
|
||||
|
||||
@@ -48,14 +84,14 @@ class Alert extends UIBlock
|
||||
* Alert constructor.
|
||||
*
|
||||
* @param string $sTitle
|
||||
* @param string $sMainText
|
||||
* @param string $sContent
|
||||
* @param string $sColor
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct($sTitle = '', $sMainText = '', $sColor = 'secondary', $sId = null)
|
||||
public function __construct($sTitle = '', $sContent = '', $sColor = self::DEFAULT_COLOR, $sId = null)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
$this->sMainText = $sMainText;
|
||||
$this->sContent = $sContent;
|
||||
$this->sColor = $sColor;
|
||||
parent::__construct($sId);
|
||||
}
|
||||
@@ -75,28 +111,33 @@ class Alert extends UIBlock
|
||||
public function SetTitle($sTitle)
|
||||
{
|
||||
$this->sTitle = $sTitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the raw HTML content, should be already sanitized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetMainText()
|
||||
public function GetContent()
|
||||
{
|
||||
return $this->sMainText;
|
||||
return $this->sContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $aMainText
|
||||
* Set the raw HTML content, must be already sanitized.
|
||||
*
|
||||
* @param string $sContent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMainText($aMainText)
|
||||
public function SetContent($sContent)
|
||||
{
|
||||
$this->sMainText = $aMainText;
|
||||
$this->sContent = $sContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@@ -115,5 +156,4 @@ class Alert extends UIBlock
|
||||
$this->sColor = $sColor;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
125
sources/application/UI/Component/Alert/AlertFactory.php
Normal file
125
sources/application/UI/Component/Alert/AlertFactory.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?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\Component\Alert;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Component\Alert\Alert;
|
||||
|
||||
/**
|
||||
* Class AlertFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Component\Alert
|
||||
* @since 2.8.0
|
||||
*/
|
||||
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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeNeutral($sTitle, $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_NEUTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForSuccess($sTitle, $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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForWarning($sTitle, $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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForDanger($sTitle, $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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeForFailure($sTitle, $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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingPrimaryColor($sTitle, $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\Component\Alert\Alert
|
||||
*/
|
||||
public static function MakeWithBrandingSecondaryColor($sTitle, $sContent)
|
||||
{
|
||||
return new Alert($sTitle, $sContent, Alert::ENUM_COLOR_SECONDARY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user