N°2847 - Button: Add factory, color constants and refactor existing code to use the factory

This commit is contained in:
Molkobain
2020-08-26 15:58:18 +02:00
parent d5f44ffd7b
commit 61ec7f8053
7 changed files with 471 additions and 141 deletions

View File

@@ -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,
),
),
)

View File

@@ -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',

View File

@@ -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',

View File

@@ -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 .= '<p>'.Dict::S('UI:Favorites:SelectYourLanguage').' <select name="language">';
foreach($aSortedlang as $sCode)
{
$sSelected = ($sCode == Dict::GetUserLanguage()) ? 'selected' : '';
$sUserLanguageBlockSelect .= '<option value="'.$sCode.'" '.$sSelected.'/>'.$aLanguages[$sCode]['description'].' ('.$aLanguages[$sCode]['localized_description'].')</option>';
}
foreach ($aSortedlang as $sCode)
{
$sSelected = ($sCode == Dict::GetUserLanguage()) ? 'selected' : '';
$sUserLanguageBlockSelect .= '<option value="'.$sCode.'" '.$sSelected.'/>'.$aLanguages[$sCode]['description'].' ('.$aLanguages[$sCode]['localized_description'].')</option>';
}
$sUserLanguageBlockSelect .= '</select></p>';
$sUserLanguageBlockSelect .= '<input type="hidden" name="operation" value="apply_language"/>';
$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('</form>');
$oUserLanguageBlock->AddSubBlock($oUserLanguageStartForm);
@@ -104,7 +106,8 @@ function DisplayPreferences($oP)
$sMiscSettingsHtml = '';
$sMiscSettingsHtml .= '<p>'.Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '<input id="default_page_size" name="default_page_size" type="text" size="3" value="'.$iDefaultPageSize.'"/><span id="v_default_page_size"></span>').'</p>';
$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)
.'<input type="checkbox" id="show_obsolete_data" name="show_obsolete_data" value="1"'.$sSelected.$sDisabled.'>'
.'<label for="show_obsolete_data" title="'.Dict::S('UI:Favorites:ShowObsoleteData+').'">'.Dict::S('UI:Favorites:ShowObsoleteData').'</label>'
.'</p>';
$sMiscSettingsHtml .= '<input type="hidden" name="operation" value="apply_others"/>';
$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 = '</form>';
$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('</form>');
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsStartForm);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsHtml);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsCancelButton);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsSubmitButton);
$oMiscSettingsBlock->AddSubBlock($oMiscSettingsEndHtmlBlock);
$oContentLayout->AddMainBlock($oMiscSettingsBlock);
$oP->add_script(
<<<EOF
function ValidateOtherSettings()
@@ -153,6 +155,7 @@ function ValidateOtherSettings()
}
EOF
);
//////////////////////////////////////////////////////////////////////////
//
// Favorite Organizations
@@ -163,27 +166,35 @@ EOF
$sFavoriteOrganizationsHtml = '';
$sFavoriteOrganizationsHtml .= Dict::S('UI:FavoriteOrganizations+');
$sFavoriteOrganizationsHtml .= '<form method="post">';
$sFavoriteOrganizationsHtml .= '<form method="post">';
// Favorite organizations: the organizations listed in the drop-down menu
$sOQL = ApplicationMenu::GetFavoriteSiloQuery();
$oFilter = DBObjectSearch::FromOQL($sOQL);
$oBlock = new DisplayBlock($oFilter, 'list', false);
$sFavoriteOrganizationsHtml .= $oBlock->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 .= '<input type="hidden" name="operation" value="apply"/>';
$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 = '</form>';
$oFavoriteOrganizationsEndHtmlBlock = new Html($sFavoriteOrganizationsEndHtml) ;
$oFavoriteOrganizationsEndHtmlBlock = new Html($sFavoriteOrganizationsEndHtml);
$aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
if ($aFavoriteOrgs == null)
{
// All checked
$oP->add_ready_script(
<<<EOF
<<<EOF
if ($('#user_prefs table.pagination').length > 0)
{
// paginated display, restore the selection
@@ -387,21 +398,27 @@ EOF
$sPreferencesLink = ' - <a class=".newsroom-configuration-link" href="'.$sUrl.'"'.$sTarget.'>'.Dict::S('UI:Newsroom:ConfigurationLink').'</a>';
}
$sChecked = appUserPreferences::GetPref('newsroom_provider_'.$sProviderClass, true) ? ' checked="" ' : '';
$sNewsroomHtml .= '<div><input type="checkbox" id="newsroom_provider_'.$sProviderClass.'" value="on"'.$sChecked.'name="newsroom_provider_'.$sProviderClass.'"><label for="newsroom_provider_'.$sProviderClass.'">'.Dict::Format('UI:Newsroom:DisplayMessagesFor_Provider', $oProvider->GetLabel()).'</label> '.$sPreferencesLink.'</div>';
$sNewsroomHtml .= '<div><input type="checkbox" id="newsroom_provider_'.$sProviderClass.'" value="on"'.$sChecked.'name="newsroom_provider_'.$sProviderClass.'"><label for="newsroom_provider_'.$sProviderClass.'">'.Dict::Format('UI:Newsroom:DisplayMessagesFor_Provider',
$oProvider->GetLabel()).'</label> '.$sPreferencesLink.'</div>';
}
}
$sNewsroomHtml .= '<input type="hidden" name="operation" value="apply_newsroom_preferences"/>';
$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 = '</form>';
$oNewsroomEndHtmlBlock = new Html($sNewsroomEndHtml);
$oNewsroomHtmlBlock = new Html($sNewsroomHtml);
$oNewsroomBlock->AddSubBlock($oNewsroomHtmlBlock);
$oNewsroomBlock->AddSubBlock($oNewsroomResetCacheButton);

View File

@@ -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 <stephen.abello@combodo.com>
* @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;
}
/**

View File

@@ -0,0 +1,240 @@
<?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\Button;
use Combodo\iTop\Application\UI\Component\Button\Button;
/**
* Class ButtonFactory
*
* @internal
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
* @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;
}
}

View File

@@ -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);
});