Commit 812ccfb5 authored by efalcy's avatar efalcy
Browse files

dev #56107 kiosk configuration: style properties loaded with ajax

parent 920c3dd1
......@@ -183,14 +183,24 @@ class Admin_WidgetController extends ZendAfi_Controller_Action {
public function updateStyleAction() {
$preferences = Class_Systeme_ModulesAccueil::getInstance()->getValeursParDefaut('KIOSQUE');
if ($id_module = $this->_getParam('id')) {
$profil = $this->extractProfilFromUrl();
$preferences = array_merge(Class_Systeme_ModulesAccueil::getInstance()->getValeursParDefaut('KIOSQUE'),
$preferences = array_merge($preferences,
$profil->getModuleAccueilPreferences($id_module, 'KIOSQUE'));
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();
}
$this->getHelper('ViewRenderer')->setNoRender();
$html = $this->view->imgObjectPropertiesReader($this->_getParam('style_liste',''),
$preferences,
true);
$html = Class_ScriptLoader::getInstance()->beAjax()->html() . $html;
$this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8');
$this->getResponse()->setBody(json_encode(['content' => $this->view->imgObjectPropertiesReader($this->_getParam('style_liste',''),$preferences, true)]));
$this->getResponse()->setBody(json_encode(['content' => $html] ));
}
......
......@@ -35,19 +35,20 @@ class JavaController extends ZendAfi_Controller_Action {
// rien ici -> tout est fait par le view-helper
}
public function widgetAction() {
$id_module = $this->_getParam('code','KIOSQUE');
public function kiosqueAction() {
$profil = $this->extractProfilFromUrl();
$id_module = $this->extractIdModuleFromUrl();
$preferences = array_merge(Class_Systeme_ModulesAccueil::getInstance()->getValeursParDefaut('KIOSQUE'),
$this->_request->getParams());
$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();
}
protected function renderView() {
$viewRenderer = $this->getHelper('ViewRenderer');
if(!$this->view->notices) {
......@@ -56,23 +57,9 @@ 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();
}
......
......@@ -38,23 +38,21 @@ class ZendAfi_View_Helper_TagObjetsImgProperties
private function getComboStyles($styles, $valeur_select) {
// $submit_script = '$("select[name=\'style_liste\']").change(function() {$("#styles_reload").val("1");var form=$(this).closest("form"); form.submit();});';
$script = '$("select[name=\'style_liste\']").change(function() {$("#styles_reload").val("1");
$.ajax({
url: "/stl/admin/widget/update-style/style_liste/"+$("#style_liste").val() ,
type: "GET",
dataType: "json",
success: function(data) {
var div = data["content"];
$("#objet_props").html(div);
}
});
});
';
//$(.style_liste option:selected).each( function(index,element) {$($(element)[index]).html(div)
$update_url = $this->view->url(['module' => 'admin',
'controller' => 'widget',
'action' => 'update-style']);
$script = '$("select[name=\'style_liste\']").change(
function() {
$.ajax({
url: "' . $update_url . '/style_liste/" + $("#style_liste").val(),
dataType: "json",
success: function(data) {
var div = data["content"];
$("#objet_props").html(div);
}
});
});';
Class_ScriptLoader::getInstance()
->addJQueryReady($script);
......
......@@ -2323,6 +2323,75 @@ class WidgetControllerGetFormTest extends Admin_AbstractControllerTestCase {
class WidgetControllerUpdateStyleTest extends Admin_AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_json,
$_xpath;
public function setUp() {
parent::setUp();
$this->_xpath = new Storm_Test_XPath();
}
protected function _dispatchUpdateStyle() {
$this->dispatch('/admin/widget/update-style/style_liste/cube',true);
$this->_json = json_decode($this->_response->getBody(), true);
}
/** @test */
public function withoutIdModuleResponseShouldContainsSliderOpHauteurImg() {
$this->_dispatchUpdateStyle();
$this->_xpath->assertXPath($this->_json['content'],
'//input[@name="op_hauteur_img"]',
$this->_json['content']);
}
/** @test */
public function responseShouldContainsSliderJavascriptInAjaxMode() {
$this->_dispatchUpdateStyle();
$this->_xpath->assertXPathContentContains($this->_json['content'],
'//script',
'setTimeout');
}
/** @test */
public function withoutIdModuleResponseShouldContainsDefaultValue150() {
$this->_dispatchUpdateStyle();
$this->_xpath->assertXPathContentContains($this->_json['content'],
'//script',
'value: 150');
}
/** @test */
public function withoutIdModuleResponseShouldContainsValue80() {
$cfg_accueil = ['modules' => ['12' => ['division' => '2',
'type_module' => 'KIOSQUE',
'preferences' => ['style_liste' => 'vignettes',
'op_hauteur_img' => 80]]]];
$this
->fixture('Class_Profil',
['id' => 5,
'libelle' => 'my profile',
'cfg_accueil' => $cfg_accueil])
->beCurrentProfil();
$this->dispatch('/admin/widget/update-style/style_liste/cube/id/12/id_profil/5',true);
$this->_json = json_decode($this->_response->getBody(), true);
$this->_xpath->assertXPathContentContains($this->_json['content'],
'//script',
'value: 80');
}
}
class WidgetControllerGetFormPostTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
......
......@@ -1676,13 +1676,16 @@ class CmsControllerDispatchViewSummaryTest extends AbstractControllerTestCase {
class CmsControllerWithArticleWithKioskTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
class CmsControllerWithArticleWithKioskTestCase extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true;
protected function _loginHook($account) {
$account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL;
$account->PSEUDO = "admin";
}
public function setUp() {
parent::setUp();
$records = [$this->fixture('Class_Notice' , ['id' => 2,
......@@ -1707,8 +1710,16 @@ class CmsControllerWithArticleWithKioskTest extends AbstractControllerTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findAllByRequeteRecherche')
->answers($records);
}
}
class CmsControllerWithArticleWithWallKioskTest extends CmsControllerWithArticleWithKioskTestCase {
public function setUp() {
parent::setUp();
$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>']);
......@@ -1733,6 +1744,26 @@ class CmsControllerWithArticleWithKioskTest extends AbstractControllerTestCase {
public function adminButtonShouldNotBeenShow() {
$this->assertNotXPath('//a[contains(@href,"widget/edit-widget")]',$this->_response->getBody());
}
}
class CmsControllerWithArticleWithCubeKioskTest extends CmsControllerWithArticleWithKioskTestCase {
public function setUp() {
parent::setUp();
$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=cube&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 pageShouldContainsIFrameForCubeKiosque() {
$this->assertXPath( '//iframe[contains(@src, "style_liste/cube")]');;
}
}
\ 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