Skip to content
Snippets Groups Projects
Commit 4e20254d authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #60900 refacto js function

parent 32008a75
Branches
Tags
3 merge requests!2334Master,!2177Dev#60900 ajouter un menu admin en front pour regrouper les actions outils de l adminstrateur,!2173Dev#60900 ajouter un menu admin en front pour regrouper les actions outils de l adminstrateur
Pipeline #1608 failed with stage
in 10 minutes and 35 seconds
...@@ -102,28 +102,28 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper ...@@ -102,28 +102,28 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper
$this->_toggleAnchor($this->_('Déplacement des boites'), $this->_toggleAnchor($this->_('Déplacement des boites'),
'block_sorting', 'block_sorting',
'reactiveOpacBlocksSorting()', sprintf('opacBlocksSorting(\'%s\',%d); $("div.layout-division>div").sortable("enable");', Class_Url::absolute('/admin/profil/module-sort'), Class_Profil::getCurrentProfil()->getId()),
'deactiveOpacBlocksSorting()'), '$("div.layout-division>div").sortable("disable");'),
$this->_toggleAnchor($this->_('Afficher les icones d\'administration'), $this->_toggleAnchor($this->_('Afficher les icones d\'administration'),
'show_admin_icons', 'show_admin_icons',
'showAdminIcons()', '$("#site_web_wrapper").attr("data-show_admin_icons", "true");',
'hideAdminIcons()'), '$("#site_web_wrapper").attr("data-show_admin_icons", "false");'),
$this->_toggleAnchor($this->_('Editeur CSS'), $this->_toggleAnchor($this->_('Editeur CSS'),
'css_editor', 'css_editor',
'showCSSEditor()', 'showCSSEditor();$("#amber").show();',
'hideCSSEditor()'), 'smalltalk.AFICssEditor._close();$("#amber").hide();'),
$this->_toggleAnchor($this->_('Amber IDE'), $this->_toggleAnchor($this->_('Amber IDE'),
'amber_ide', 'amber_ide',
'showAmberIDE()', 'showAmberIDE();$("#amber").show();',
'hideAmberIDE()'), '$("#amber").hide();'),
$this->_toggleAnchor($this->_('ZF Debug'), $this->_toggleAnchor($this->_('ZF Debug'),
'zf_debug', 'zf_debug',
'showZFDebug()', '$(".activate_zf_debug").show();',
'hideZFDebug()'), '$(".deactivate_zf_debug").hide();'),
$this->_changeProfile()]; $this->_changeProfile()];
...@@ -160,28 +160,61 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper ...@@ -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) { protected function _toggleAnchor($label, $key, $js_on, $js_off) {
$toggleFy = function($js, $img, $class_prefix) use ($value, $class_sufix) { $toggleFy = function($function_name, $img) use ($label, $key) {
return $this->view->tagAnchor('#', return $this->view->tagAnchor('#',
$value . $label .
$this->view->tagImg(Class_Admin_Skin::current() $this->view->tagImg(Class_Admin_Skin::current()
->getIconUrl('actions', ->getIconUrl('actions',
$img)), $img)),
['class' => $class_prefix . $class_sufix, ['class' => $function_name,
'title' => $value, 'title' => $label,
'onclick' => $js . ';return true;']); 'onclick' => $function_name . '();return true;']);
}; };
$admin = Class_Users::getIdentity(); $admin = Class_Users::getIdentity();
$settings = Class_User_Settings::newWith($admin); $settings = Class_User_Settings::newWith($admin);
if($settings->get($class_sufix)) $activate_function = 'activate_' . $key;
Class_ScriptLoader::getInstance()->addJQueryReady($js_on); $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() { protected function _adminLinks() {
$links = [$this->view->tagAnchor(Class_Url::absolute('/admin'), $links = [$this->view->tagAnchor(Class_Url::absolute('/admin'),
$this->_('Accès professionnel') . $this->_('Accès professionnel') .
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software * 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 { class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper {
public function portail($cfg_accueil,$division_demandee = false) { public function portail($cfg_accueil,$division_demandee = false) {
$this->loadAdminUI(); $this->loadAdminUI();
$ret = ['', $ret = ['',
'', '',
'', '',
...@@ -34,7 +34,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { ...@@ -34,7 +34,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper {
foreach ($cfg_accueil["modules"] as $id_module => $module) { foreach ($cfg_accueil["modules"] as $id_module => $module) {
if ($id_module === null) continue; if ($id_module === null) continue;
$helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($id_module, $module, $this->view); $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($id_module, $module, $this->view);
if (!$helper) continue; if (!$helper) continue;
...@@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { ...@@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper {
return $ret; return $ret;
} }
public function loadAdminUI() { public function loadAdminUI() {
$request = Zend_Controller_Front::getInstance()->getRequest(); $request = Zend_Controller_Front::getInstance()->getRequest();
if (($user = Class_Users::getLoader()->getIdentity()) if (($user = Class_Users::getLoader()->getIdentity())
...@@ -60,16 +60,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper { ...@@ -60,16 +60,7 @@ class ZendAfi_View_Helper_Portail extends ZendAfi_View_Helper_BaseHelper {
&& 'opac' == $request->getModuleName()) { && 'opac' == $request->getModuleName()) {
Class_ScriptLoader::getInstance() Class_ScriptLoader::getInstance()
->addAdminScript('cfg.accueil') ->addAdminScript('cfg.accueil')
->addJQueryReady('window.activateOpacBlocksSorting = function() { ->addInlineScript('window.activateOpacBlocksSorting = window.deactiveOpacBlocksSorting = function() {};');
opacBlocksSorting("'.
$this->view->url(['module' => 'admin',
'controller' => 'profil',
'action' => 'module-sort'],
null, true) .'","'.
Class_Profil::getCurrentProfil()->getId() .'");}');
} }
} }
} }
\ No newline at end of file
...@@ -268,78 +268,29 @@ if (initializeNoticeMurAnimation == undefined) { ...@@ -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() { function showCSSEditor() {
smalltalk.AFICssEditor._open(); amberReadyDo(function() {
$('.activate_css_editor').hide(); smalltalk.AFICssEditor._open();
$('.deactivate_css_editor').show(); });
$('#amber').show();
}
function hideCSSEditor() {
smalltalk.AFICssEditor._close();
$('.activate_css_editor').show();
$('.deactivate_css_editor').hide();
$('#amber').hide();
} }
function showAmberIDE() { function showAmberIDE() {
smalltalk.Browser._open(); amberReadyDo(function() {
$('.activate_amber_ide').hide(); smalltalk.Browser._open();
$('.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');
} }
function hideAdminIcons() { function amberReadyDo(callback_function) {
$("#site_web_wrapper").attr('data-show_admin_icons', 'false'); setTimeout(function() {
$('.activate_show_admin_icons').show(); if(('undefined' == typeof smalltalk)
$('.deactivate_show_admin_icons').hide(); || ('undefined' == typeof smalltalk.AFICssEditor)
$.ajax( baseUrl + '/admin/users/settings/key/show_admin_icons/value/0'); || ('undefined' == typeof smalltalk.Browser))
return amberReadyDo(callback_function);
return callback_function();
}, 500);
} }
......
...@@ -71,10 +71,6 @@ ...@@ -71,10 +71,6 @@
display: none; display: none;
} }
#amber_close {
display: none;
}
.menu_admin_front fieldset { .menu_admin_front fieldset {
padding: 0; padding: 0;
margin: 0; margin: 0;
......
...@@ -720,7 +720,8 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase { ...@@ -720,7 +720,8 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase {
'login' => 'Joe', 'login' => 'Joe',
'password' => 'unsupermotdepasse', 'password' => 'unsupermotdepasse',
'id_site' => 1, '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]); 'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_BIB]);
ZendAfi_Auth::getInstance()->logUser($joe); ZendAfi_Auth::getInstance()->logUser($joe);
...@@ -802,12 +803,18 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase { ...@@ -802,12 +803,18 @@ class IndexControllerWithBibAdminLoggedTest extends AbstractControllerTestCase {
/** @test */ /** @test */
public function scriptToShowAdminIconsShouldBePresent() { public function scriptToShowAdminIconsShouldBePresent() {
$this->assertXPathContentContains('//script', 'showAdminIcons()'); $this->assertXPathContentContains('//script', 'activate_show_admin_icons()');
} }
/** @test */ /** @test */
public function scriptCssEditorShouldNotBePresent() { public function scriptCssEditorShouldNotBePresent() {
$this->assertNotXPathContentContains('//script', 'showCSSEditor()'); $this->assertNotXPathContentContains('//script', 'activate_show_css_editor()');
}
/** @test */
public function scriptToShowAmberIdeShouldBePresent() {
$this->assertXPathContentContains('//script', 'showAmberIDE()');
} }
} }
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