Commit f16a4c09 authored by efalcy's avatar efalcy
Browse files

dev #56107 : display widget inside article

parent c2100896
......@@ -39,23 +39,6 @@ class CmsController extends ZendAfi_Controller_Action {
'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);
}
});
});
');
}
......
......@@ -45,6 +45,7 @@ abstract class ZendAfi_View_Helper_Article_RenderAbstract
}
public function tagArticleEvent($article) {
return $this->view->tagArticleEvent($article);
}
......@@ -90,10 +91,11 @@ abstract class ZendAfi_View_Helper_Article_RenderAbstract
public function renderContent($article) {
if (!$article->hasSummary())
return $article->getFullContent();
$content = (!$article->hasSummary()) ?
$this->renderSummary($article)
: $article->getFullContent();
return $this->view->article_ReplaceWidgets($content);
return $this->renderSummary($article);
}
......
......@@ -28,7 +28,7 @@ class ZendAfi_View_Helper_Article_RenderFullContent extends ZendAfi_View_Helper_
}
public function renderContent($article) {
return $article->getFullContent();
return $this->view->article_ReplaceWidgets($article->getFullContent());
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, 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_View_Helper_Article_ReplaceWidgets extends ZendAfi_View_Helper_BaseHelper {
public function article_ReplaceWidgets($content) {
// '|<div[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>\w+)"[^>]*>[^<]+</div>|',
return preg_replace_callback(
'|(?P<alldiv><div[^>]+data-code="(?P<code>\w+)"[^>]+data-form="(?P<form>[^"]+)[^>]*>[^<]+</div>)|',
function ($matches) {
return $this->_renderWidget($matches['code'],$matches['form']);
},
$content
);
}
protected function _renderWidget($code,$form) {
$prefs = [];
parse_str(html_entity_decode($form),$prefs);
$params=['type_module'=> $code,
'preferences' => $prefs];
xdebug_break();
$helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams(null,$params,$this->view);
return $helper->getBoite();
//Class_Systeme_ModulesAccueil::moduleByCode($code)
}
}
?>
\ No newline at end of file
CKEDITOR.dialog.add( 'kioskDialog', function ( editor ) {
return {
var dialog = {
title: 'Bokeh Kiosk Properties',
minWidth: 400,
minHeight: 200,
......@@ -44,11 +43,17 @@ CKEDITOR.dialog.add( 'kioskDialog', function ( editor ) {
],
isBokehKiosk: function(element) {
return
( $(element.$).hasClass('bokeh-kiosk') || $(element.$).closest('bokeh-kiosk').size );
},
onShow: function() {
var selection = editor.getSelection();
var element = selection.getStartElement();
this.insertMode = true;
if ( $(element.$).hasClass('bokeh-kiosk') || $(element.$).closest('bokeh-kiosk').size ) {
if (dialog.isBokehKiosk(element)) {
element = $(element.$).closest( 'bokeh-kiosk' );
this.insertMode = false;
}
......@@ -57,13 +62,11 @@ CKEDITOR.dialog.add( 'kioskDialog', function ( editor ) {
return this.setupContent( this.element );
this.setupContent(null);
},
onOk: function() {
var dialog = this;
var selection = editor.getSelection();
var widget = selection.getStartElement();
if (!widget) {
if (!widget || !dialog.isBokehKiosk(widget)) {
widget = editor.document.createElement( 'div' );
editor.insertElement( widget );
}
......@@ -74,9 +77,14 @@ CKEDITOR.dialog.add( 'kioskDialog', function ( editor ) {
$(widget)
.attr('data-form', $('.bokeh-kiosk-form form').serialize())
.attr('data-code', 'KIOSQUE')
.attr('class','bokeh-kiosk');
},10);
}
};
});
return dialog;
}
)
;
.bokeh-widget {
.bokeh-kiosk {
background-color: red;
width: 100px;
height: 100px;
......
......@@ -8,17 +8,17 @@ CKEDITOR.plugins.add( 'bokeh-kiosk', {
editor.addContentsCss( this.path + 'plugin.css' );
if ( editor.contextMenu ) {
editor.addMenuGroup( 'bokehWidgetGroup' );
editor.addMenuItem( 'bokehWidgetItem', {
label: 'Edit widget',
editor.addMenuGroup( 'bokehKioskGroup' );
editor.addMenuItem( 'bokehKioskItem', {
label: 'Edit kiosk',
icon: this.path + 'icons/basket.png',
command: 'editKiosk',
group: 'bokehWidgetGroup'
group: 'bokehKioskGroup'
});
editor.contextMenu.addListener( function( element ) {
if ( $(element.$).hasClass('bokeh-widget') || $(element.$).closest('bokeh-widget').size ) {
return { bokehWidgetItem: CKEDITOR.TRISTATE_OFF };
if ( $(element.$).hasClass('bokeh-kiosk') || $(element.$).closest('bokeh-kiosk').size ) {
return { bokehKioskItem: CKEDITOR.TRISTATE_OFF };
}
});
}
......
......@@ -2350,26 +2350,3 @@ class WidgetControllerGetFormPostTest extends Admin_AbstractControllerTestCase {
}
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
......@@ -954,11 +954,6 @@ class CmsControllerArticleViewInEnglishTest extends CmsControllerWithFeteDeLaFri
class CmsControllerArticleViewOnPortalTest extends CmsControllerWithFeteDeLaFriteTestCase {
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();
$this->dispatch('/cms/articleview/id/224', true);
}
......@@ -977,8 +972,9 @@ class CmsControllerArticleViewOnPortalTest extends CmsControllerWithFeteDeLaFrit
/** @test */
public function withKioskShouldDisplayJs() {
$this->postdispatch('/java/widget', ['titre'=> 'Mon kiosque',
'style_liste' => 'mycarousel_horizontal']);
// $this->assertXPathContentContains('//',);
'style_liste' => 'mycarousel_horizontal']);
}
......@@ -1675,4 +1671,58 @@ class CmsControllerDispatchViewSummaryTest extends AbstractControllerTestCase {
public function profilShouldBe3() {
$this->assertXpath('//body[contains(@class, "profil_1")]');
}
}
class CmsControllerWithArticleWithKioskTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$records = [$this->fixture('Class_Notice' , ['id' => 2,
'unimarc' => file_get_contents(ROOT_PATH.'/tests/fixtures/dvd_potter.uni'),
'url_vignette' => 'hp.png',
'url_image' => 'hp_big.png',
'facettes' => 'D123 A400 Y2',
'clef_oeuvre' => 'HPELPA',
'clef_alpha' => 'POTTER',
'exemplaires' => []]),
$this->fixture('Class_Notice' , ['id' => 45,
'unimarc' => file_get_contents(ROOT_PATH.'/tests/fixtures/jeune_fille_dvd.uni'),
'url_vignette' => 'jeune_fille.png',
'url_image' => 'jeune_fille_big.png',
'facettes' => 'D13 A10 Y1',
'clef_oeuvre' => 'JF',
'clef_alpha' => 'JF',
'exemplaires' => []]),
];
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findAllByRequeteRecherche')
->answers($records);
$this->fixture('Class_Article', [ 'id' => 55,
'titre' => 'Mes dvds',
'contenu' => '<div class="bokeh-kiosk" data-code="KIOSQUE" data-form="titre=Boite%20kiosque&amp;style_liste=mur&amp;styles_reload=0&amp;op_speed=100&amp;op_largeur_img=120&amp;op_hauteur_img=150&amp;profil_redirect=&amp;id_catalogue=0&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">KIOSQUE</div>']);
$this->dispatch('/cms/articleview/id/55',true);
}
/** @test */
public function bokehKioskShouldBeRemoved() {
$this->assertNotXPath('//div[@class="bokeh-kiosk"]');
}
/** @test */
public function pageShouldContainsKiosk() {
$this->assertXPath( '//div[@class="liste_mur"]');;
}
}
\ No newline at end of file
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