From 3b9f94cec843a2e4a3373977a175126fbda71996 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 31 Oct 2013 12:16:14 +0100 Subject: [PATCH] Using now templates instead of hard code in AdminUtilities smarty plugin --- .../Controller/Admin/BaseAdminController.php | 2 +- .../Smarty/Plugins/AdminUtilities.php | 55 +++++++++++++------ install/insert.sql | 1 + .../AdminIncludes/footer_js.html | 2 + .../admin-utilities-position-block.html | 7 +++ ...dmin-utilities-sortable-column-header.html | 10 ++++ templates/admin/default/modules.html | 5 +- 7 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 templates/admin/default/includes/admin-utilities-position-block.html create mode 100644 templates/admin/default/includes/admin-utilities-sortable-column-header.html diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index ad8d46ba0..5fc11c814 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -199,7 +199,7 @@ class BaseAdminController extends BaseController $parser = $this->container->get("thelia.parser"); // Define the template thant shoud be used - $parser->setTemplate($template ?: ConfigQuery::read('base_admin_template', 'admin/default')); + $parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default')); return $parser; } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 244d09166..3b432cea9 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -27,6 +27,8 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Tools\URL; use Thelia\Core\Security\SecurityContext; +use Thelia\Model\Config; +use Thelia\Model\ConfigQuery; /** * This class implements variour admin template utilities @@ -42,6 +44,26 @@ class AdminUtilities extends AbstractSmartyPlugin $this->securityContext = $securityContext; } + protected function fetch_snippet($smarty, $templateName, $variablesArray) { + + $data = ''; + + $snippet_path = sprintf('%s/%s/%s.html', + THELIA_TEMPLATE_DIR, + ConfigQuery::read('base-admin-template', 'admin/default'), + $templateName + ); + + if (false !== $snippet_content = file_get_contents($snippet_path)) { + + $smarty->assign($variablesArray); + + $data = $smarty->fetch(sprintf('string:%s', $snippet_content)); + } + + return $data; + } + public function generatePositionChangeBlock($params, &$smarty) { // The required permissions @@ -70,15 +92,15 @@ class AdminUtilities extends AbstractSmartyPlugin */ if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($resource), array($access))) { - return sprintf( - '%s', - URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)), - $in_place_edit_class, - $id, - $position, - URL::getInstance()->absoluteUrl($path, array('mode' => 'down', $url_parameter => $id)) - ); - } else { + + return $this->fetch_snippet($smarty, 'includes/admin-utilities-position-block', array( + 'admin_utilities_go_up_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)), + 'admin_utilities_in_place_edit_class' => $in_place_edit_class, + 'admin_utilities_object_id' => $id, + 'admin_utilities_current_position' => $position, + 'admin_utilities_go_down_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'down', $url_parameter => $id)) + )); + } else { return $position; } } @@ -111,21 +133,20 @@ class AdminUtilities extends AbstractSmartyPlugin $request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order'); if ($current_order == $order) { - $icon = 'up'; + $sort_direction = 'up'; $order_change = $reverse_order; } elseif ($current_order == $reverse_order) { - $icon = 'down'; + $sort_direction = 'down'; $order_change = $order; } else { $order_change = $order; } - if (! empty($icon)) - $output = sprintf(' ', $icon); - else - $output = ''; - - return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), $label); + return $this->fetch_snippet($smarty, 'includes/admin-utilities-sortable-column-header', array( + 'admin_utilities_sort_direction' => $sort_direction, + 'admin_utilities_sorting_url' => URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), + 'admin_utilities_header_text' => $label + )); } /** diff --git a/install/insert.sql b/install/insert.sql index 71dc0c745..7ceb6ce34 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -8,6 +8,7 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('session_config.default', '1', 1, 1, NOW(), NOW()), ('verifyStock', '1', 0, 0, NOW(), NOW()), ('active-template', 'default', 0, 0, NOW(), NOW()), +('base-admin-template', 'admin/default', 0, 0, NOW(), NOW()), ('default_lang_without_translation', '1', 1, 1, NOW(), NOW()), ('rewriting_enable', '0', 0, 0, NOW(), NOW()), ('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()), diff --git a/local/modules/TheliaDebugBar/AdminIncludes/footer_js.html b/local/modules/TheliaDebugBar/AdminIncludes/footer_js.html index 52b154116..6f897e091 100644 --- a/local/modules/TheliaDebugBar/AdminIncludes/footer_js.html +++ b/local/modules/TheliaDebugBar/AdminIncludes/footer_js.html @@ -1,2 +1,4 @@ +{* Include debug bar smarty calls *} + {debugbar_renderjs} {debugbar_renderresult} diff --git a/templates/admin/default/includes/admin-utilities-position-block.html b/templates/admin/default/includes/admin-utilities-position-block.html new file mode 100644 index 000000000..c1277f212 --- /dev/null +++ b/templates/admin/default/includes/admin-utilities-position-block.html @@ -0,0 +1,7 @@ +{* +This snippet is used by the AdminUtilities Smarty plugin to generate +the position maagement block in tables +*} + +{$admin_utilities_current_position} + \ No newline at end of file diff --git a/templates/admin/default/includes/admin-utilities-sortable-column-header.html b/templates/admin/default/includes/admin-utilities-sortable-column-header.html new file mode 100644 index 000000000..0dce13492 --- /dev/null +++ b/templates/admin/default/includes/admin-utilities-sortable-column-header.html @@ -0,0 +1,10 @@ +{* +This snippet is used by the AdminUtilities Smarty plugin to generate +the header on a sortable column +*} +{if $admin_utilities_sort_direction == 'up'} + +{else if $admin_utilities_sort_direction == 'down'} + +{/if} +{$admin_utilities_header_text} \ No newline at end of file diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index ca94be812..d82bce399 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -9,7 +9,7 @@
- +
{module_include location='modules_top'}