[*] BO : #PSFV-481 - Refactor HelperList position management

This commit is contained in:
tDidierjean
2012-03-13 16:22:23 +00:00
parent ed21db27b6
commit b2e056ec8b
13 changed files with 39 additions and 47 deletions
@@ -27,7 +27,7 @@
{if count($list)}
{foreach $list AS $index => $tr}
<tr
{if $is_dnd_identifier}id="tr_{$tr.id_attribute_group}_{$tr.$identifier}_{if isset($tr.position['position'])}{$tr.position['position']}{else}0{/if}"{/if}
{if $position_identifier}id="tr_{$tr.id_attribute_group}_{$tr.$identifier}_{if isset($tr.position['position'])}{$tr.position['position']}{else}0{/if}"{/if}
{if $index is odd}class="alt_row"{/if}
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
>
@@ -26,7 +26,7 @@
<tbody>
{foreach $list AS $index => $tr}
<tr
{if $is_dnd_identifier}id="tr_{$id_category}_{$tr.$identifier}_{$tr.position['position']}"{/if}
{if $position_identifier}id="tr_{$id_category}_{$tr.$identifier}_{$tr.position['position']}"{/if}
{if $index is odd}class="alt_row"{/if}
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
>
@@ -27,7 +27,7 @@
{if count($list)}
{foreach $list AS $index => $tr}
<tr
{if $is_dnd_identifier}id="tr_{$id_category}_{$tr.$identifier}_{if isset($tr.position['position'])}{$tr.position['position']}{else}0{/if}"{/if}
{if $position_identifier}id="tr_{$id_category}_{$tr.$identifier}_{if isset($tr.position['position'])}{$tr.position['position']}{else}0{/if}"{/if}
class="{if $index is odd}alt_row{/if} {if $row_hover}row_hover{/if}"
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
>
@@ -44,15 +44,14 @@
</td>
{foreach $fields_display AS $key => $params}
{block name="open_td"}
<td
{if isset($params.position)}
<td
{if isset($params.position)}
id="td_{if !empty($id_category)}{$id_category}{else}0{/if}_{$tr.$identifier}"
{/if}
class="{if !$no_link}pointer{/if}
{if isset($params.position) && $order_by == 'position'} dragHandle{/if}
{if isset($params.align)} {$params.align}{/if}"
{if (!isset($params.position) && !$no_link && !isset($params.remove_onclick))}
{/if}
class="{if !$no_link}pointer{/if}
{if isset($params.position) && $order_by == 'position'} dragHandle{/if}
{if isset($params.align)} {$params.align}{/if}"
{if (!isset($params.position) && !$no_link && !isset($params.remove_onclick))}
onclick="document.location = '{$current_index}&{$identifier}={$tr.$identifier}{if $view}&view{else}&update{/if}{$table}&token={$token}'">
{else}
>
+3 -9
View File
@@ -202,15 +202,8 @@ class AdminControllerCore extends Controller
protected $is_cms = false;
protected $is_dnd_identifier = false;
protected $identifiersDnd = array(
'id_product' => 'id_product',
'id_category' => 'id_category_to_move',
'id_cms_category' => 'id_cms_category_to_move',
'id_cms' => 'id_cms',
'id_attribute' => 'id_attribute'
);
/** @var string identifier to use for changing positions in lists (can be omitted if positions cannot be changed) */
protected $position_identifier;
/** @var boolean Table records are not deleted but marked as deleted if set to true */
protected $deleted = false;
@@ -1542,6 +1535,7 @@ class AdminControllerCore extends Controller
$helper->allow_employee_form_lang = $this->allow_employee_form_lang;
$helper->multiple_fieldsets = $this->multiple_fieldsets;
$helper->row_hover = $this->row_hover;
$helper->position_identifier = $this->position_identifier;
// For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions;
+9 -26
View File
@@ -66,7 +66,7 @@ class HelperListCore extends Helper
protected $is_cms = false;
protected $is_dnd_identifier = false;
public $position_identifier;
/**
* @var string Customize list display
@@ -100,18 +100,6 @@ class HelperListCore extends Helper
/** @var bool If true, activates color on hover */
public $row_hover = true;
protected $identifiersDnd = array(
'id_product' => 'id_product',
'id_category' => 'id_category_to_move',
'id_cms_category' => 'id_cms_category_to_move',
'id_cms' => 'id_cms',
'id_attribute' => 'id_attribute',
'id_attribute_group' => 'id_attribute_group',
'id_carrier' => 'id_carrier',
'id_tab' => 'id_tab',
'id_feature' => 'id_feature'
);
/** @var if not null, a title will be added on that list */
public $title = null;
@@ -137,9 +125,6 @@ class HelperListCore extends Helper
*/
public function generateList($list, $fields_display)
{
/*if ($this->edit && (!isset($this->noAdd) || !$this->noAdd))
$this->displayAddButton();*/
// Append when we get a syntax error in SQL query
if ($list === false)
{
@@ -192,10 +177,10 @@ class HelperListCore extends Helper
public function displayListContent()
{
if ($this->is_dnd_identifier)
if ($this->position_identifier)
$id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1');
else
$id_category = Category::getRootCategory();
$id_category = Category::getRootCategory()->id;
if (isset($this->fieldsDisplay['position']))
{
@@ -258,10 +243,10 @@ class HelperListCore extends Helper
$this->_list[$index][$key] = array(
'position' => $tr[$key],
'position_url_down' => $this->currentIndex.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->position_identifier.'='.$id.
'&way=1&position='.((int)$tr['position'] + 1).'&token='.$this->token,
'position_url_up' => $this->currentIndex.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&'.$key_to_get.'='.(int)$id_category.'&'.$this->position_identifier.'='.$id.
'&way=0&position='.((int)$tr['position'] - 1).'&token='.$this->token
);
}
@@ -321,7 +306,7 @@ class HelperListCore extends Helper
$this->content_tpl->assign(array_merge($this->tpl_vars, array(
'shop_link_type' => $this->shopLinkType,
'name' => isset($name) ? $name : null,
'is_dnd_identifier' => $this->is_dnd_identifier,
'position_identifier' => $this->position_identifier,
'identifier' => $this->identifier,
'table' => $this->table,
'token' => $this->token,
@@ -539,16 +524,14 @@ class HelperListCore extends Helper
isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : null
);
$this->is_dnd_identifier = array_key_exists($this->identifier, $this->identifiersDnd);
// Cleaning links
if (Tools::getValue($this->table.'Orderby') && Tools::getValue($this->table.'Orderway'))
$this->currentIndex = preg_replace('/&'.$this->table.'Orderby=([a-z _]*)&'.$this->table.'Orderway=([a-z]*)/i', '', $this->currentIndex);
if (array_key_exists($this->identifier, $this->identifiersDnd) && (int)Tools::getValue($this->identifiersDnd[$this->identifier], 1))
if ($this->position_identifier && (int)Tools::getValue($this->position_identifier, 1))
$table_id = substr($this->identifier, 3, strlen($this->identifier));
if (array_key_exists($this->identifier, $this->identifiersDnd) && ($this->orderBy == 'position' && $this->orderWay != 'DESC'))
if ($this->position_identifier && ($this->orderBy == 'position' && $this->orderWay != 'DESC'))
$table_dnd = true;
foreach ($this->fieldsDisplay as $key => $params)
@@ -610,7 +593,7 @@ class HelperListCore extends Helper
'selected_pagination' => $selected_pagination,
'pagination' => $this->_pagination,
'list_total' => $this->listTotal,
'is_order_position' => array_key_exists($this->identifier, $this->identifiersDnd) && $this->orderBy == 'position',
'is_order_position' => $this->position_identifier && $this->orderBy == 'position',
'order_way' => $this->orderWay,
'order_by' => $this->orderBy,
'token' => $this->token,
@@ -28,6 +28,7 @@
class AdminAttributesGroupsControllerCore extends AdminController
{
protected $id_attribute;
protected $position_identifier = 'id_attribute_group';
public function __construct()
{
@@ -157,6 +158,7 @@ class AdminAttributesGroupsControllerCore extends AdminController
$helper->simple_header = true;
$helper->show_toolbar = false;
$helper->bulk_actions = $this->bulk_actions;
$helper->position_identifier = 'id_attribute';
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
die (Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)));
@@ -27,6 +27,8 @@
class AdminCarriersControllerCore extends AdminController
{
protected $position_identifier = 'id_carrier';
public function __construct()
{
$this->table = 'carrier';
@@ -31,6 +31,7 @@ class AdminCategoriesControllerCore extends AdminController
* @var object Category() instance for navigation
*/
private $_category = null;
protected $position_identifier = 'id_category_to_move';
public function __construct()
{
@@ -28,7 +28,9 @@
class AdminCmsCategoriesControllerCore extends AdminController
{
/** @var object CMSCategory() instance for navigation*/
private $_CMSCategory;
protected $_CMSCategory;
protected $position_identifier = 'id_cms_category_to_move';
public function __construct()
{
+2
View File
@@ -31,6 +31,8 @@ class AdminCmsControllerCore extends AdminController
public $id_cms_category;
protected $position_identifier = 'id_cms';
public function __construct()
{
$this->table = 'cms';
@@ -26,6 +26,8 @@
*/
class AdminFeaturesControllerCore extends AdminController
{
protected $position_identifier = 'id_feature';
public function __construct()
{
$this->table = 'feature';
@@ -68,6 +68,8 @@ class AdminProductsControllerCore extends AdminController
protected $available_tabs_lang = array();
protected $position_identifier = 'id_product';
public function __construct()
{
$this->table = 'product';
@@ -27,6 +27,8 @@
class AdminTabsControllerCore extends AdminController
{
protected $position_identifier = 'id_tab';
public function __construct()
{
$this->context = Context::getContext();
@@ -226,6 +228,7 @@ class AdminTabsControllerCore extends AdminController
$helper->currentIndex = self::$currentIndex;
$helper->token = $this->token;
$helper->table = $this->table;
$helper->position_identifier = $this->position_identifier;
// Force render - no filter, form, js, sorting ...
$helper->simple_header = true;
$content = $helper->generateList($this->_list, $this->fieldsDisplay);