diff --git a/css/backoffice/components/_alert.scss b/css/backoffice/components/_alert.scss index df920ba99..e889a330c 100644 --- a/css/backoffice/components/_alert.scss +++ b/css/backoffice/components/_alert.scss @@ -8,19 +8,21 @@ $ibo-alert--title--highlight--width: 4px !default; $ibo-alert--title--highlight--height: 100% !default; $ibo-alert-colors: ( - 'grey' : ($ibo-color-grey-200, $ibo-color-grey-700, $ibo-color-grey-900), - 'red': ($ibo-color-red-200, $ibo-color-red-700, $ibo-color-red-900), - 'orange' : ($ibo-color-orange-200, $ibo-color-orange-700, $ibo-color-orange-900), - 'green': ($ibo-color-green-200, $ibo-color-green-700, $ibo-color-green-900), - 'blue-grey': ($ibo-color-blue-grey-200, $ibo-color-blue-grey-700, $ibo-color-blue-grey-900), - 'blue': ($ibo-color-blue-200, $ibo-color-blue-700, $ibo-color-blue-900), - 'cyan': ($ibo-color-cyan-100, $ibo-color-blue-700, $ibo-color-cyan-900), - 'pink': ($ibo-color-pink-200, $ibo-color-pink-700, $ibo-color-pink-900), - 'primary': ($ibo-color-primary-200, $ibo-color-primary-700, $ibo-color-primary-900), - 'secondary': ($ibo-color-secondary-200, $ibo-color-secondary-700, $ibo-color-secondary-900), - 'success': ($ibo-color-success-200, $ibo-color-success-700, $ibo-color-success-900), - 'warning': ($ibo-color-warning-200, $ibo-color-warning-700, $ibo-color-warning-900), - 'danger': ($ibo-color-danger-200, $ibo-color-danger-700, $ibo-color-danger-900), + 'primary': ($ibo-color-primary-200, $ibo-color-primary-700, $ibo-color-primary-900), + 'secondary': ($ibo-color-secondary-200, $ibo-color-secondary-700, $ibo-color-secondary-900), + 'neutral': ($ibo-color-secondary-200, $ibo-color-secondary-700, $ibo-color-secondary-900), + 'success': ($ibo-color-success-200, $ibo-color-success-700, $ibo-color-success-900), + 'warning': ($ibo-color-warning-200, $ibo-color-warning-700, $ibo-color-warning-900), + 'danger': ($ibo-color-danger-200, $ibo-color-danger-700, $ibo-color-danger-900), + 'failure': ($ibo-color-danger-200, $ibo-color-danger-700, $ibo-color-danger-900), + 'grey' : ($ibo-color-grey-200, $ibo-color-grey-700, $ibo-color-grey-900), + 'blue-grey': ($ibo-color-blue-grey-200, $ibo-color-blue-grey-700, $ibo-color-blue-grey-900), + 'blue': ($ibo-color-blue-200, $ibo-color-blue-700, $ibo-color-blue-900), + 'cyan': ($ibo-color-cyan-100, $ibo-color-blue-700, $ibo-color-cyan-900), + 'green': ($ibo-color-green-200, $ibo-color-green-700, $ibo-color-green-900), + 'orange' : ($ibo-color-orange-200, $ibo-color-orange-700, $ibo-color-orange-900), + 'red': ($ibo-color-red-200, $ibo-color-red-700, $ibo-color-red-900), + 'pink': ($ibo-color-pink-200, $ibo-color-pink-700, $ibo-color-pink-900), ) !default; @each $sColor, $aColorValues in $ibo-alert-colors{ diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 35361bc28..6278d8940 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -148,8 +148,10 @@ return array( 'Combodo\\iTop\\Application\\TwigBase\\Controller\\PageNotFoundException' => $baseDir . '/sources/application/TwigBase/Controller/Controller.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\Extension' => $baseDir . '/sources/application/TwigBase/Twig/Extension.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\TwigHelper' => $baseDir . '/sources/application/TwigBase/Twig/TwigHelper.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\Alert\\Alert' => $baseDir . '/sources/application/UI/Component/Alert/Alert.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\Alert' => $baseDir . '/sources/application/UI/Component/Alert/Alert.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\AlertFactory' => $baseDir . '/sources/application/UI/Component/Alert/AlertFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\Breadcrumbs\\Breadcrumbs' => $baseDir . '/sources/application/UI/Component/Breadcrumbs/Breadcrumbs.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Button\\ButtonFactory' => $baseDir . '/sources/application/UI/Component/Button/ButtonFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\Button\\Button\\Button' => $baseDir . '/sources/application/UI/Component/Button/Button.php', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearch' => $baseDir . '/sources/application/UI/Component/GlobalSearch/GlobalSearch.php', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearchFactory' => $baseDir . '/sources/application/UI/Component/GlobalSearch/GlobalSearchFactory.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index af16acf1c..8f3468568 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -378,8 +378,10 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b 'Combodo\\iTop\\Application\\TwigBase\\Controller\\PageNotFoundException' => __DIR__ . '/../..' . '/sources/application/TwigBase/Controller/Controller.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\Extension' => __DIR__ . '/../..' . '/sources/application/TwigBase/Twig/Extension.php', 'Combodo\\iTop\\Application\\TwigBase\\Twig\\TwigHelper' => __DIR__ . '/../..' . '/sources/application/TwigBase/Twig/TwigHelper.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\Alert\\Alert' => __DIR__ . '/../..' . '/sources/application/UI/Component/Alert/Alert.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\Alert' => __DIR__ . '/../..' . '/sources/application/UI/Component/Alert/Alert.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Alert\\AlertFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/Alert/AlertFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\Breadcrumbs\\Breadcrumbs' => __DIR__ . '/../..' . '/sources/application/UI/Component/Breadcrumbs/Breadcrumbs.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Button\\ButtonFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/Button/ButtonFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\Button\\Button\\Button' => __DIR__ . '/../..' . '/sources/application/UI/Component/Button/Button.php', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearch' => __DIR__ . '/../..' . '/sources/application/UI/Component/GlobalSearch/GlobalSearch.php', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearchFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/GlobalSearch/GlobalSearchFactory.php', diff --git a/sources/application/UI/Component/Alert/Alert.php b/sources/application/UI/Component/Alert/Alert.php index c3e068346..aa3b961b2 100644 --- a/sources/application/UI/Component/Alert/Alert.php +++ b/sources/application/UI/Component/Alert/Alert.php @@ -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 - * @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; } - } \ No newline at end of file diff --git a/sources/application/UI/Component/Alert/AlertFactory.php b/sources/application/UI/Component/Alert/AlertFactory.php new file mode 100644 index 000000000..1200a709d --- /dev/null +++ b/sources/application/UI/Component/Alert/AlertFactory.php @@ -0,0 +1,125 @@ + + * @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); + } +} \ No newline at end of file diff --git a/templates/components/alert/layout.html.twig b/templates/components/alert/layout.html.twig index 2ee6e7f0c..0405c64e2 100644 --- a/templates/components/alert/layout.html.twig +++ b/templates/components/alert/layout.html.twig @@ -1,4 +1,4 @@
-
{{ oUIBlock.GetTitle() }}
-
{{ oUIBlock.GetMainText() }}
+
{{ oUIBlock.GetTitle() }}
+
{{ oUIBlock.GetContent()|raw }}
\ No newline at end of file