Using now templates instead of hard code in AdminUtilities smarty plugin

This commit is contained in:
Franck Allimant
2013-10-31 12:16:14 +01:00
parent a295fee0d3
commit 3b9f94cec8
7 changed files with 62 additions and 20 deletions

View File

@@ -199,7 +199,7 @@ class BaseAdminController extends BaseController
$parser = $this->container->get("thelia.parser"); $parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used // 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; return $parser;
} }

View File

@@ -27,6 +27,8 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\Security\SecurityContext; use Thelia\Core\Security\SecurityContext;
use Thelia\Model\Config;
use Thelia\Model\ConfigQuery;
/** /**
* This class implements variour admin template utilities * This class implements variour admin template utilities
@@ -42,6 +44,26 @@ class AdminUtilities extends AbstractSmartyPlugin
$this->securityContext = $securityContext; $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) public function generatePositionChangeBlock($params, &$smarty)
{ {
// The required permissions // The required permissions
@@ -70,15 +92,15 @@ class AdminUtilities extends AbstractSmartyPlugin
*/ */
if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($resource), array($access))) { if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($resource), array($access))) {
return sprintf(
'<a href="%s"><i class="glyphicon glyphicon-arrow-up"></i></a><span class="%s" data-id="%s">%s</span><a href="%s"><i class="glyphicon glyphicon-arrow-down"></i></a>', return $this->fetch_snippet($smarty, 'includes/admin-utilities-position-block', array(
URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)), 'admin_utilities_go_up_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'up', $url_parameter => $id)),
$in_place_edit_class, 'admin_utilities_in_place_edit_class' => $in_place_edit_class,
$id, 'admin_utilities_object_id' => $id,
$position, 'admin_utilities_current_position' => $position,
URL::getInstance()->absoluteUrl($path, array('mode' => 'down', $url_parameter => $id)) 'admin_utilities_go_down_url' => URL::getInstance()->absoluteUrl($path, array('mode' => 'down', $url_parameter => $id))
); ));
} else { } else {
return $position; return $position;
} }
} }
@@ -111,21 +133,20 @@ class AdminUtilities extends AbstractSmartyPlugin
$request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order'); $request_parameter_name = $this->getParam($params, 'request_parameter_name', 'order');
if ($current_order == $order) { if ($current_order == $order) {
$icon = 'up'; $sort_direction = 'up';
$order_change = $reverse_order; $order_change = $reverse_order;
} elseif ($current_order == $reverse_order) { } elseif ($current_order == $reverse_order) {
$icon = 'down'; $sort_direction = 'down';
$order_change = $order; $order_change = $order;
} else { } else {
$order_change = $order; $order_change = $order;
} }
if (! empty($icon)) return $this->fetch_snippet($smarty, 'includes/admin-utilities-sortable-column-header', array(
$output = sprintf('<i class="glyphicon glyphicon-chevron-%s"></i> ', $icon); 'admin_utilities_sort_direction' => $sort_direction,
else 'admin_utilities_sorting_url' => URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)),
$output = ''; 'admin_utilities_header_text' => $label
));
return sprintf('%s<a href="%s">%s</a>', $output, URL::getInstance()->absoluteUrl($path, array($request_parameter_name => $order_change)), $label);
} }
/** /**

View File

@@ -8,6 +8,7 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
('session_config.default', '1', 1, 1, NOW(), NOW()), ('session_config.default', '1', 1, 1, NOW(), NOW()),
('verifyStock', '1', 0, 0, NOW(), NOW()), ('verifyStock', '1', 0, 0, NOW(), NOW()),
('active-template', 'default', 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()), ('default_lang_without_translation', '1', 1, 1, NOW(), NOW()),
('rewriting_enable', '0', 0, 0, NOW(), NOW()), ('rewriting_enable', '0', 0, 0, NOW(), NOW()),
('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()), ('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()),

View File

@@ -1,2 +1,4 @@
{* Include debug bar smarty calls *}
{debugbar_renderjs} {debugbar_renderjs}
{debugbar_renderresult} {debugbar_renderresult}

View File

@@ -0,0 +1,7 @@
{*
This snippet is used by the AdminUtilities Smarty plugin to generate
the position maagement block in tables
*}
<a href="{$admin_utilities_go_up_url}"><i class="glyphicon glyphicon-arrow-up"></i></a>
<span class="{$admin_utilities_in_place_edit_class}" data-id="{$admin_utilities_object_id}">{$admin_utilities_current_position}</span>
<a href="{$admin_utilities_go_down_url}"><i class="glyphicon glyphicon-arrow-down"></i></a>

View File

@@ -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'}
<i class="glyphicon glyphicon-chevron-up"></i>
{else if $admin_utilities_sort_direction == 'down'}
<i class="glyphicon glyphicon-chevron-down"></i>
{/if}
<a href="{$admin_utilities_sorting_url}">{$admin_utilities_header_text}</a>

View File

@@ -9,7 +9,7 @@
<div class="modules"> <div class="modules">
<div id="wrapper" class="container"> <div id="wrapper" class="container">
<div class="clearfix"> <div class="clearfix">
<ul class="breadcrumb pull-left"> <ul class="breadcrumb pull-left">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li> <li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
@@ -19,7 +19,8 @@
<a class="btn btn-default btn-primary pull-right" title="{intl l='Install a new module'}" href="#install_dialog" data-toggle="modal"> <a class="btn btn-default btn-primary pull-right" title="{intl l='Install a new module'}" href="#install_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-import"></span> {intl l="Install a new module"} <span class="glyphicon glyphicon-import"></span> {intl l="Install a new module"}
</a> </a>
{/loop}*} {/loop}
*}
</div> </div>
{module_include location='modules_top'} {module_include location='modules_top'}