diff --git a/css/backoffice/components/_button.scss b/css/backoffice/components/_button.scss index 542c83f86..dc5bb2fe1 100644 --- a/css/backoffice/components/_button.scss +++ b/css/backoffice/components/_button.scss @@ -7,39 +7,56 @@ $ibo-button--box-shadow-bottom: 0px 2px 0px !default; $ibo-button--box-shadow-top: inset 0px 2px 0px !default; $ibo-button-colors: ( 'regular': ( - 'primary': ( - '': ( - $ibo-color-primary-400, - $ibo-color-grey-900, - $ibo-button--box-shadow-bottom $ibo-color-primary-400, - ), - ':hover': ( - $ibo-color-primary-600, - $ibo-color-grey-900, - $ibo-button--box-shadow-bottom $ibo-color-primary-800, + 'neutral': ( + '': ( + $ibo-color-secondary-100, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-secondary-300, + ), + ':hover': ( + $ibo-color-secondary-200, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-secondary-300, + ), + ':active': ( + $ibo-color-secondary-200, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-secondary-300 #{','} $ibo-button--box-shadow-bottom $ibo-color-secondary-200, + ), + ), + 'primary': ( + '': ( + $ibo-color-primary-400, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-primary-600, + ), + ':hover': ( + $ibo-color-primary-600, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-primary-800, ), ':active': ( - $ibo-color-primary-600, - $ibo-color-grey-900, - $ibo-button--box-shadow-top $ibo-color-primary-800 + ',' + $ibo-button--box-shadow-bottom $ibo-color-primary-600, + $ibo-color-primary-600, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-primary-800 #{','} $ibo-button--box-shadow-bottom $ibo-color-primary-600, ), ), 'secondary': ( '': ( $ibo-color-secondary-100, $ibo-color-grey-900, - $ibo-button--box-shadow-bottom $ibo-color-secondary-300, - ), - ':hover': ( - $ibo-color-secondary-200, - $ibo-color-grey-900, - $ibo-button--box-shadow-bottom $ibo-color-secondary-300, - ), - ':active': ( - $ibo-color-secondary-200, - $ibo-color-grey-900, - $ibo-button--box-shadow-top $ibo-color-secondary-300 + ',' + $ibo-button--box-shadow-bottom $ibo-color-secondary-200, - ), + $ibo-button--box-shadow-bottom $ibo-color-secondary-300, + ), + ':hover': ( + $ibo-color-secondary-200, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-secondary-300, + ), + ':active': ( + $ibo-color-secondary-200, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-secondary-300 #{','} $ibo-button--box-shadow-bottom $ibo-color-secondary-200, + ), ), 'red': ( '': ( @@ -47,32 +64,32 @@ $ibo-button-colors: ( $ibo-color-white-100, $ibo-button--box-shadow-bottom $ibo-color-red-800, ), - ':hover': ( - $ibo-color-red-700, - $ibo-color-white-100, - $ibo-button--box-shadow-bottom $ibo-color-red-800, + ':hover': ( + $ibo-color-red-700, + $ibo-color-white-100, + $ibo-button--box-shadow-bottom $ibo-color-red-800, + ), + ':active': ( + $ibo-color-red-700, + $ibo-color-white-100, + $ibo-button--box-shadow-top $ibo-color-red-800 #{','} $ibo-button--box-shadow-bottom $ibo-color-red-700, + ), + ), + 'green': ( + '': ( + $ibo-color-green-700, + $ibo-color-white-100, + $ibo-button--box-shadow-bottom $ibo-color-green-900, + ), + ':hover': ( + $ibo-color-green-800, + $ibo-color-white-100, + $ibo-button--box-shadow-bottom $ibo-color-green-900, ), ':active': ( - $ibo-color-red-700, - $ibo-color-white-100, - $ibo-button--box-shadow-top $ibo-color-red-800 + ',' + $ibo-button--box-shadow-bottom $ibo-color-red-700, - ), - ), - 'green': ( - '': ( - $ibo-color-green-700, - $ibo-color-white-100, - $ibo-button--box-shadow-bottom $ibo-color-green-900, - ), - ':hover': ( - $ibo-color-green-800, - $ibo-color-white-100, - $ibo-button--box-shadow-bottom $ibo-color-green-900, - ), - ':active': ( - $ibo-color-green-800, - $ibo-color-white-100, - $ibo-button--box-shadow-top $ibo-color-green-900 + ',' + $ibo-button--box-shadow-bottom $ibo-color-green-800, + $ibo-color-green-800, + $ibo-color-white-100, + $ibo-button--box-shadow-top $ibo-color-green-900 #{','} $ibo-button--box-shadow-bottom $ibo-color-green-800, ), ), 'cyan': ( @@ -87,28 +104,45 @@ $ibo-button-colors: ( $ibo-button--box-shadow-bottom $ibo-color-cyan-900, ), ':active': ( - $ibo-color-cyan-700, - $ibo-color-white-100, - $ibo-button--box-shadow-top $ibo-color-cyan-900 + ',' + $ibo-button--box-shadow-bottom $ibo-color-cyan-700, + $ibo-color-cyan-700, + $ibo-color-white-100, + $ibo-button--box-shadow-top $ibo-color-cyan-900 #{','} $ibo-button--box-shadow-bottom $ibo-color-cyan-700, ), ) ), -'misc': ( - 'primary': ( - '': ( - transparent, - $ibo-color-primary-600, - $ibo-button--box-shadow-bottom transparent, - ), - ':hover': ( - $ibo-color-primary-300, - $ibo-color-grey-900, - $ibo-button--box-shadow-bottom $ibo-color-primary-300, + 'alternative': ( + 'neutral': ( + '': ( + transparent, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom transparent, + ), + ':hover': ( + $ibo-color-secondary-100, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-secondary-100, + ), + ':active': ( + $ibo-color-secondary-100, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-secondary-200 #{','} $ibo-button--box-shadow-bottom $ibo-color-secondary-100, + ), + ), + 'primary': ( + '': ( + transparent, + $ibo-color-primary-600, + $ibo-button--box-shadow-bottom transparent, + ), + ':hover': ( + $ibo-color-primary-300, + $ibo-color-grey-900, + $ibo-button--box-shadow-bottom $ibo-color-primary-300, ), ':active': ( - $ibo-color-primary-300, - $ibo-color-grey-900, - $ibo-button--box-shadow-top $ibo-color-primary-700 + ',' + $ibo-button--box-shadow-bottom $ibo-color-primary-300, + $ibo-color-primary-300, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-primary-700 #{','} $ibo-button--box-shadow-bottom $ibo-color-primary-300, ), ), 'secondary': ( @@ -123,9 +157,9 @@ $ibo-button-colors: ( $ibo-button--box-shadow-bottom $ibo-color-secondary-100, ), ':active': ( - $ibo-color-secondary-100, - $ibo-color-grey-900, - $ibo-button--box-shadow-top $ibo-color-secondary-200 + ',' + $ibo-button--box-shadow-bottom $ibo-color-secondary-100, + $ibo-color-secondary-100, + $ibo-color-grey-900, + $ibo-button--box-shadow-top $ibo-color-secondary-200 #{','} $ibo-button--box-shadow-bottom $ibo-color-secondary-100, ), ), 'red': ( @@ -140,9 +174,9 @@ $ibo-button-colors: ( $ibo-button--box-shadow-bottom $ibo-color-red-200, ), ':active': ( - $ibo-color-red-200, - $ibo-color-red-900, - $ibo-button--box-shadow-top $ibo-color-red-700 + ',' + $ibo-button--box-shadow-bottom $ibo-color-red-200, + $ibo-color-red-200, + $ibo-color-red-900, + $ibo-button--box-shadow-top $ibo-color-red-700 #{','} $ibo-button--box-shadow-bottom $ibo-color-red-200, ), ), 'green': ( @@ -157,9 +191,9 @@ $ibo-button-colors: ( $ibo-button--box-shadow-bottom $ibo-color-green-100, ), ':active': ( - $ibo-color-green-100, - $ibo-color-green-900, - $ibo-button--box-shadow-top $ibo-color-green-700 + ',' + $ibo-button--box-shadow-bottom $ibo-color-green-100, + $ibo-color-green-100, + $ibo-color-green-900, + $ibo-button--box-shadow-top $ibo-color-green-700 #{','} $ibo-button--box-shadow-bottom $ibo-color-green-100, ), ), 'cyan': ( @@ -174,9 +208,9 @@ $ibo-button-colors: ( $ibo-button--box-shadow-bottom $ibo-color-cyan-100, ), ':active': ( - $ibo-color-cyan-100, - $ibo-color-cyan-900, - $ibo-button--box-shadow-top $ibo-color-cyan-800 + ',' + $ibo-button--box-shadow-bottom $ibo-color-cyan-100, + $ibo-color-cyan-100, + $ibo-color-cyan-900, + $ibo-button--box-shadow-top $ibo-color-cyan-800 #{','} $ibo-button--box-shadow-bottom $ibo-color-cyan-100, ), ), ) diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index 6278d8940..a69ecdfe7 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -151,13 +151,13 @@ return array( '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\\Button' => $baseDir . '/sources/application/UI/Component/Button/Button.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', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearchHelper' => $baseDir . '/sources/application/UI/Component/GlobalSearch/GlobalSearchHelper.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Html\\Html\\Html' => $baseDir . '/sources/application/UI/Component/Html/Html.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Panel\\Panel\\Panel' => $baseDir . '/sources/application/UI/Component/Panel/Panel.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Html\\Html' => $baseDir . '/sources/application/UI/Component/Html/Html.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Panel\\Panel' => $baseDir . '/sources/application/UI/Component/Panel/Panel.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\NewsroomMenu\\NewsroomMenu' => $baseDir . '/sources/application/UI/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\NewsroomMenu\\NewsroomMenuFactory' => $baseDir . '/sources/application/UI/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\PopoverMenu' => $baseDir . '/sources/application/UI/Component/PopoverMenu/PopoverMenu.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index 8f3468568..4420b746e 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -381,13 +381,13 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b '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\\Button' => __DIR__ . '/../..' . '/sources/application/UI/Component/Button/Button.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', 'Combodo\\iTop\\Application\\UI\\Component\\GlobalSearch\\GlobalSearchHelper' => __DIR__ . '/../..' . '/sources/application/UI/Component/GlobalSearch/GlobalSearchHelper.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Html\\Html\\Html' => __DIR__ . '/../..' . '/sources/application/UI/Component/Html/Html.php', - 'Combodo\\iTop\\Application\\UI\\Component\\Panel\\Panel\\Panel' => __DIR__ . '/../..' . '/sources/application/UI/Component/Panel/Panel.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Html\\Html' => __DIR__ . '/../..' . '/sources/application/UI/Component/Html/Html.php', + 'Combodo\\iTop\\Application\\UI\\Component\\Panel\\Panel' => __DIR__ . '/../..' . '/sources/application/UI/Component/Panel/Panel.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\NewsroomMenu\\NewsroomMenu' => __DIR__ . '/../..' . '/sources/application/UI/Component/PopoverMenu/NewsroomMenu/NewsroomMenu.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\NewsroomMenu\\NewsroomMenuFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/PopoverMenu/NewsroomMenu/NewsroomMenuFactory.php', 'Combodo\\iTop\\Application\\UI\\Component\\PopoverMenu\\PopoverMenu' => __DIR__ . '/../..' . '/sources/application/UI/Component/PopoverMenu/PopoverMenu.php', diff --git a/pages/preferences.php b/pages/preferences.php index 653fa9aed..c4100a573 100644 --- a/pages/preferences.php +++ b/pages/preferences.php @@ -17,9 +17,9 @@ * You should have received a copy of the GNU Affero General Public License */ -use Combodo\iTop\Application\UI\Component\Button\Button\Button; -use Combodo\iTop\Application\UI\Component\Html\Html\Html; -use Combodo\iTop\Application\UI\Component\Panel\Panel\Panel; +use Combodo\iTop\Application\UI\Component\Button\ButtonFactory; +use Combodo\iTop\Application\UI\Component\Html\Html; +use Combodo\iTop\Application\UI\Component\Panel\Panel; use Combodo\iTop\Application\UI\Layout\PageContent\PageContentFactory; require_once('../approot.inc.php'); @@ -66,20 +66,22 @@ function DisplayPreferences($oP) ksort($aSortedlang); $sUserLanguageBlockSelect = ''; $sUserLanguageBlockSelect .= '

'.Dict::S('UI:Favorites:SelectYourLanguage').'

'; $sUserLanguageBlockSelect .= ''; $sUserLanguageBlockSelect .= $oAppContext->GetForForm(); - - //$oUserLanguageCancelButton = new Button('ibo-user-language-cancel', Dict::S('UI:Button:Cancel'), '', Dict::S('UI:Button:Cancel'), ) - $oUserLanguageBlockSelect = new Html($sUserLanguageBlockSelect); - $oUserLanguageCancelButton = new Button('ibo-user-language-cancel', Dict::S('UI:Button:Cancel'), '', Dict::S('UI:Button:Cancel'), '', '', '', 'regular', 'secondary', 'window.location.href='.$sURL); - $oUserLanguageSubmitButton = new Button('ibo-user-language-submit', Dict::S('UI:Button:Apply'), '', Dict::S('UI:Button:Apply'), 'submit', '', '', 'regular', 'green'); + + // - Cancel button + $oUserLanguageCancelButton = ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel')); + $oUserLanguageCancelButton->SetOnClickJsCode("window.location.href = '$sURL'"); + // - Submit button + $oUserLanguageSubmitButton = ButtonFactory::MakeForValidationAction(Dict::S('UI:Button:Apply'), null, null, true); + $oUserLanguageEndForm = new Html(''); $oUserLanguageBlock->AddSubBlock($oUserLanguageStartForm); @@ -104,7 +106,8 @@ function DisplayPreferences($oP) $sMiscSettingsHtml = ''; $sMiscSettingsHtml .= '

'.Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '').'

'; - $bShow = utils::IsArchiveMode() || appUserPreferences::GetPref('show_obsolete_data', MetaModel::GetConfig()->Get('obsolescence.show_obsolete_data')); + $bShow = utils::IsArchiveMode() || appUserPreferences::GetPref('show_obsolete_data', + MetaModel::GetConfig()->Get('obsolescence.show_obsolete_data')); $sSelected = $bShow ? ' checked="checked"' : ''; $sDisabled = utils::IsArchiveMode() ? 'disabled="disabled"' : ''; $sMiscSettingsHtml .= @@ -112,26 +115,25 @@ function DisplayPreferences($oP) .'' .'' .'

'; - - $sMiscSettingsHtml .= ''; $sMiscSettingsHtml .= $oAppContext->GetForForm(); - $oMiscSettingsCancelButton = new Button('ibo-misc-settings-cancel', Dict::S('UI:Button:Cancel'), '', Dict::S('UI:Button:Cancel'), '', '', '', 'regular', 'secondary', 'window.location.href='.$sURL); - $oMiscSettingsSubmitButton = new Button('ibo-misc-settings-submit', Dict::S('UI:Button:Apply'), '', Dict::S('UI:Button:Apply'), 'submit', '', '', 'regular', 'green'); - - $oMiscSettingsHtml = new Html($sMiscSettingsHtml); - - $sMiscSettingsEndHtml = ''; - $oMiscSettingsEndHtmlBlock = new Html($sMiscSettingsEndHtml); + + // - Cancel button + $oMiscSettingsCancelButton = ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel')); + $oMiscSettingsCancelButton->SetOnClickJsCode("window.location.href = '$sURL'"); + // - Submit button + $oMiscSettingsSubmitButton = ButtonFactory::MakeForValidationAction(Dict::S('UI:Button:Apply'), 'operation', 'apply_others', true); + + $oMiscSettingsEndHtmlBlock = new Html(''); $oMiscSettingsBlock->AddSubBlock($oMiscSettingsStartForm); $oMiscSettingsBlock->AddSubBlock($oMiscSettingsHtml); $oMiscSettingsBlock->AddSubBlock($oMiscSettingsCancelButton); $oMiscSettingsBlock->AddSubBlock($oMiscSettingsSubmitButton); $oMiscSettingsBlock->AddSubBlock($oMiscSettingsEndHtmlBlock); - + $oContentLayout->AddMainBlock($oMiscSettingsBlock); - + $oP->add_script( <<GetDisplay($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount'=> '.selectedCount', 'table_id' => 'user_prefs')); + $sFavoriteOrganizationsHtml .= $oBlock->GetDisplay($oP, 1, array( + 'menu' => false, + 'selection_mode' => true, + 'selection_type' => 'multiple', + 'cssCount' => '.selectedCount', + 'table_id' => 'user_prefs', + )); $sFavoriteOrganizationsHtml .= $oAppContext->GetForForm(); - $sFavoriteOrganizationsHtml .= ''; - $oFavoriteOrganizationsCancelButton = new Button('ibo-favorite-organizations-cancel', Dict::S('UI:Button:Cancel'), '', Dict::S('UI:Button:Cancel'), '', '', '', 'regular', 'secondary', 'window.location.href='.$sURL); - $oFavoriteOrganizationsSubmitButton = new Button('ibo-favorite-organizations-submit', Dict::S('UI:Button:Apply'), '', Dict::S('UI:Button:Apply'), 'submit', '', '', 'regular', 'green'); - + // - Cancel button + $oFavoriteOrganizationsCancelButton = ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel')); + $oFavoriteOrganizationsCancelButton->SetOnClickJsCode("window.location.href = '$sURL'"); + // - Submit button + $oFavoriteOrganizationsSubmitButton = ButtonFactory::MakeForValidationAction(Dict::S('UI:Button:Apply'), 'operation', 'apply', true); + $sFavoriteOrganizationsEndHtml = ''; - $oFavoriteOrganizationsEndHtmlBlock = new Html($sFavoriteOrganizationsEndHtml) ; - + $oFavoriteOrganizationsEndHtmlBlock = new Html($sFavoriteOrganizationsEndHtml); + $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null); if ($aFavoriteOrgs == null) { // All checked $oP->add_ready_script( -<< 0) { // paginated display, restore the selection @@ -387,21 +398,27 @@ EOF $sPreferencesLink = ' - '.Dict::S('UI:Newsroom:ConfigurationLink').''; } $sChecked = appUserPreferences::GetPref('newsroom_provider_'.$sProviderClass, true) ? ' checked="" ' : ''; - $sNewsroomHtml .= '
'.$sPreferencesLink.'
'; + $sNewsroomHtml .= '
'.$sPreferencesLink.'
'; } } - $sNewsroomHtml .= ''; $sNewsroomHtml .= $oAppContext->GetForForm(); - - $oNewsroomResetCacheButton = new Button('ibo-newsroom-reset-cache', Dict::S('UI:Newsroom:ResetCache'), '', Dict::S('UI:Newsroom:ResetCache'), '', '', '', 'regular', 'red', "$('#ibo-navigation-menu--notifications-menu').newsroom_menu('clearCache')"); - $oNewsroomCancelButton = new Button('ibo-newsroom-cancel', Dict::S('UI:Button:Cancel'), '', Dict::S('UI:Button:Cancel'), '', '', '', 'regular', 'secondary', 'window.location.href='.$sURL); - $oNewsroomSubmitButton = new Button('ibo-newsroom-submit', Dict::S('UI:Button:Apply'), '', Dict::S('UI:Button:Apply'), 'submit', '', '', 'regular', 'green'); - + + // - Reset button + $oNewsroomResetCacheButton = ButtonFactory::MakeForAlternativeDestructiveAction(Dict::S('UI:Newsroom:ResetCache')); + $oNewsroomResetCacheButton->SetOnClickJsCode("$('#ibo-navigation-menu--notifications-menu').newsroom_menu('clearCache')"); + // - Cancel button + $oNewsroomCancelButton = ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel')); + $oNewsroomCancelButton->SetOnClickJsCode("window.location.href = '$sURL'"); + // - Submit button + $oNewsroomSubmitButton = ButtonFactory::MakeForValidationAction(Dict::S('UI:Button:Apply'), 'operation', + 'apply_newsroom_preferences', true); + $sNewsroomEndHtml = ''; $oNewsroomEndHtmlBlock = new Html($sNewsroomEndHtml); - + $oNewsroomHtmlBlock = new Html($sNewsroomHtml); $oNewsroomBlock->AddSubBlock($oNewsroomHtmlBlock); $oNewsroomBlock->AddSubBlock($oNewsroomResetCacheButton); diff --git a/sources/application/UI/Component/Button/Button.php b/sources/application/UI/Component/Button/Button.php index 432157e2f..4b3845e45 100644 --- a/sources/application/UI/Component/Button/Button.php +++ b/sources/application/UI/Component/Button/Button.php @@ -17,8 +17,7 @@ * You should have received a copy of the GNU Affero General Public License */ -namespace Combodo\iTop\Application\UI\Component\Button\Button; - +namespace Combodo\iTop\Application\UI\Component\Button; use Combodo\iTop\Application\UI\UIBlock; @@ -27,7 +26,7 @@ use Combodo\iTop\Application\UI\UIBlock; * Class Button * * @author Stephen Abello - * @package Combodo\iTop\Application\UI\Component\Button\Button + * @package Combodo\iTop\Application\UI\Component\Button * @since 2.8.0 */ class Button extends UIBlock @@ -37,19 +36,55 @@ class Button extends UIBlock const HTML_TEMPLATE_REL_PATH = 'components/button/layout'; const JS_TEMPLATE_REL_PATH = 'components/button/layout'; + // Specific constants + /** @var string ENUM_TYPE_BUTTON */ + const ENUM_TYPE_BUTTON = 'button'; + /** @var string ENUM_TYPE_SUBMIT */ + const ENUM_TYPE_SUBMIT = 'submit'; + /** @var string ENUM_TYPE_RESET */ + const ENUM_TYPE_RESET = 'reset'; + /** @var string DEFAULT_TYPE */ + const DEFAULT_TYPE = self::ENUM_TYPE_BUTTON; + + /** @var string ENUM_ACTION_TYPE_REGULAR */ + const ENUM_ACTION_TYPE_REGULAR = 'regular'; + /** @var string ENUM_ACTION_TYPE_ALTERNATIVE */ + const ENUM_ACTION_TYPE_ALTERNATIVE = 'alternative'; + /** @var string DEFAULT_ACTION_TYPE */ + const DEFAULT_ACTION_TYPE = self::ENUM_ACTION_TYPE_REGULAR; + + /** @var string ENUM_COLOR_NEUTRAL */ + const ENUM_COLOR_NEUTRAL = 'neutral'; + /** @var string ENUM_COLOR_VALIDATION */ + const ENUM_COLOR_VALIDATION = 'green'; + /** @var string ENUM_COLOR_DESTRUCTIVE */ + const ENUM_COLOR_DESTRUCTIVE = 'red'; + /** @var string ENUM_COLOR_PRIMARY */ + const ENUM_COLOR_PRIMARY = 'primary'; + /** @var string ENUM_COLOR_SECONDARY */ + const ENUM_COLOR_SECONDARY = 'secondary'; + /** @var string ENUM_COLOR_GREEN */ + const ENUM_COLOR_GREEN = 'green'; + /** @var string ENUM_COLOR_RED */ + const ENUM_COLOR_RED = 'red'; + /** @var string ENUM_COLOR_CYAN */ + const ENUM_COLOR_CYAN = 'cyan'; + /** @var string DEFAULT_COLOR */ + const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL; + /** @var string $sLabel */ protected $sLabel; - /** @var string $sType */ + /** @var string $sType The HTML type of the button (eg. 'submit', 'button', ...) */ protected $sType; - /** @var string $sName */ + /** @var string $sName The HTML name of the button, used by forms */ protected $sName; - /** @var string $sValue */ + /** @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 */ + /** @var string $sActionType The type of action, a 'regular' action or a 'misc' action */ protected $sActionType; /** @var string $sColor */ protected $sColor; @@ -61,8 +96,8 @@ class Button extends UIBlock /** * Button constructor. * - * @param string $sId * @param string $sLabel + * @param string|null $sId * @param string $sName * @param string $sValue * @param string $sType @@ -73,8 +108,10 @@ class Button extends UIBlock * @param string $sJsCode * @param string $sOnClickJsCode */ - public function __construct($sId, $sLabel, $sName, $sValue, $sType = '', $sTooltip = '', $sIconClass = '', $sActionType = 'regular', $sColor = 'secondary', $sJsCode = '', $sOnClickJsCode = '') - { + public function __construct( + $sLabel, $sId = null, $sName = '', $sValue = '', $sType = self::DEFAULT_TYPE, string $sTooltip = '', $sIconClass = '', + $sActionType = self::DEFAULT_ACTION_TYPE, $sColor = self::DEFAULT_COLOR, $sJsCode = '', $sOnClickJsCode = '' + ) { $this->sLabel = $sLabel; $this->sName = $sName; $this->sValue = $sValue; @@ -97,7 +134,6 @@ class Button extends UIBlock return $this->sLabel; } - /** /** * @param string $sLabel * @@ -220,6 +256,8 @@ class Button extends UIBlock public function SetActionType(string $sActionType) { $this->sActionType = $sActionType; + + return $this; } /** diff --git a/sources/application/UI/Component/Button/ButtonFactory.php b/sources/application/UI/Component/Button/ButtonFactory.php new file mode 100644 index 000000000..70416b214 --- /dev/null +++ b/sources/application/UI/Component/Button/ButtonFactory.php @@ -0,0 +1,240 @@ + + * @package Combodo\iTop\Application\UI\Component\Button + * @since 2.8.0 + */ +class ButtonFactory +{ + /** + * Make a basis Button component for any purpose + * + * @param string $sLabel + * @param string $sName See Button::$sName + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeNeutral(string $sLabel, string $sName): Button + { + $oButton = new Button($sLabel); + $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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForPrimaryAction(string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_PRIMARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForSecondaryAction(string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_SECONDARY, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit); + } + + /** + * Make a Button component for a validation action, should be used to tell the user he/she going to save / validate / confirm his/her + * choices + * + * @param string $sLabel + * @param string|null $sName See Button::$sName + * @param string|null $sValue See Button::$sValue + * @param bool $bIsSubmit See Button::$sType + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForValidationAction(string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_VALIDATION, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForDestructiveAction(string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_REGULAR, $sValue, $sName, + $bIsSubmit); + } + + /** + * Make a basis Button component for any purpose + * + * @param string $sLabel + * @param string $sName See Button::$sName + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeAlternativeNeutral(string $sLabel, string $sName): Button + { + $oButton = new Button($sLabel); + $oButton->SetActionType(Button::ENUM_ACTION_TYPE_ALTERNATIVE) + ->SetColor(Button::ENUM_COLOR_NEUTRAL) + ->SetName($sName); + + return $oButton; + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForAlternativePrimaryAction( + string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_PRIMARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName, + $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForAlternativeSecondaryAction( + string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_SECONDARY, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName, + $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForAlternativeValidationAction( + string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_VALIDATION, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName, + $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + */ + public static function MakeForAlternativeDestructiveAction( + string $sLabel, string $sName = null, string $sValue = null, bool $bIsSubmit = false + ): Button { + return static::MakeForAction($sLabel, Button::ENUM_COLOR_DESTRUCTIVE, Button::ENUM_ACTION_TYPE_ALTERNATIVE, $sValue, $sName, + $bIsSubmit); + } + + /** + * 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 + * + * @return \Combodo\iTop\Application\UI\Component\Button\Button + * @interal + */ + protected static function MakeForAction( + string $sLabel, string $sColor, string $sActionType, string $sValue = null, string $sName = null, bool $bIsSubmit = false + ): Button { + $oButton = new Button($sLabel); + $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; + } +} \ No newline at end of file diff --git a/templates/components/button/layout.js.twig b/templates/components/button/layout.js.twig index 18f31f1a0..0519718fe 100644 --- a/templates/components/button/layout.js.twig +++ b/templates/components/button/layout.js.twig @@ -3,12 +3,13 @@ document.addEventListener("DOMContentLoaded", function(){ setTimeout(function(){ {% if oUIBlock.GetOnClickJsCode() is not empty %} - $('#{{ oUIBlock.GetId() }}').on('click', function(){ - {{ oUIBlock.GetOnClickJsCode() }} - }) + $('#{{ oUIBlock.GetId() }}').on('click', function () + { + {{ oUIBlock.GetOnClickJsCode()|raw }} + }) {% endif %} {% if oUIBlock.GetJsCode() is not empty %} - {{ oUIBlock.GetJsCode() }} + {{ oUIBlock.GetJsCode()|raw }} {% endif %} }, 500); });