// bugfix admin products, adminattributesgroups, admincategories
// helper list and form improved
This commit is contained in:
+13
-17
@@ -78,7 +78,7 @@ class AdminControllerCore extends Controller
|
||||
protected $list_simple_header;
|
||||
|
||||
/** @var define if the header of the list contains filter and sorting links or not */
|
||||
protected $list_title;
|
||||
protected $toolbar_title;
|
||||
|
||||
/** @var array list to be generated */
|
||||
protected $fieldsDisplay;
|
||||
@@ -192,7 +192,8 @@ class AdminControllerCore extends Controller
|
||||
protected $action;
|
||||
protected $display;
|
||||
protected $_includeContainer = true;
|
||||
protected $tpl_folder;
|
||||
|
||||
public $tpl_folder;
|
||||
|
||||
/** @var bool Redirect or not ater a creation */
|
||||
protected $_redirect = true;
|
||||
@@ -739,7 +740,6 @@ class AdminControllerCore extends Controller
|
||||
'desc' => $this->l('Add new')
|
||||
);
|
||||
}
|
||||
$this->context->smarty->assign('toolbar_btn', $this->toolbar_btn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1151,12 +1151,6 @@ class AdminControllerCore extends Controller
|
||||
|
||||
$helper = new HelperList();
|
||||
// Check if list templates have been overriden
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_header.tpl'))
|
||||
$helper->header_tpl = $this->tpl_folder.'list_header.tpl';
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_content.tpl'))
|
||||
$helper->content_tpl = $this->tpl_folder.'list_content.tpl';
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_footer.tpl'))
|
||||
$helper->footer_tpl = $this->tpl_folder.'list_footer.tpl';
|
||||
|
||||
// For compatibility reasons, we have to check standard actions in class attributes
|
||||
foreach ($this->actions_available as $action)
|
||||
@@ -1183,10 +1177,11 @@ class AdminControllerCore extends Controller
|
||||
* @return void
|
||||
*/
|
||||
public function setHelperListDisplay(Helper $helper)
|
||||
{
|
||||
{
|
||||
// @todo : move that in Helper
|
||||
$helper->actions = $this->actions;
|
||||
$helper->simple_header = $this->list_simple_header;
|
||||
$helper->title = $this->list_title;
|
||||
$helper->title = $this->toolbar_title;
|
||||
$helper->toolbar_btn = $this->toolbar_btn;
|
||||
$helper->bulk_actions = $this->bulk_actions;
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
@@ -1223,10 +1218,10 @@ class AdminControllerCore extends Controller
|
||||
if ($this->fields_form && is_array($this->fields_form))
|
||||
{
|
||||
$this->getlanguages();
|
||||
$helper = new HelperForm();
|
||||
$helper = new HelperForm($this);
|
||||
// Check if form template has been overriden
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form.tpl'))
|
||||
$helper->tpl = $this->tpl_folder.'form.tpl';
|
||||
$helper->setTpl($this->tpl_folder.'form.tpl');
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = $this->table;
|
||||
@@ -1238,14 +1233,14 @@ class AdminControllerCore extends Controller
|
||||
$helper->fields_value = $this->getFieldsValue($this->object);
|
||||
$helper->toolbar_btn = $this->toolbar_btn;
|
||||
$helper->no_back = isset($this->no_back) ? $this->no_back : false;
|
||||
$helper->tpl_vars = $this->tpl_form_vars;
|
||||
if ($this->tabAccess['view'])
|
||||
{
|
||||
if (Tools::getValue('back'))
|
||||
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
|
||||
$this->tpl_vars['back'] = Tools::safeOutput(Tools::getValue('back'));
|
||||
else
|
||||
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token)));
|
||||
$this->tpl_vars['back'] = Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token));
|
||||
}
|
||||
|
||||
return $helper->generateForm($this->fields_form);
|
||||
}
|
||||
}
|
||||
@@ -1260,9 +1255,10 @@ class AdminControllerCore extends Controller
|
||||
$helper = new HelperOptions();
|
||||
// Check if form template has been overriden
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'options.tpl'))
|
||||
$helper->tpl = $this->tpl_folder.'options.tpl';
|
||||
$helper->setTpl($this->tpl_folder.'options.tpl');
|
||||
$helper->id = $this->id;
|
||||
$helper->token = $this->token;
|
||||
$helper->shopLinkType = $this->shopLinkType;
|
||||
$helper->table = $this->table;
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
return $helper->generateOptions($this->options);
|
||||
|
||||
+33
-3
@@ -37,11 +37,39 @@ class HelperCore
|
||||
public $identifier;
|
||||
public $token;
|
||||
public $toolbar_btn;
|
||||
public $title;
|
||||
public $show_toolbar = true;
|
||||
public $context;
|
||||
|
||||
/**
|
||||
* @var string filename, then smartyTemplate object
|
||||
*/
|
||||
protected $tpl = 'content.tpl';
|
||||
|
||||
public $tpl_vars = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
$this->tpl = $this->context->smarty->createTemplate($this->tpl);
|
||||
}
|
||||
|
||||
|
||||
public function setTpl($tpl)
|
||||
{
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl))
|
||||
$this->tpl = $this->context->smarty->createTemplate($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* default behaviour for helper is to return a tpl fetched
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$this->tpl->assign($this->tpl_vars);
|
||||
return $this->tpl->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +97,7 @@ class HelperCore
|
||||
* @param type $input_name name of input
|
||||
* @return string
|
||||
*/
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false)
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array())
|
||||
{
|
||||
if (!$use_radio)
|
||||
$input_name = $input_name.'[]';
|
||||
@@ -117,15 +145,17 @@ class HelperCore
|
||||
{
|
||||
if (is_array($cat))
|
||||
{
|
||||
$disabled = in_array($cat['id_category'], $disabled_categories);
|
||||
if ($cat['id_category'] != 1)
|
||||
$html .= '<input type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
|
||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled = in_array($cat, $disabled_categories);
|
||||
if ($cat != 1)
|
||||
$html .= '<input type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
|
||||
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
|
||||
@@ -62,22 +62,21 @@ class HelperFormCore extends Helper
|
||||
public $default_form_language = null;
|
||||
public $allow_employee_form_lang = null;
|
||||
|
||||
public $tpl = 'helper/form/form.tpl';
|
||||
protected $tpl = 'helper/form/form.tpl';
|
||||
|
||||
public function generateForm($fields_form)
|
||||
{
|
||||
$this->fields_form = $fields_form;
|
||||
|
||||
return $this->displayForm();
|
||||
return $this->generate();
|
||||
}
|
||||
|
||||
public function displayForm()
|
||||
public function generate()
|
||||
{
|
||||
if ($this->submit_action == '')
|
||||
$this->submit_action = 'submitAdd'.$this->table;
|
||||
|
||||
$iso = $this->context->language->iso_code;
|
||||
$this->context->smarty->assign(array(
|
||||
$this->tpl->assign(array(
|
||||
'submit_action' => $this->submit_action,
|
||||
'toolbar_btn' => $this->toolbar_btn,
|
||||
'firstCall' => $this->first_call,
|
||||
@@ -100,10 +99,9 @@ class HelperFormCore extends Helper
|
||||
'iso' => file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en',
|
||||
'path_css' => _THEME_CSS_DIR_,
|
||||
'ad' => dirname($_SERVER["PHP_SELF"]),
|
||||
'toolbar' => $this->toolbar
|
||||
'show_toolbar' => $this->show_toolbar
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl);
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
public function getFieldsRequired()
|
||||
|
||||
+62
-35
@@ -81,9 +81,10 @@ class HelperListCore extends Helper
|
||||
/** @var boolean Content line is clickable if true */
|
||||
public $no_link = false;
|
||||
|
||||
public $header_tpl = 'helper/list/list_header.tpl';
|
||||
public $content_tpl = 'helper/list/list_content.tpl';
|
||||
public $footer_tpl = 'helper/list/list_footer.tpl';
|
||||
protected $tpl = 'helper/list/list.tpl';
|
||||
protected $header_tpl = 'helper/list/list_header.tpl';
|
||||
protected $content_tpl = 'helper/list/list_content.tpl';
|
||||
protected $footer_tpl = 'helper/list/list_footer.tpl';
|
||||
|
||||
/** @var array list of required actions for each list row */
|
||||
public $actions = array();
|
||||
@@ -112,6 +113,27 @@ class HelperListCore extends Helper
|
||||
/** @var boolean ask for simple header : no filters, no paginations and no sorting */
|
||||
public $simple_header = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$smarty = $this->context->smarty;
|
||||
$controller = $this->context->controller;
|
||||
|
||||
// handle template overriding (smarty 3 template inheritance)
|
||||
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_header.tpl'))
|
||||
$this->header_tpl = $controller->tpl_folder.'list_header.tpl';
|
||||
|
||||
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_content.tpl'))
|
||||
$this->content_tpl = $controller->tpl_folder.'list_content.tpl';
|
||||
|
||||
if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_footer.tpl'))
|
||||
$this->footer_tpl = $controller->tpl_folder.'list_footer.tpl';
|
||||
|
||||
$this->header_tpl = $this->context->smarty->createTemplate($this->header_tpl);
|
||||
$this->content_tpl = $this->context->smarty->createTemplate($this->content_tpl);
|
||||
$this->footer_tpl = $this->context->smarty->createTemplate($this->footer_tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* Usage : Set the value to false if you want to simply display the back button
|
||||
@@ -140,17 +162,14 @@ class HelperListCore extends Helper
|
||||
$this->fieldsDisplay = $fields_display;
|
||||
|
||||
/* Display list header (filtering, pagination and column names) */
|
||||
$list_display = $this->displayListHeader();
|
||||
if (!count($this->_list))
|
||||
$list_display .= '<tr><td class="center" colspan="'.(count($this->fieldsDisplay) + 2).'">'.$this->l('No items found').'</td></tr>';
|
||||
|
||||
$tpl_vars['header'] = $this->displayListHeader();
|
||||
/* Show the content of the table */
|
||||
$list_display .= $this->displayListContent();
|
||||
|
||||
$tpl_vars['content'] = $this->displayListContent();
|
||||
/* Close list table and submit button */
|
||||
$list_display .= $this->displayListFooter();
|
||||
$tpl_vars['footer'] = $this->displayListFooter();
|
||||
|
||||
return $list_display;
|
||||
$this->tpl->assign($tpl_vars);
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,8 +195,6 @@ class HelperListCore extends Helper
|
||||
|
||||
public function displayListContent($token = null)
|
||||
{
|
||||
if (!$this->_list)
|
||||
return;
|
||||
|
||||
if ($this->is_dnd_identifier)
|
||||
$id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1');
|
||||
@@ -305,13 +322,20 @@ class HelperListCore extends Helper
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$this->content_tpl->assign(array(
|
||||
'shop_link_type' => $this->shopLinkType,
|
||||
'name' => isset($name) ? $name : null,
|
||||
'is_dnd_identifier' => $this->is_dnd_identifier,
|
||||
'identifier' => $this->identifier,
|
||||
'table' => $this->table,
|
||||
'token' => $this->token,
|
||||
'color_on_bg' => $this->colorOnBackground,
|
||||
'id_category' => $id_category,
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
'key_to_get' => $key_to_get,
|
||||
'positions' => isset($positions) ? $positions : null,
|
||||
'order_by' => $this->orderBy,
|
||||
'order_way' => $this->orderWay,
|
||||
'is_cms' => $this->is_cms,
|
||||
'fields_display' => $this->fieldsDisplay,
|
||||
'list' => $this->_list,
|
||||
@@ -324,7 +348,7 @@ class HelperListCore extends Helper
|
||||
'has_bulk_actions' => (bool)count($this->bulk_actions),
|
||||
'list_skip_actions' => $this->list_skip_actions,
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->content_tpl);
|
||||
return $this->content_tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,6 +356,7 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
protected function displayDuplicateLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_duplicate.tpl');
|
||||
if (!array_key_exists('Duplicate', self::$cache_lang))
|
||||
self::$cache_lang['Duplicate'] = $this->l('Duplicate');
|
||||
|
||||
@@ -340,7 +365,7 @@ class HelperListCore extends Helper
|
||||
|
||||
$duplicate = $this->currentIndex.'&'.$this->identifier.'='.$id.'&duplicate'.$this->table;
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Duplicate'],
|
||||
'confirm' => self::$cache_lang['Copy images too?'],
|
||||
@@ -348,7 +373,7 @@ class HelperListCore extends Helper
|
||||
'location_ko' => $duplicate.'&noimage=1&token='.($token ? $token : $this->token).'\\',
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_duplicate.tpl');
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -373,15 +398,16 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
protected function displayDetailsLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_details.tpl');
|
||||
if (!array_key_exists('Details', self::$cache_lang))
|
||||
self::$cache_lang['Details'] = $this->l('Details');
|
||||
$this->context->smarty->assign(array(
|
||||
$tpl->assign(array(
|
||||
'id' => $id,
|
||||
'controller' => str_replace('Controller', '', get_class($this->context->controller)),
|
||||
'token' => $this->token,
|
||||
'action' => self::$cache_lang['Details'],
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_details.tpl');
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,15 +415,16 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
protected function displayViewLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_view.tpl');
|
||||
if (!array_key_exists('View', self::$cache_lang))
|
||||
self::$cache_lang['View'] = $this->l('View');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['View'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_view.tpl');
|
||||
return $tpl->fetch();
|
||||
|
||||
}
|
||||
|
||||
@@ -406,21 +433,17 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
protected function displayEditLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_edit.tpl');
|
||||
if (!array_key_exists('Edit', self::$cache_lang))
|
||||
self::$cache_lang['Edit'] = $this->l('Edit');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Edit'],
|
||||
'id' => (int)$id
|
||||
));
|
||||
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_action_edit.tpl'))
|
||||
$tpl = $this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_action_edit.tpl';
|
||||
else
|
||||
$tpl = $this->context->smarty->template_dir[0].'/helper/list/list_action_edit.tpl';
|
||||
|
||||
return $this->context->smarty->fetch($tpl);
|
||||
return $tpl->fetch();
|
||||
|
||||
}
|
||||
|
||||
@@ -429,19 +452,21 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
protected function displayDeleteLink($token = null, $id)
|
||||
{
|
||||
$tpl = $this->context->smarty->createTemplate('helper/list/list_action_delete.tpl');
|
||||
if (!array_key_exists('Delete', self::$cache_lang))
|
||||
self::$cache_lang['Delete'] = $this->l('Delete');
|
||||
|
||||
if (!array_key_exists('DeleteItem', self::$cache_lang))
|
||||
self::$cache_lang['DeleteItem'] = $this->l('Delete item #', __CLASS__, true, false);
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$tpl->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'confirm' => (!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : self::$cache_lang['DeleteItem'].$id.' ? '),
|
||||
'action' => self::$cache_lang['Delete'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch('helper/list/list_action_delete.tpl');
|
||||
return $tpl->fetch();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -543,7 +568,7 @@ class HelperListCore extends Helper
|
||||
$this->fieldsDisplay[$key] = $params;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$this->header_tpl->assign(array(
|
||||
'table' => $this->table,
|
||||
'currentIndex' => $this->currentIndex,
|
||||
'action' => $action,
|
||||
@@ -570,12 +595,12 @@ class HelperListCore extends Helper
|
||||
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
|
||||
'name' => isset($name) ? $name : null,
|
||||
'name_id' => isset($name_id) ? $name_id : null,
|
||||
'toolbar' => $this->toolbar,
|
||||
'show_toolbar' => $this->show_toolbar,
|
||||
'back' => Tools::getValue('back'),
|
||||
'no_back' => $this->no_back
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->header_tpl);
|
||||
return $this->header_tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -583,12 +608,14 @@ class HelperListCore extends Helper
|
||||
*/
|
||||
public function displayListFooter($token = null)
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
$this->footer_tpl->assign(array(
|
||||
'token' => $this->token,
|
||||
'table' => $this->table,
|
||||
'simple_header' => $this->simple_header,
|
||||
'bulk_actions' => $this->bulk_actions,
|
||||
'no_back' => $this->no_back
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->footer_tpl);
|
||||
return $this->footer_tpl->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class HelperOptionsCore extends Helper
|
||||
$option_list[$category] = $category_data;
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
$this->tpl->assign(array(
|
||||
'current' => $this->currentIndex,
|
||||
'table' => $this->table,
|
||||
'token' => $this->token,
|
||||
@@ -154,7 +154,7 @@ class HelperOptionsCore extends Helper
|
||||
'required_fields' => isset($required_fields) ? $required_fields : false,
|
||||
'languages' => isset($languages) ? $languages : null,
|
||||
));
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl);
|
||||
return $this->tpl->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user