From 4e20254db18eb9b33cd4ce96b53a911a80431842 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 31 May 2017 17:12:31 +0200 Subject: [PATCH] dev #60900 refacto js function --- .../ZendAfi/View/Helper/Admin/FrontNav.php | 71 ++++++++++++----- library/ZendAfi/View/Helper/Portail.php | 19 ++--- public/admin/js/global.js | 79 ++++--------------- public/admin/skins/bokeh74/front_nav.css | 4 - .../opac/controllers/IndexControllerTest.php | 13 ++- 5 files changed, 82 insertions(+), 104 deletions(-) diff --git a/library/ZendAfi/View/Helper/Admin/FrontNav.php b/library/ZendAfi/View/Helper/Admin/FrontNav.php index 9a712515dfe..3c3cb5f03cd 100644 --- a/library/ZendAfi/View/Helper/Admin/FrontNav.php +++ b/library/ZendAfi/View/Helper/Admin/FrontNav.php @@ -102,28 +102,28 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper $this->_toggleAnchor($this->_('Déplacement des boites'), 'block_sorting', - 'reactiveOpacBlocksSorting()', - 'deactiveOpacBlocksSorting()'), + sprintf('opacBlocksSorting(\'%s\',%d); $("div.layout-division>div").sortable("enable");', Class_Url::absolute('/admin/profil/module-sort'), Class_Profil::getCurrentProfil()->getId()), + '$("div.layout-division>div").sortable("disable");'), $this->_toggleAnchor($this->_('Afficher les icones d\'administration'), 'show_admin_icons', - 'showAdminIcons()', - 'hideAdminIcons()'), + '$("#site_web_wrapper").attr("data-show_admin_icons", "true");', + '$("#site_web_wrapper").attr("data-show_admin_icons", "false");'), $this->_toggleAnchor($this->_('Editeur CSS'), 'css_editor', - 'showCSSEditor()', - 'hideCSSEditor()'), + 'showCSSEditor();$("#amber").show();', + 'smalltalk.AFICssEditor._close();$("#amber").hide();'), $this->_toggleAnchor($this->_('Amber IDE'), 'amber_ide', - 'showAmberIDE()', - 'hideAmberIDE()'), + 'showAmberIDE();$("#amber").show();', + '$("#amber").hide();'), $this->_toggleAnchor($this->_('ZF Debug'), 'zf_debug', - 'showZFDebug()', - 'hideZFDebug()'), + '$(".activate_zf_debug").show();', + '$(".deactivate_zf_debug").hide();'), $this->_changeProfile()]; @@ -160,28 +160,61 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper } - protected function _toggleAnchor($value, $class_sufix, $js_on, $js_off) { - $toggleFy = function($js, $img, $class_prefix) use ($value, $class_sufix) { + protected function _toggleAnchor($label, $key, $js_on, $js_off) { + $toggleFy = function($function_name, $img) use ($label, $key) { return $this->view->tagAnchor('#', - $value . + $label . $this->view->tagImg(Class_Admin_Skin::current() ->getIconUrl('actions', $img)), - ['class' => $class_prefix . $class_sufix, - 'title' => $value, - 'onclick' => $js . ';return true;']); + ['class' => $function_name, + 'title' => $label, + 'onclick' => $function_name . '();return true;']); }; $admin = Class_Users::getIdentity(); $settings = Class_User_Settings::newWith($admin); - if($settings->get($class_sufix)) - Class_ScriptLoader::getInstance()->addJQueryReady($js_on); + $activate_function = 'activate_' . $key; + $deactivate_function = 'deactivate_' . $key; - return $toggleFy($js_on, 'toggle_off', 'activate_') . $toggleFy($js_off, 'toggle_on', 'deactivate_'); + $url = Class_Url::absolute(sprintf('/admin/users/settings/key/%s/value/', $key)); + + $this->_injectJsFunction($activate_function, $deactivate_function, $js_on, $js_off, $url); + + if($settings->get($key)) + Class_ScriptLoader::getInstance() + ->addJQueryReady($activate_function . '();'); + + return $toggleFy($activate_function, 'toggle_off') . $toggleFy($deactivate_function, 'toggle_on'); } + protected function _injectJsFunction($activate_function, $deactivate_function, $js_on, $js_off, $url) { + $js_default_function = '%s = function() {%s; $(\'.%s\').hide(); $(\'.%s\').show();$.ajax(\'%s\');};'; + + $js_activate = sprintf($js_default_function, + $activate_function, + $js_on, + $activate_function, + $deactivate_function, + $url . 1); + + $js_deactivate = sprintf($js_default_function, + $deactivate_function, + $js_off, + $deactivate_function, + $activate_function, + $url . 0); + + Class_ScriptLoader::getInstance() + ->addInlineScript($js_activate . $js_deactivate); + + return $this; + } + + + protected function _adminLinks() { $links = [$this->view->tagAnchor(Class_Url::absolute('/admin'), $this->_('Accès professionnel') . diff --git a/library/ZendAfi/View/Helper/Portail.php b/library/ZendAfi/View/Helper/Portail.php index 84db737f910..848beedd3b1 100644 --- a/library/ZendAfi/View/Helper/Portail.php +++ b/library/ZendAfi/View/Helper/Portail.php @@ -16,13 +16,13 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { public function portail($cfg_accueil,$division_demandee = false) { $this->loadAdminUI(); - + $ret = ['', '', '', @@ -34,7 +34,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { foreach ($cfg_accueil["modules"] as $id_module => $module) { if ($id_module === null) continue; - + $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($id_module, $module, $this->view); if (!$helper) continue; @@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { return $ret; } - + public function loadAdminUI() { $request = Zend_Controller_Front::getInstance()->getRequest(); if (($user = Class_Users::getLoader()->getIdentity()) @@ -60,16 +60,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { && 'opac' == $request->getModuleName()) { Class_ScriptLoader::getInstance() ->addAdminScript('cfg.accueil') - ->addJQueryReady('window.activateOpacBlocksSorting = function() { - opacBlocksSorting("'. - $this->view->url(['module' => 'admin', - 'controller' => 'profil', - 'action' => 'module-sort'], - null, true) .'","'. - Class_Profil::getCurrentProfil()->getId() .'");}'); - + ->addInlineScript('window.activateOpacBlocksSorting = window.deactiveOpacBlocksSorting = function() {};'); } } - - } \ No newline at end of file diff --git a/public/admin/js/global.js b/public/admin/js/global.js index 1109abe39ec..64384af5a94 100644 --- a/public/admin/js/global.js +++ b/public/admin/js/global.js @@ -268,78 +268,29 @@ if (initializeNoticeMurAnimation == undefined) { } -function deactiveOpacBlocksSorting() { - $('div.layout-division>div').sortable("disable"); - $('.activate_block_sorting').show(); - $('.deactivate_block_sorting').hide(); -} - - -function reactiveOpacBlocksSorting() { - $('div.layout-division>div').sortable("enable"); - $('.deactivate_block_sorting').show(); - $('.activate_block_sorting').hide(); -} - - function showCSSEditor() { - smalltalk.AFICssEditor._open(); - $('.activate_css_editor').hide(); - $('.deactivate_css_editor').show(); - $('#amber').show(); -} - - -function hideCSSEditor() { - smalltalk.AFICssEditor._close(); - $('.activate_css_editor').show(); - $('.deactivate_css_editor').hide(); - $('#amber').hide(); + amberReadyDo(function() { + smalltalk.AFICssEditor._open(); + }); } function showAmberIDE() { - smalltalk.Browser._open(); - $('.activate_amber_ide').hide(); - $('.deactivate_amber_ide').show(); - $('#amber').show(); -} - - -function hideAmberIDE() { - $('.activate_amber_ide').show(); - $('.deactivate_amber_ide').hide(); - $('#amber').hide(); -} - - -function showZFDebug() { - $("#ZFDebug").show(); - $('.activate_zf_debug').hide(); - $('.deactivate_zf_debug').show(); -} - - -function hideZFDebug() { - $("#ZFDebug").hide(); - $('.activate_zf_debug').show(); - $('.deactivate_zf_debug').hide(); -} - - -function showAdminIcons() { - $("#site_web_wrapper").attr('data-show_admin_icons', 'true'); - $('.activate_show_admin_icons').hide(); - $('.deactivate_show_admin_icons').show(); - $.ajax( baseUrl + '/admin/users/settings/key/show_admin_icons/value/1'); + amberReadyDo(function() { + smalltalk.Browser._open(); + }); } -function hideAdminIcons() { - $("#site_web_wrapper").attr('data-show_admin_icons', 'false'); - $('.activate_show_admin_icons').show(); - $('.deactivate_show_admin_icons').hide(); - $.ajax( baseUrl + '/admin/users/settings/key/show_admin_icons/value/0'); +function amberReadyDo(callback_function) { + setTimeout(function() { + if(('undefined' == typeof smalltalk) + || ('undefined' == typeof smalltalk.AFICssEditor) + || ('undefined' == typeof smalltalk.Browser)) + return amberReadyDo(callback_function); + + return callback_function(); + }, 500); } diff --git a/public/admin/skins/bokeh74/front_nav.css b/public/admin/skins/bokeh74/front_nav.css index b823bddb027..b75e6bc92e6 100644 --- a/public/admin/skins/bokeh74/front_nav.css +++ b/public/admin/skins/bokeh74/front_nav.css @@ -71,10 +71,6 @@ display: none; } -#amber_close { - display: none; -} - .menu_admin_front fieldset { padding: 0; margin: 0; diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php index 0a8987196d7..86ffcfee980 100644 --- a/tests/application/modules/opac/controllers/IndexControllerTest.php +++ b/tests/application/modules/opac/controllers/IndexControllerTest.php @@ -720,7 +720,8 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase { 'login' => 'Joe', 'password' => 'unsupermotdepasse', 'id_site' => 1, - 'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1']), + 'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1', + 'amber_ide' => 1]), 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_BIB]); ZendAfi_Auth::getInstance()->logUser($joe); @@ -802,12 +803,18 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase { /** @test */ public function scriptToShowAdminIconsShouldBePresent() { - $this->assertXPathContentContains('//script', 'showAdminIcons()'); + $this->assertXPathContentContains('//script', 'activate_show_admin_icons()'); } /** @test */ public function scriptCssEditorShouldNotBePresent() { - $this->assertNotXPathContentContains('//script', 'showCSSEditor()'); + $this->assertNotXPathContentContains('//script', 'activate_show_css_editor()'); + } + + + /** @test */ + public function scriptToShowAmberIdeShouldBePresent() { + $this->assertXPathContentContains('//script', 'showAmberIDE()'); } } -- GitLab