Commit 4babae91 authored by efalcy's avatar efalcy
Browse files

dev #56107 : WIP bokeh ckeditor plugin and display kiosk in article view

parent 4af8a8ef
......@@ -182,6 +182,13 @@ class Admin_WidgetController extends ZendAfi_Controller_Action {
}
public function getFormAction() {
$module = Class_Systeme_ModulesAccueil::moduleByCode($this->_getParam('code'));
$form_class = $module->getForm();
$this->view->form = (new $form_class())->populate(array_merge( $module->getDefaultValues(),$this->_request->getPost()));
}
protected function _readTemplates() {
$templates = file_get_contents(ROOT_PATH . 'public/opac/js/widget_templates/widget_templates.json');
return json_decode($templates, true);
......
<?php echo $this->renderForm($this->form, ZendAfi_View_Helper_RenderForm::NO_BUTTONS) ?>
......@@ -32,8 +32,31 @@ class CmsController extends ZendAfi_Controller_Action {
parent::init();
$this->_helper->getHelper('AjaxContext')
->addActionContext('reseau', 'html')
->initContext();
->addActionContext('reseau', 'html')
->initContext();
$url = Class_Url::assemble(['module' => 'opac',
'controller' => 'java',
'action' => 'widget',
'code' => 'KIOSQUE',
'render' => 'popup']);
Class_ScriptLoader::getInstance()->addJQueryReady('
$(\'.bokeh-widget\').each(function(index,element) {
$.ajax({
url:"'.$url.'",
type: "POST",
data: $(this).attr("data-form"),
dataType: "json",
success: function(data) {
var div = data["content"];
$($(element)[index]).html(div);
}
});
});
');
}
......
......@@ -35,19 +35,19 @@ class JavaController extends ZendAfi_Controller_Action {
// rien ici -> tout est fait par le view-helper
}
public function kiosqueAction() {
$profil = $this->extractProfilFromUrl();
$id_module = $this->extractIdModuleFromUrl();
public function widgetAction() {
$id_module = $this->_getParam('code','KIOSQUE');
$preferences = array_merge(Class_Systeme_ModulesAccueil::getInstance()->getValeursParDefaut('KIOSQUE'),
$profil->getModuleAccueilPreferences($id_module, 'KIOSQUE'));
$preferences = Class_Systeme_ModulesAccueil_Kiosque::updatePreferencesForProfileRedirect($id_module,
$preferences);
$this->_request->getParams());
$this->view->notices = Class_Catalogue::getNoticesByPreferences($preferences);
$this->view->preferences = $preferences;
$this->renderView();
}
protected function renderView() {
$viewRenderer = $this->getHelper('ViewRenderer');
if(!$this->view->notices) {
......@@ -56,9 +56,23 @@ class JavaController extends ZendAfi_Controller_Action {
return;
}
// Redirection vers la bonne vue
$vue = '/java/' . $this->_getParam('vue', 'diaporama').'.phtml';
$viewRenderer->renderScript($vue);
}
public function kiosqueAction() {
$profil = $this->extractProfilFromUrl();
$id_module = $this->extractIdModuleFromUrl();
$preferences = array_merge(Class_Systeme_ModulesAccueil::getInstance()->getValeursParDefaut('KIOSQUE'),
$profil->getModuleAccueilPreferences($id_module, 'KIOSQUE'));
$preferences = Class_Systeme_ModulesAccueil_Kiosque::updatePreferencesForProfileRedirect($id_module,
$preferences);
$this->view->notices = Class_Catalogue::getNoticesByPreferences($preferences);
$this->view->preferences = $preferences;
$this->renderView();
}
......
CKEDITOR.dialog.add( 'basketDialog', function ( editor ) {
return {
title: 'Basket Properties',
minWidth: 400,
minHeight: 200,
title: 'Basket Properties',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-adv',
label: 'Advanced Settings',
contents: [
{
id: 'tab-adv',
label: 'Advanced Settings',
elements: [
{
onLoading: function () {
var htmlElement = this;
elements: [
{
onLoad: function () {
var htmlElement = this;
$.ajax({
url: "http://sandbox.pergame.net/stl/admin/widget/edit-widget/id/10/id_profil/78/render/popup",
type: "get",
datatype: 'json',
success: function (data) {
$('.mybasket').html(data['content']);
},
error: function (xhr, status) {
alert(status);
}
});
},
type: 'html',
className: 'mybasket',
html: ''
}
// UI elements of the second tab will be defined here.
]
}
],
$.ajax({
url: editor.config['perso_var'],
type: "POST",
data: this.getValue(),
datatype: 'json',
success: function (data) {
$('.mybasket').html(data['content']);
},
error: function (xhr, status) {
alert(status);
}
});
},
type: 'html',
className: 'mybasket',
html: '',
setup: function( element ) {
if (element) {
this.setValue( element.prevObject.attr( "data-form" ) );
this.element = element;
}
this.onLoading();
},
commit: function( element ) {
// if (this.element)
// this.element.removeAttribute('div');
}}
// UI elements of the second tab will be defined here.
]
}
],
onShow: function() {
var selection = editor.getSelection();
var element = selection.getStartElement();
this.insertMode = true;
if ( $(element.$).hasClass('bokeh-widget') || $(element.$).closest('bokeh-widget').size ) {
element = $(element.$).closest( 'bokeh-widget' );
this.insertMode = false;
}
this.element = element;
if (!this.insertMode)
return this.setupContent( this.element );
this.setupContent(null);
},
onOk: function() {
var dialog = this;
var abbr = editor.document.createElement( 'div' );
var widget = editor.document.createElement( 'div' );
// widget.setText($('form input #titre').attr('value') );
widget.setText('KIOSQUE');
$(widget)
.attr('data-form', $('.mybasket form').serialize())
.attr('class','bokeh-widget');
this.commitContent(widget);
//editor.document.remove(this.element);
$(abbr).attr('data-form', $('.mybasket form').serialize());
editor.insertElement( abbr );
editor.insertElement( widget );
}
};
......
.bokeh-widget {
background-color: red;
width: 100px;
height: 100px;
}
\ No newline at end of file
......@@ -3,8 +3,28 @@ CKEDITOR.plugins.add( 'bokehsample', {
init: function( editor ) {
CKEDITOR.dialog.add( 'basketDialog', this.path + 'dialogs/basket.js' );
editor.addCommand( 'insertBasket', new CKEDITOR.dialogCommand( 'basketDialog'));
editor.addCommand( 'editBasket', new CKEDITOR.dialogCommand( 'basketDialog'));
editor.addContentsCss( this.path + 'plugin.css' );
if ( editor.contextMenu ) {
editor.addMenuGroup( 'bokehWidgetGroup' );
editor.addMenuItem( 'bokehWidgetItem', {
label: 'Edit widget',
icon: this.path + 'icons/basket.png',
command: 'editBasket',
group: 'bokehWidgetGroup'
});
editor.contextMenu.addListener( function( element ) {
if ( $(element.$).hasClass('bokeh-widget') || $(element.$).closest('bokeh-widget').size ) {
return { bokehWidgetItem: CKEDITOR.TRISTATE_OFF };
}
});
}
// Create a toolbar button that executes the above command.
editor.ui.addButton( 'Basket', {
label: 'Insert Bokeh basket',
......
......@@ -106,7 +106,11 @@ class ZendAfi_View_Helper_CkEditor extends ZendAfi_View_Helper_BaseHelper
['NumberedList','BulletedList','-','Outdent','Indent'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
]);
$config['perso_var'] = Class_Url::assemble(['module' => 'admin',
'controller' => 'widget',
'action' => 'get-form',
'code' => 'KIOSQUE',
'render' => 'popup']);
$config['extraPlugins'] = 'colordialog,bokehsample';
......
......@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_RenderForm extends ZendAfi_View_Helper_BaseHelper {
const NO_BUTTONS = 'no_buttons';
/**
* @param Zend_Form $form
* @return string
......@@ -37,7 +39,9 @@ class ZendAfi_View_Helper_RenderForm extends ZendAfi_View_Helper_BaseHelper {
if ($this->_isFormContainsSubmit($form))
return $form->render();
return $this->_renderFormWithDefaultButtons($form, $buttons);
return $buttons == static::NO_BUTTONS
? $form->render()
: $this->_renderFormWithDefaultButtons($form, $buttons);
}
......
......@@ -94,7 +94,7 @@ class ZendAfi_View_Helper_TagObjetsImgProperties
private function addOptGroupOn($html, $groupLabel, $options, $current) {
$html .= sprintf('<optgroup label="%s" style="font-style:normal;color:#FF6600">',
$groupLabel);
$options = $options ? $options : [];
foreach ($options as $clef => $libelle) {
$selected = ($current == $clef) ? ' selected="selected"' : '';
$html .= sprintf('<option style="color:#666666" value="%s"%s>%s</option>',
......
......@@ -2294,4 +2294,82 @@ class WidgetControllerWidgetAddWidgetFromTemplateTest extends WidgetControllerWi
$this->assertEquals(6,
$this->_module_config['op_timeout']);
}
}
class WidgetControllerGetFormTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->dispatch('/admin/widget/get-form/code/KIOSQUE', true);
}
/** @test */
public function formShouldHaveFieldsetAndTable() {
$this->assertXPath('//fieldset/table');
}
/** @test */
public function formShouldNotHaveSubmitButtons() {
$this->assertNotXPath('//button');
}
}
class WidgetControllerGetFormPostTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/widget/get-form/code/KIOSQUE', ['titre' => 'Boite%20kiosque',
'nb_notices' =>'12']);
}
/** @test */
public function formShouldHaveFieldsetAndTable() {
$this->assertXPath('//fieldset/table');
}
/** @test */
public function formShouldNotHaveSubmitButtons() {
$this->assertNotXPath('//button');
}
/** @test */
public function formShouldHaveDefaultValueButtons() {
$this->assertXPath('//input[@id="nb_notices"][@value="12"]', $this->_response->getBody());
}
}
class WidgetControllerCmsKioskTest extends WidgetControllerWidgetConfigurationTestCase {
public function setUp() {
$this->_type_module = 'KIOSQUE';
$article_en = $this->fixture('Class_Article',
['id' => 2241,
'titre' => 'Feast of fried',
'contenu' => '
an appetizing feast</div>']);
parent::setUp();
$this->dispatch('/opac/cms/articleview/id/2241', true);
}
/** @test */
public function kioskShouldBeDisplayed() {
$this->assertXPath('//div',$this->_response->getBody());
}
}
\ No newline at end of file
......@@ -955,6 +955,7 @@ class CmsControllerArticleViewOnPortalTest extends CmsControllerWithFeteDeLaFrit
public function setUp() {
parent::setUp();
Class_Article::find(224)
->setContent('<div class="bokeh-widget" data-form="titre=ma%20boiboite&amp;style_liste=mycarousel_horizontal&amp;styles_reload=0&amp;op_speed=100&amp;op_largeur_img=120&amp;op_hauteur_img=150&amp;profil_redirect=&amp;id_catalogue=&amp;id_panier=&amp;aleatoire=1&amp;tri=1&amp;nb_notices=20&amp;nb_analyse=50&amp;only_img=1&amp;boite=&amp;rss_avis=0">&nbsp;</div>')
->getCategorie()
->setBib(null)
->assertSave();
......@@ -972,6 +973,15 @@ class CmsControllerArticleViewOnPortalTest extends CmsControllerWithFeteDeLaFrit
public function articleInfoShouldContainsEventBibLinkToBibViewBonlieu() {
$this->assertNotXPath('//dl[@class="article_info"]/dd[@class="event_bib_link"]');
}
/** @test */
public function withKioskShouldDisplayJs() {
$this->postdispatch('/java/widget', ['titre'=> 'Mon kiosque',
'style_liste' => 'mycarousel_horizontal']);
// $this->assertXPathContentContains('//',);
}
}
......
Markdown is supported
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