Skip to content
Snippets Groups Projects
Commit d39b5c9e authored by Laurent's avatar Laurent
Browse files

Add admin var for editor

parent 9dadfd35
No related merge requests found
Pipeline #18998 failed with stage
in 21 minutes and 17 seconds
This commit is part of merge request !4580. Comments created here will be created in the context of that merge request.
...@@ -143,6 +143,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader { ...@@ -143,6 +143,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
'activity' => $this->_getActivityVars(), 'activity' => $this->_getActivityVars(),
'pellicule' => $this->_getPelliculeVars(), 'pellicule' => $this->_getPelliculeVars(),
'rgpd' => (new Class_AdminVar_Cookies())->meta(), 'rgpd' => (new Class_AdminVar_Cookies())->meta(),
'print' => $this->_getPrintModelVars()
]; ];
} }
...@@ -450,6 +451,16 @@ Pour vous désabonner de la lettre d\'information, merci de cliquer sur le lien ...@@ -450,6 +451,16 @@ Pour vous désabonner de la lettre d\'information, merci de cliquer sur le lien
} }
protected function _getPrintModelVars() : array {
return [
'PRINT_MODELS_EDITOR' => Class_AdminVar_Meta::newCombo($this->_('Éditeur utilisé pour les modèles d\'impression'),
['options' => ['selectOptions' => ['label' => $this->_('Éditeur'),
'multioptions' => ['CKEDITOR' => 'CKEditor',
'CODE_MIRROR' => 'CodeMirror']]]])
];
}
protected function _getCommentVars() { protected function _getCommentVars() {
return [ return [
'AVIS_MAX_SAISIE' => Class_AdminVar_Meta::newDefault($this->_('Nombre de caractères maximum autorisé à saisir dans les avis.')), 'AVIS_MAX_SAISIE' => Class_AdminVar_Meta::newDefault($this->_('Nombre de caractères maximum autorisé à saisir dans les avis.')),
......
...@@ -38,24 +38,5 @@ class ZendAfi_Controller_Plugin_Manager_ModeleFusion extends ZendAfi_Controller_ ...@@ -38,24 +38,5 @@ class ZendAfi_Controller_Plugin_Manager_ModeleFusion extends ZendAfi_Controller_
Class_ModeleFusion::generateDefaults($this->_view); Class_ModeleFusion::generateDefaults($this->_view);
$this->_redirectToReferer(); $this->_redirectToReferer();
} }
protected function _postEditAction($model) {
Class_ScriptLoader::getInstance()
->loadCodeMirror()
->addAdminScript('codemirror-4.4/mode/css/css')
->addAdminScript('codemirror-4.4/mode/xml/xml')
->addAdminScript('codemirror-4.4/mode/htmlmixed/htmlmixed')
->addInlineStyle('.CodeMirror-wrap { height: 500px }')
->addJQueryReady("
CodeMirror.fromTextArea($('textarea[name=\'contenu\']')[0],
{
lineNumbers:true,
tabSize:2,
matchBrackets:true,
lineWrapping:true,
mode: 'htmlmixed'
});");
}
} }
?> ?>
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Form_Decorator_CodeMirror extends Zend_Form_Decorator_Abstract {
public function render($content) {
Class_ScriptLoader::getInstance()
->loadCodeMirror()
->addAdminScript('codemirror-4.4/mode/css/css')
->addAdminScript('codemirror-4.4/mode/xml/xml')
->addAdminScript('codemirror-4.4/mode/htmlmixed/htmlmixed')
->addInlineStyle('.CodeMirror-wrap { height: 500px }')
->addJQueryReady("
CodeMirror.fromTextArea($('textarea[name=\'" . $this->_element->getName() . "\']')[0],
{
lineNumbers:true,
tabSize:2,
matchBrackets:true,
lineWrapping:true,
mode: 'htmlmixed'
});");
return $content . $this->_element->getView()->tag('textarea',
$this->_element->getValue(),
['name' => $this->_element->getName()]);
}
}
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Form_Element_CodeMirror extends ZendAfi_Form_Element_XhtmlOnViewHelper {
protected $_decorator_name = 'CodeMirror';
}
...@@ -44,7 +44,9 @@ class ZendAfi_Form_ModeleFusion extends ZendAfi_Form { ...@@ -44,7 +44,9 @@ class ZendAfi_Form_ModeleFusion extends ZendAfi_Form {
'profil_ids', 'profil_ids',
['label' => $form->_('Afficher pour les profils (separé par des ;)'), ['label' => $form->_('Afficher pour les profils (separé par des ;)'),
]) ])
->addElement('textarea', ->addElement(Class_AdminVar::get('PRINT_MODELS_EDITOR') === 'CODE_MIRROR'
? 'codeMirror'
: 'ckeditor',
'contenu', 'contenu',
[ [
'label' => '', 'label' => '',
......
...@@ -48,6 +48,11 @@ class PrintControllerIndexTest extends Admin_AbstractControllerTestCase { ...@@ -48,6 +48,11 @@ class PrintControllerIndexTest extends Admin_AbstractControllerTestCase {
public function generateLinkShouldBePresent() { public function generateLinkShouldBePresent() {
$this->assertXPathContentContains('//button[contains(@onclick, "/admin/print/generate")]', 'Générer'); $this->assertXPathContentContains('//button[contains(@onclick, "/admin/print/generate")]', 'Générer');
} }
/** @test */
public function pageShouldContainsLinkToAdminPrintConfigForAdminVars() {
$this->assertXPath('//a[contains(@href, "admin/print/config")]');
}
} }
...@@ -170,7 +175,7 @@ class PrintControllerPostActionTest extends AbstractControllerTestCase { ...@@ -170,7 +175,7 @@ class PrintControllerPostActionTest extends AbstractControllerTestCase {
class PrintControllerAdminEditTest extends AbstractControllerTestCase { abstract class PrintControllerAdminEditTestCase extends AbstractControllerTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->fixture(Class_ModeleFusion::class, $this->fixture(Class_ModeleFusion::class,
...@@ -179,7 +184,16 @@ class PrintControllerAdminEditTest extends AbstractControllerTestCase { ...@@ -179,7 +184,16 @@ class PrintControllerAdminEditTest extends AbstractControllerTestCase {
'contenu' => '<p> {notices.each[<img src="{url_vignette}"/> {titre_principal} <div>{article.contenu}</div> 'contenu' => '<p> {notices.each[<img src="{url_vignette}"/> {titre_principal} <div>{article.contenu}</div>
]}</p>', ]}</p>',
'type' => 'Notice_List']); 'type' => 'Notice_List']);
}
}
class PrintControllerAdminEditWithCodeMirrorTest extends PrintControllerAdminEditTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('PRINT_MODELS_EDITOR', 'CODE_MIRROR');
$this->dispatch('/admin/print/edit/id/1'); $this->dispatch('/admin/print/edit/id/1');
} }
...@@ -195,4 +209,39 @@ class PrintControllerAdminEditTest extends AbstractControllerTestCase { ...@@ -195,4 +209,39 @@ class PrintControllerAdminEditTest extends AbstractControllerTestCase {
public function pageShouldLoadCodeMirror() { public function pageShouldLoadCodeMirror() {
$this->assertXPathContentContains('//script', 'CodeMirror.fromTextArea($(\'textarea[name=\\\'contenu\\\''); $this->assertXPathContentContains('//script', 'CodeMirror.fromTextArea($(\'textarea[name=\\\'contenu\\\'');
} }
/** @test */
public function pageShouldNotLoadCKEditor() {
$this->assertNotXPathContentContains('//script', 'CKEDITOR');
}
}
class PrintControllerAdminEditWithCKEditorTest extends PrintControllerAdminEditTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/print/edit/id/1');
}
/** @test */
public function textAreaShouldContainsContentNoticesEach() {
$this->assertXPathContentContains('//textarea[@name="contenu"]',
'notices.each[');
}
/** @test */
public function pageShouldNotLoadCodeMirror() {
$this->assertNotXPathContentContains('//script', 'CodeMirror');
}
/** @test */
public function pageShouldLoadCKEditor() {
$this->assertXPathContentContains('//script', 'CKEDITOR');
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment