From a019c36cbe6764fd3ed0191eda30b581f5daf33d Mon Sep 17 00:00:00 2001 From: aFolletete Date: Tue, 11 Oct 2011 13:42:46 +0000 Subject: [PATCH] // change template system for AdminController --- admin-dev/themes/template/adminAddresses.tpl | 27 ------------- .../{adminHome.tpl => home/content.tpl} | 0 .../{adminTools.tpl => tools/content.tpl} | 0 .../{tracking.tpl => tracking/content.tpl} | 0 classes/AdminController.php | 40 +++++++++---------- classes/Tools.php | 11 +++++ 6 files changed, 29 insertions(+), 49 deletions(-) delete mode 100644 admin-dev/themes/template/adminAddresses.tpl rename admin-dev/themes/template/{adminHome.tpl => home/content.tpl} (100%) rename admin-dev/themes/template/{adminTools.tpl => tools/content.tpl} (100%) rename admin-dev/themes/template/{tracking.tpl => tracking/content.tpl} (100%) diff --git a/admin-dev/themes/template/adminAddresses.tpl b/admin-dev/themes/template/adminAddresses.tpl deleted file mode 100644 index 41e6d38a3..000000000 --- a/admin-dev/themes/template/adminAddresses.tpl +++ /dev/null @@ -1,27 +0,0 @@ -{* -* 2007-2011 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-3.0.php -* If you did not receive a copy of the license and are unable to -* obtain it through the world-wide-web, please send an email -* to license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision$ -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - -{$content} \ No newline at end of file diff --git a/admin-dev/themes/template/adminHome.tpl b/admin-dev/themes/template/home/content.tpl similarity index 100% rename from admin-dev/themes/template/adminHome.tpl rename to admin-dev/themes/template/home/content.tpl diff --git a/admin-dev/themes/template/adminTools.tpl b/admin-dev/themes/template/tools/content.tpl similarity index 100% rename from admin-dev/themes/template/adminTools.tpl rename to admin-dev/themes/template/tools/content.tpl diff --git a/admin-dev/themes/template/tracking.tpl b/admin-dev/themes/template/tracking/content.tpl similarity index 100% rename from admin-dev/themes/template/tracking.tpl rename to admin-dev/themes/template/tracking/content.tpl diff --git a/classes/AdminController.php b/classes/AdminController.php index f92f1010d..faa015dfa 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -38,7 +38,7 @@ class AdminControllerCore extends Controller public $meta_title = 'Administration panel'; - public $template = ''; + public $template = 'content.tpl'; /** @var string Associated table name */ public $table; @@ -173,16 +173,6 @@ class AdminControllerCore extends Controller parent::__construct(); - // if this->template is empty, - // generate the filename from the classname, without "Controller" suffix - if (empty($this->template)) - { - $tpl_name = substr(get_class($this), 0, -10).'.tpl'; - $tpl_name[0] = strtolower($tpl_name[0]); - if (file_exists($this->context->smarty->template_dir.'/'.$tpl_name)) - $this->template = $tpl_name; - } - $this->id = Tab::getIdFromClassName($controller); $this->token = Tools::getAdminToken($controller.(int)$this->id.(int)$this->context->employee->id); @@ -688,25 +678,31 @@ class AdminControllerCore extends Controller public function displayNoSmarty() { } + public function displayAjax() { echo $this->content; } + public function display() { $this->context->smarty->assign('content', $this->content); $this->context->smarty->assign('meta_title', $this->meta_title); - if (empty($this->template)) - { - $class_name = get_class($this); - $class_name = strtolower($class_name[0]).substr($class_name, 1); - $default_tpl = substr($class_name, 0, -10).'.tpl'; - if (file_exists($this->context->smarty->template_dir.'/'.$default_tpl)) - $this->template = $default_tpladdress; - else - $this->template = 'content.tpl'; - } + $class_name = get_class($this); + $class_name = strtolower($class_name[5]).substr($class_name, 6); + $class_name = Tools::toUnderscoreCase(substr($class_name, 0, -10)); + + $tpl = $class_name.'/content.tpl'; + $tpl_action = $class_name.'/'.$this->display.'.tpl'; + + // Check if action template has been override + if (file_exists($this->context->smarty->template_dir.'/'.$tpl_action)) + $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); + + // Check if content template has been override + if (file_exists($this->context->smarty->template_dir.'/'.$tpl)) + $page = $this->context->smarty->fetch($tpl); else $page = $this->context->smarty->fetch($this->template); @@ -719,7 +715,6 @@ class AdminControllerCore extends Controller $this->context->smarty->assign('errors', $this->_errors); $this->context->smarty->assign('warnings', $this->warnings); - $page = $this->context->smarty->fetch($this->template); } $this->context->smarty->assign('page', $page); @@ -922,6 +917,7 @@ class AdminControllerCore extends Controller $helper->identifier = $this->identifier; $helper->token = $this->token; $helper->_listSkipDelete = $this->_listSkipDelete; + $helper->colorOnBackground = $this->colorOnBackground; $this->content .= $helper->generateList($this->_list, $this->fieldsDisplay); } diff --git a/classes/Tools.php b/classes/Tools.php index ba58bab48..08cc8273d 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -1227,6 +1227,17 @@ class ToolsCore return preg_replace_callback('/_([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $str); } + /** + * + * Transform a CamelCase string to underscore_case string + * @param string $string + * @return string + */ + public static function toUnderscoreCase($string) + { + return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $string)); + } + public static function getBrightness($hex) { $hex = str_replace('#', '', $hex);