mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°2629 Allow user to choose default expanded/collapsed toolbar for richtext editors
This commit is contained in:
@@ -2012,11 +2012,7 @@ EOF
|
||||
// To change the default settings of the editor,
|
||||
// a) edit the file /js/ckeditor/config.js
|
||||
// b) or override some of the configuration settings, using the second parameter of ckeditor()
|
||||
$aConfig = array();
|
||||
$sLanguage = strtolower(trim(UserRights::GetUserLanguage()));
|
||||
$aConfig['language'] = $sLanguage;
|
||||
$aConfig['contentsLanguage'] = $sLanguage;
|
||||
$aConfig['extraPlugins'] = 'disabler,codesnippet';
|
||||
$aConfig = utils::GetCkeditorPref();
|
||||
$aConfig['placeholder'] = Dict::S('UI:CaseLogTypeYourTextHere');
|
||||
$sConfigJS = json_encode($aConfig);
|
||||
|
||||
|
||||
@@ -70,11 +70,7 @@ class UIHTMLEditorWidget
|
||||
// To change the default settings of the editor,
|
||||
// a) edit the file /js/ckeditor/config.js
|
||||
// b) or override some of the configuration settings, using the second parameter of ckeditor()
|
||||
$aConfig = array();
|
||||
$sLanguage = strtolower(trim(UserRights::GetUserLanguage()));
|
||||
$aConfig['language'] = $sLanguage;
|
||||
$aConfig['contentsLanguage'] = $sLanguage;
|
||||
$aConfig['extraPlugins'] = 'disabler,codesnippet';
|
||||
$aConfig = utils::GetCkeditorPref();
|
||||
$sWidthSpec = addslashes(trim($this->m_oAttDef->GetWidth()));
|
||||
if ($sWidthSpec != '')
|
||||
{
|
||||
|
||||
@@ -2471,4 +2471,19 @@ class utils
|
||||
{
|
||||
return static::$iNextId++;
|
||||
}
|
||||
|
||||
public static function GetCkeditorPref()
|
||||
{
|
||||
$sLanguage = strtolower(trim(UserRights::GetUserLanguage()));
|
||||
|
||||
$aDefaultConf = array('language'=> $sLanguage,
|
||||
'contentsLanguage' => $sLanguage,
|
||||
'extraPlugins' => 'disabler,codesnippet',
|
||||
);
|
||||
|
||||
$aRichTextConfig = json_decode(appUserPreferences::GetPref('richtext_config', '{}'), true);
|
||||
|
||||
|
||||
return array_merge($aDefaultConf, $aRichTextConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ Dict::Add('EN US', 'English', 'English', array(
|
||||
'UI:Preferences:Title' => 'Preferences',
|
||||
'UI:Preferences:ChooseAPlaceholder' => 'User placeholder image',
|
||||
'UI:Preferences:ChooseAPlaceholder+' => 'Choose a placeholder image that will be displayed if the contact linked to your user doesn\'t have one',
|
||||
'UI:RichText:Preferences' => 'Rich text editor',
|
||||
'UI:RichText:ToolbarState' => 'Toolbar default state',
|
||||
'UI:RichText:ToolbarState:Expanded' => 'Expanded',
|
||||
'UI:RichText:ToolbarState:Collapsed' => 'Collapsed',
|
||||
));
|
||||
@@ -381,6 +381,32 @@ EOF
|
||||
$oNewsroomBlock->AddSubBlock($oNewsroomEndHtmlBlock);
|
||||
$oContentLayout->AddMainBlock($oNewsroomBlock);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Rich text editor preferences
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
$oRichTextBlock = new Panel(Dict::S('UI:RichText:Preferences'), array(), 'grey', 'ibo-richtext');
|
||||
|
||||
$oRichTextForm = new Form();
|
||||
$oRichTextForm->AddSubBlock(InputFactory::MakeForHidden('operation', 'apply_richtext_config'));
|
||||
|
||||
$sRichTextToolbarDefaultState = isset(utils::GetCkeditorPref()['toolbarStartupExpanded']) ? (bool)utils::GetCkeditorPref()['toolbarStartupExpanded'] : false;
|
||||
$oRichTextToolbarDefaultStateInput = InputFactory::MakeForSelectWithLabel('toolbarexpanded', Dict::S('UI:RichText:ToolbarState'));
|
||||
$oRichTextToolbarDefaultStateInput->GetInput()->AddOption(InputFactory::MakeForSelectOption('true', Dict::S('UI:RichText:ToolbarState:Expanded'), $sRichTextToolbarDefaultState));
|
||||
$oRichTextToolbarDefaultStateInput->GetInput()->AddOption(InputFactory::MakeForSelectOption('false', Dict::S('UI:RichText:ToolbarState:Collapsed'), !$sRichTextToolbarDefaultState));
|
||||
$oRichTextForm->AddSubBlock($oRichTextToolbarDefaultStateInput);
|
||||
|
||||
// - Cancel button
|
||||
$oRichTextCancelButton = ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel'));
|
||||
$oRichTextCancelButton->SetOnClickJsCode("window.location.href = '$sURL'");
|
||||
$oRichTextForm->AddSubBlock($oRichTextCancelButton);
|
||||
// - Submit button
|
||||
$oRichTextSubmitButton = ButtonFactory::MakeForPrimaryAction(Dict::S('UI:Button:Apply'), null, null, true);
|
||||
$oRichTextForm->AddSubBlock($oRichTextSubmitButton);
|
||||
|
||||
$oRichTextBlock->AddSubBlock($oRichTextForm);
|
||||
$oContentLayout->AddMainBlock($oRichTextBlock);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -532,7 +558,15 @@ try
|
||||
}
|
||||
DisplayPreferences($oPage);
|
||||
break;
|
||||
|
||||
case 'apply_richtext_config':
|
||||
$aRichTextConfig = json_decode(appUserPreferences::GetPref('richtext_config', '{}'), true);
|
||||
|
||||
$bToolbarExpanded = utils::ReadParam('toolbarexpanded', 'false') === 'true';
|
||||
$aRichTextConfig['toolbarStartupExpanded'] = $bToolbarExpanded;
|
||||
|
||||
appUserPreferences::SetPref('richtext_config', json_encode($aRichTextConfig));
|
||||
DisplayPreferences($oPage);
|
||||
break;
|
||||
case 'apply_language':
|
||||
$sLangCode = utils::ReadParam('language', 'EN US');
|
||||
$oUser = UserRights::GetUserObject();
|
||||
|
||||
@@ -153,11 +153,14 @@ EOF
|
||||
|
||||
// Some additional stuff if we are displaying it with a rich editor
|
||||
if ($bRichEditor) {
|
||||
$sEditorLanguage = strtolower(trim(UserRights::GetUserLanguage()));
|
||||
$aConfig = utils::GetCkeditorPref();
|
||||
$aConfig['extraPlugins'] = 'codesnippet';
|
||||
$sJsConfig = json_encode($aConfig);
|
||||
|
||||
$oOutput->AddJs(
|
||||
<<<EOF
|
||||
$('#{$this->oField->GetGlobalId()}').addClass('htmlEditor');
|
||||
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, {language: '$sEditorLanguage', contentsLanguage: '$sEditorLanguage', extraPlugins: 'codesnippet'}).editor.on("change", function(){
|
||||
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, $sJsConfig).editor.on("change", function(){
|
||||
$('#{$this->oField->GetGlobalId()}').trigger("change");
|
||||
});
|
||||
EOF
|
||||
|
||||
@@ -103,11 +103,14 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
|
||||
// Some additional stuff if we are displaying it with a rich editor
|
||||
if ($bRichEditor)
|
||||
{
|
||||
$sEditorLanguage = strtolower(trim(UserRights::GetUserLanguage()));
|
||||
$aConfig = utils::GetCkeditorPref();
|
||||
$aConfig['extraPlugins'] = 'codesnippet';
|
||||
$sJsConfig = json_encode($aConfig);
|
||||
|
||||
$oOutput->AddJs(
|
||||
<<<EOF
|
||||
$('#{$this->oField->GetGlobalId()}').addClass('htmlEditor');
|
||||
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, {language: '$sEditorLanguage', contentsLanguage: '$sEditorLanguage', extraPlugins: 'codesnippet'});
|
||||
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, $sJsConfig);
|
||||
EOF
|
||||
);
|
||||
if (($this->oField->GetObject() !== null) && ($this->oField->GetTransactionId() !== null))
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\Input\RichText;
|
||||
use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class RichText
|
||||
@@ -17,4 +18,26 @@ class RichText extends UIBlock
|
||||
public const BLOCK_CODE = 'ibo-richtext';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/input/richtext/layout';
|
||||
/** @var string */
|
||||
protected $aConfig;
|
||||
|
||||
/**
|
||||
* RichText constructor.
|
||||
*
|
||||
* @param string|null $sId
|
||||
*/
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
$this->aConfig = json_encode(utils::GetCkeditorPref());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetConfig()
|
||||
{
|
||||
return $this->aConfig;
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
$('#{{ oUIBlock.GetId() }}').ckeditor(function() { /* callback code */ }, {'language': 'en', 'contentsLanguage' : 'en', 'extraPlugins' : 'disabler,codesnippet'});
|
||||
$('#{{ oUIBlock.GetId() }}').ckeditor(function() { /* callback code */ }, {{ oUIBlock.GetConfig()| raw }});
|
||||
Reference in New Issue
Block a user