From e36f71c50dc9bbad1861d38bf08b3e47e27e2b94 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Fri, 5 May 2017 16:22:11 +0200 Subject: [PATCH] dev #59734 zendform PAGE --- .../admin/controllers/ProfilController.php | 56 ++++++++----------- library/Class/ScriptLoader.php | 4 +- .../View/Helper/ProfileComposition.php | 53 +++++++----------- public/admin/css/config_accueil.css | 23 +------- .../input_connect_list/input_connect_list.js | 42 ++++++++++++++ 5 files changed, 88 insertions(+), 90 deletions(-) diff --git a/application/modules/admin/controllers/ProfilController.php b/application/modules/admin/controllers/ProfilController.php index 196a1676682..baa29100434 100644 --- a/application/modules/admin/controllers/ProfilController.php +++ b/application/modules/admin/controllers/ProfilController.php @@ -181,41 +181,34 @@ class Admin_ProfilController extends ZendAfi_Controller_Action { } - private function _parseSaveContentString($cfg_module) { - $enreg = ['modules' => []]; - if(0 == count($cfg_module)) - return $enreg; + protected function _parseSaveContentString() { + $modules = ['modules' => []]; $profil = Class_Profil::find($this->id_profil); - // Decoupage des modules - $modules = array_filter(explode(';box',$cfg_module)); - foreach ($modules as $module) { - $elem = explode('|', $module); - $division=substr($elem[0],-1); + for($division = 1; $division <= Class_Profil::DIV_FLOTANTTE; $division++) { - $id_module=$elem[1]; + if(!$widgets = $this->_getParam('division' . $division)) + continue; - // permet de ne pas écraser un module existant, - // on réaffecte un id si c'est un nouveau module - if ($id_module == 'new') { - $id_module = $profil->createNewModuleAccueilId(); - } - $type_module=$elem[2]; - $str_preferences=trim($elem[3]); + $widgets = explode(';', $widgets); + foreach($widgets as $widget) { + $config = explode('-', $widget); + $id = $config[1]; + $type = $config[0]; + $params = $profil->getModulePref($id); - $preferences = array(); - if(strlen($str_preferences) > 0) { - $props=explode(Class_Profil::PROPERTIES_DELIMITER, $str_preferences); - foreach($props as $prop) { - $names_vals=$this->_splitArg($prop); - $preferences[$names_vals[0]]=$names_vals[1]; + if($id == 0) { + $id = $profil->createNewModuleAccueilId(); + $params = $profil->getDefautBoite($type); } + + $modules['modules'][$id] = array_merge(['division' => $division, + 'type_module' => $type, + 'preferences' => $params]); } - $enreg["modules"][$id_module]=compact("division", - "type_module", - "preferences"); } - return $enreg; + + return $modules; } @@ -262,15 +255,12 @@ class Admin_ProfilController extends ZendAfi_Controller_Action { protected function updateAccueil($profil) { - $profil->setLibelle($this->_getParam('libelle', - $profil->getLibelle())); - - $cfg_module = urldecode($this->_getParam('saveContent')); - $enreg = $this->_parseSaveContentString($cfg_module); - + $enreg = $this->_parseSaveContentString(); $enreg["use_parent_css"] = $this->_getParam('use_parent_css', $profil->getUseParentCss()); $enreg['sitemap'] = $this->_getParam('sitemap'); $enreg["page_css"]=$this->_getParam('page_css'); + + $profil->setLibelle($this->_getParam('libelle', $profil->getLibelle())); $profil->setRewriteUrl($this->_getParam('rewrite_url')); foreach($enreg["modules"] as $id_module => $module_config) { diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index 9e654d218bf..13b05a6c2bc 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -849,8 +849,8 @@ class Class_ScriptLoader { public function loadProfileComposition() { $this - ->addJqueryReady('$("form ul.sortable_list").sortable({connectWith: "form ul.sortable_list", update: function() {var values = $("[id*=mainContainer] ul").sortable("toArray", {attribute: "data-value"});var input = $(".profile_composition input"); input.val( values.join(\';\'));$(".profile_composition").closest("form");}}).disableSelection()') -// ->addAdminScript('config_accueil') + ->addOPACScript('input_connect_list/input_connect_list') + ->addJQueryReady('$(".profile_composition").draggableComposition();') ->addAdminStyleSheet('config_accueil'); return $this; diff --git a/library/ZendAfi/View/Helper/ProfileComposition.php b/library/ZendAfi/View/Helper/ProfileComposition.php index 59e671d790e..dc25410348a 100644 --- a/library/ZendAfi/View/Helper/ProfileComposition.php +++ b/library/ZendAfi/View/Helper/ProfileComposition.php @@ -24,44 +24,34 @@ class ZendAfi_View_Helper_ProfileComposition extends ZendAfi_View_Helper_BaseHel public function ProfileComposition($name, $entity, $attribs = []) { Class_ScriptLoader::getInstance()->loadProfileComposition(); - $html = implode([$this->_dragDropContainer(), - $this->_tag('ul', '', ['id' => 'dragContent']), - $this->_tag('div', - $this->view->tagImg(URL_ADMIN_IMG . 'insert.gif', - ['alt' => $this->_('insérer')]), - ['id' => 'dragDropIndicator']), - $this->_tag('input', '', ['id' => 'saveContent', - 'name' => 'saveContent', - 'type' => 'hidden'])]); - return $this->_tag('div', $html, ['class' => 'profile_composition']); + return $this->_tag('div', + $this->_dragDropContainers(), + ['class' => 'profile_composition']); } - protected function _dragDropContainer() { - $html = [$this->_listOfItems(), + protected function _dragDropContainers() { + $html = [$this->_availableItems(), $this->_mainContainer()]; return $this->_tag('div', - implode($html), - ['id' => 'dhtmlgoodies_dragDropContainer']); + implode($html)); } - protected function _listOfItems() { - $box_dispo = []; + protected function _availableItems() { + $blocks = []; foreach((new Class_Systeme_ModulesAccueil)->getGroupes() as $groupe => $libelle) - $box_dispo[$groupe] = $this->_tag('div', - $this->_tag('h5', $libelle) . - $this->_tag('ul', - $this->_getAvailableWidgetsFor($libelle), - ['id' => 'allItems', - 'class' => 'sortable_list'])); + $blocks[$groupe] = $this->_tag('div', + $this->_tag('h5', $libelle) . + $this->_tag('ul', + $this->_getAvailableWidgetsFor($libelle), + ['class' => 'source_list'])); return $this->_tag('div', $this->_tag('h4', $this->_('Boites disponibles')). - implode($box_dispo), - ['id' => 'dhtmlgoodies_listOfItems', - 'class' => 'drag_drop_container']); + implode($blocks), + ['class' => 'drag_drop_container']); } @@ -91,9 +81,7 @@ class ZendAfi_View_Helper_ProfileComposition extends ZendAfi_View_Helper_BaseHel ['title' => $this->_('Propriétés'), 'data-popup' => 'true']); - return $this->_tag('li', $module . $anchor, ['data-value' => $type_module, - 'id_module' => $id_module, - 'class' => 'cfg_accueil']); + return $this->_tag('li', $module . $anchor, ['data-value' => $type_module . '-' . $id_module]); } @@ -103,13 +91,12 @@ class ZendAfi_View_Helper_ProfileComposition extends ZendAfi_View_Helper_BaseHel $this->_getDivionsColumns()]; return $this->_tag('h4', $this->_('Boites installées')) . - $this->_tag('div', implode($html), ['id' => 'dhtmlgoodies_mainContainer', - 'class' => 'drag_drop_container']); + $this->_tag('div', implode($html), ['class' => 'drag_drop_container']); } protected function _getBannerColumn() { - return $this->_getDivisionColumn(4, $this->_('Division banniere')); + return $this->_getDivisionColumn(4, $this->_('Banniere')); } @@ -132,10 +119,10 @@ class ZendAfi_View_Helper_ProfileComposition extends ZendAfi_View_Helper_BaseHel return $this->_tag('div', $this->_tag('h5', $label) . + $this->_tag('input', null, ['type' => 'hidden', 'name' => 'division' . $column]) . $this->_tag('ul', $this->_getHTMLForDivision($column), - ['id' => sprintf('box%d', $column), - 'class' => 'sortable_list']), + ['class' => 'container_list']), ['data-division' => $column, 'data-divisions' => Class_Profil::getCurrentProfil()->getNbDivisions()]); } diff --git a/public/admin/css/config_accueil.css b/public/admin/css/config_accueil.css index 54ca960b3fa..d7574102ff2 100644 --- a/public/admin/css/config_accueil.css +++ b/public/admin/css/config_accueil.css @@ -28,28 +28,7 @@ cursor:pointer; } - -.profile_composition #dragContent { - position: absolute; - width: 180px; - height: 20px; - display: none; - margin: 0px; - padding: 0px; - z-index: 101; -} - -.profile_composition #dragDropIndicator { - position: absolute; - width: 7px; - height: 10px; - display: none; - z-index: 100; - margin: 0px; - padding: 0px; -} - -.profile_composition [id*="box"] { +.profile_composition ul { min-height: 100px; } diff --git a/public/opac/js/input_connect_list/input_connect_list.js b/public/opac/js/input_connect_list/input_connect_list.js index 787bce4da41..130aeb2f86d 100644 --- a/public/opac/js/input_connect_list/input_connect_list.js +++ b/public/opac/js/input_connect_list/input_connect_list.js @@ -99,3 +99,45 @@ }); }; } (jQuery)); + + +(function ($) { + $.fn.draggableComposition = function(options) { + var widget = $(this); + + var sources = widget.find('ul.source_list'); + var containers = widget.find('ul.container_list'); + var fixed = sources.html(); + var lists = widget.find('ul'); + var action = widget.closest("form").attr("action"); + action += "#fieldset-profile_composition_group"; + widget.closest("form").attr("action", action); + + containers.each(function() { + var values = ""; + $(this).find('li').each(function() { + values += $(this).data("value") + ";"; + }); + $(this).closest('div').find('input').val(values) + }); + + lists.sortable({ + connectWith: 'ul.container_list', + update: function(event, ui) { + var values = ""; + $(event.target).closest('div').find('ul.container_list li').each(function() { + values += $(this).data("value") + ";"; + }); + $(event.target).closest('div').find('input').val(values) + $(event.target).closest('form').submit(); + widget.find('input').change(); + sources.html(fixed); + }, + remove: function(event, ui) { + sources.html(fixed); + } + + }); + }; +} (jQuery)); + -- GitLab