// HelperList: add possibility to create custom action for each row

This commit is contained in:
dSevere
2011-10-14 14:19:45 +00:00
parent 249c817369
commit cd38def980
8 changed files with 310 additions and 114 deletions
@@ -0,0 +1,27 @@
{*
* 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 <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9197 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$href}" onclick="return confirm('{$confirm}');">
<img src="../img/admin/delete.gif" alt="{$action}" title="{$action}" /></a>
@@ -0,0 +1,27 @@
{*
* 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 <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9197 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a class="pointer" href="{$href}" onclick="if (confirm('{$confirm}')) document.location = '{$location_ok}'; else document.location = '{$location_ko}';">
<img src="../img/admin/duplicate.png" alt="{$action}" title="{$action}" /></a>
@@ -0,0 +1,27 @@
{*
* 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 <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9197 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$href}">
<img src="../img/admin/edit.gif" alt="{$action}" title="{$action}" /></a>
@@ -0,0 +1,27 @@
{*
* 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 <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9197 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$href}">
<img src="../img/admin/details.gif" alt="{$action}" title="{$action}" /></a>
+5 -12
View File
@@ -92,18 +92,11 @@
{/if} {/if}
{if $has_actions} {if $has_actions}
<td class="center" style="white-space: nowrap;"> <td class="center" style="white-space: nowrap;">
{if isset($tr.view)} {foreach $actions AS $action}
{$tr.view} {if isset($tr.$action)}
{/if} {$tr.$action}
{if isset($tr.edit)} {/if}
{$tr.edit} {/foreach}
{/if}
{if isset($tr.delete)}
{$tr.delete}
{/if}
{if isset($tr.duplicate)}
{$tr.duplicate}
{/if}
</td> </td>
{/if} {/if}
</tr> </tr>
+35 -6
View File
@@ -101,6 +101,15 @@ class AdminControllerCore extends Controller
/** @var string Order way (ASC, DESC) determined by arrows in list header */ /** @var string Order way (ASC, DESC) determined by arrows in list header */
protected $_orderWay; protected $_orderWay;
/** @var array list of available actions for each list row */
protected $actions_available = array('view', 'edit', 'delete', 'duplicate');
/** @var array list of required actions for each list row */
protected $actions = array();
/** @var array $cache_lang cache for traduction */
public static $cache_lang = array();
/** /**
* @var array actions to execute on multiple selections * @var array actions to execute on multiple selections
* Usage: * Usage:
@@ -146,7 +155,7 @@ class AdminControllerCore extends Controller
'id_cms' => 'id_cms', 'id_cms' => 'id_cms',
'id_attribute' => 'id_attribute' 'id_attribute' => 'id_attribute'
); );
protected $view; protected $view;
protected $edit; protected $edit;
protected $delete; protected $delete;
@@ -909,6 +918,14 @@ class AdminControllerCore extends Controller
)); ));
} }
/**
* Declare an action to use for each row in the list
*/
public function addRowAction($action)
{
$this->actions[] = $action;
}
/** /**
* Assign smarty variables for the page main content * Assign smarty variables for the page main content
*/ */
@@ -926,7 +943,7 @@ class AdminControllerCore extends Controller
// Check if form template has been overriden // Check if form template has been overriden
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'form.tpl')) if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'form.tpl'))
$helper->tpl = $this->tpl_folder.'form.tpl'; $helper->tpl = $this->tpl_folder.'form.tpl';
$helper::$currentIndex = self::$currentIndex; HelperForm::$currentIndex = self::$currentIndex;
$helper->token = $this->token; $helper->token = $this->token;
$helper->table = $this->table; $helper->table = $this->table;
$helper->id = $obj->id; $helper->id = $obj->id;
@@ -959,10 +976,22 @@ class AdminControllerCore extends Controller
$helper->header_tpl = $this->tpl_folder.'list_content.tpl'; $helper->header_tpl = $this->tpl_folder.'list_content.tpl';
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'list_footer.tpl')) if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'list_footer.tpl'))
$helper->header_tpl = $this->tpl_folder.'list_footer.tpl'; $helper->header_tpl = $this->tpl_folder.'list_footer.tpl';
$helper->view = $this->view;
// For compatibility reasons, we have to check standard actions in class attributes
foreach($this->actions_available as $action) {
if (!in_array($action, $this->actions) && isset($this->$action) && $this->$action)
$this->actions[] = $action;
}
//
$helper->actions = $this->actions;
/*$helper->view = $this->view;
$helper->edit = $this->edit; $helper->edit = $this->edit;
$helper->delete = $this->delete; $helper->delete = $this->delete;
$helper->duplicate = $this->duplicate; $helper->duplicate = $this->duplicate;*/
$helper->bulk_actions = $this->bulk_actions; $helper->bulk_actions = $this->bulk_actions;
HelperList::$currentIndex = self::$currentIndex; HelperList::$currentIndex = self::$currentIndex;
$helper->className = $this->className; $helper->className = $this->className;
@@ -1346,7 +1375,7 @@ class AdminControllerCore extends Controller
$this->_list = Db::getInstance()->executeS($sql); $this->_list = Db::getInstance()->executeS($sql);
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`'); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
} }
public function getlanguages() public function getlanguages()
{ {
$cookie = $this->context->cookie; $cookie = $this->context->cookie;
@@ -1460,7 +1489,7 @@ class AdminControllerCore extends Controller
else if ($className == 'Customer' && !Validate::isPasswd($value)) else if ($className == 'Customer' && !Validate::isPasswd($value))
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), 'passwd', $className).'</b> '.$this->l('is invalid'); $this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), 'passwd', $className).'</b> '.$this->l('is invalid');
} }
/* Checking for multilingual fields validity */ /* Checking for multilingual fields validity */
foreach ($rules['validateLang'] as $fieldLang => $function) foreach ($rules['validateLang'] as $fieldLang => $function)
foreach ($languages as $language) foreach ($languages as $language)
+159 -94
View File
@@ -61,6 +61,8 @@ class HelperListCore extends Helper
public $token; public $token;
public static $cache_lang = array();
protected $is_cms = false; protected $is_cms = false;
protected $is_dnd_identifier = false; protected $is_dnd_identifier = false;
@@ -82,15 +84,18 @@ class HelperListCore extends Helper
public $header_tpl = 'list_header.tpl'; public $header_tpl = 'list_header.tpl';
public $content_tpl = 'list_content.tpl'; public $content_tpl = 'list_content.tpl';
public $footer_tpl = 'list_footer.tpl'; public $footer_tpl = 'list_footer.tpl';
public $view = false; public $actions = array();
public $edit = false;
public $delete = false;
public $duplicate = false;
public $bulk_actions = false; public $bulk_actions = false;
public $specificConfirmDelete; public $specificConfirmDelete;
public $colorOnBackground; public $colorOnBackground;
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'); 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'
);
/** /**
* Return an html list given the data to fill it up * Return an html list given the data to fill it up
@@ -99,7 +104,7 @@ class HelperListCore extends Helper
* @param array $fieldsDisplay fields (cols) * @param array $fieldsDisplay fields (cols)
* @return string html * @return string html
*/ */
public function generateList($list, $fieldsDisplay) public function generateList($list, $fields_display)
{ {
/*if ($this->edit AND (!isset($this->noAdd) OR !$this->noAdd)) /*if ($this->edit AND (!isset($this->noAdd) OR !$this->noAdd))
$this->displayAddButton();*/ $this->displayAddButton();*/
@@ -112,12 +117,12 @@ class HelperListCore extends Helper
} }
$this->_list = $list; $this->_list = $list;
$this->fieldsDisplay = $fieldsDisplay; $this->fieldsDisplay = $fields_display;
/* Display list header (filtering, pagination and column names) */ /* Display list header (filtering, pagination and column names) */
$list_display = $this->displayListHeader(); $list_display = $this->displayListHeader();
if (!sizeof($this->_list)) if (!count($this->_list))
$list_display .= '<tr><td class="center" colspan="'.(sizeof($this->fieldsDisplay) + 2).'">'.$this->l('No items found').'</td></tr>'; $list_display .= '<tr><td class="center" colspan="'.(count($this->fieldsDisplay) + 2).'">'.$this->l('No items found').'</td></tr>';
/* Show the content of the table */ /* Show the content of the table */
$list_display .= $this->displayListContent(); $list_display .= $this->displayListContent();
@@ -138,21 +143,21 @@ class HelperListCore extends Helper
* @param unknown_type $id_category * @param unknown_type $id_category
* @param unknown_type $id_product * @param unknown_type $id_product
*/ */
protected function _displayEnableLink($token, $id, $value, $active, $id_category = NULL, $id_product = NULL) protected function _displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{ {
return '<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table. return '<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
((int)$id_category AND (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token!=NULL ? $token : $this->token).'"> ((int)$id_category && (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token != null ? $token : $this->token).'">
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'" <img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'"
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>'; alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>';
} }
public function displayListContent($token = NULL) public function displayListContent($token = null)
{ {
if (!$this->_list) if (!$this->_list)
return; return;
if ($this->is_dnd_identifier) if ($this->is_dnd_identifier)
$id_category = (int)(Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1')); $id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1');
else else
$id_category = 1; // default categ $id_category = 1; // default categ
@@ -166,25 +171,29 @@ class HelperListCore extends Helper
$fields = array(); $fields = array();
foreach ($this->_list AS $index => $tr) foreach ($this->_list as $index => $tr)
{ {
$id = $tr[$this->identifier]; $id = $tr[$this->identifier];
if ($this->shopLinkType) if ($this->shopLinkType)
$this->_list[$index]['short_shop_name'] = (Tools::strlen($tr['shop_name']) > 15) ? Tools::substr($tr['shop_name'], 0, 15).'...' : $tr['shop_name']; $this->_list[$index]['short_shop_name'] = Tools::strlen($tr['shop_name']) > 15 ? Tools::substr($tr['shop_name'], 0, 15).'...' : $tr['shop_name'];
$has_actions = ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) ? true : false; // Check all available actions to add to the current list row
foreach ($this->actions as $action)
if ($has_actions)
{ {
if ($this->view) $skip = '_listSkip'.ucfirst($action);
$this->_list[$index]['view'] = $this->_displayViewLink($token, $id); $method_name = 'display'.ucfirst($action).'Link';
if ($this->edit) if (!isset($this->$skip) || !in_array($id, $this->$skip))
$this->_list[$index]['edit'] = $this->_displayEditLink($token, $id); {
if ($this->delete AND (!isset($this->_listSkipDelete) || !in_array($id, $this->_listSkipDelete))) if (method_exists($this->context->controller, $method_name))
$this->_list[$index]['delete'] = $this->_displayDeleteLink($token, $id); $this->_list[$index][$action] = $this->context->controller->$method_name($token, $id);
if ($this->duplicate)
$this->_list[$index]['duplicate'] = $this->_displayDuplicate($token, $id); else if (method_exists($this, '_'.$method_name))
{
$method_name = '_'.$method_name;
$this->_list[$index][$action] = $this->$method_name($token, $id);
}
}
} }
foreach ($this->fieldsDisplay as $key => $params) foreach ($this->fieldsDisplay as $key => $params)
@@ -193,7 +202,14 @@ class HelperListCore extends Helper
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0]; $key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
if (isset($params['active'])) if (isset($params['active']))
$this->_list[$index][$key] = $this->_displayEnableLink($this->token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product')); $this->_list[$index][$key] = $this->_displayEnableLink(
$this->token,
$id,
$tr[$key],
$params['active'],
Tools::getValue('id_category'),
Tools::getValue('id_product')
);
else if (isset($params['activeVisu'])) else if (isset($params['activeVisu']))
$this->_list[$index][$key] = (bool)$tr[$key]; $this->_list[$index][$key] = (bool)$tr[$key];
else if (isset($params['position'])) else if (isset($params['position']))
@@ -201,10 +217,10 @@ class HelperListCore extends Helper
$this->_list[$index][$key] = array( $this->_list[$index][$key] = array(
'position' => $tr[$key], 'position' => $tr[$key],
'position_url_down' => self::$currentIndex. 'position_url_down' => self::$currentIndex.
'&'.$key_to_get.'='.(int)($id_category).'&'.$this->identifiersDnd[$this->identifier].'='.$id. '&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&way=1&position='.(int)($tr['position'] + 1).'&token='.$this->token, '&way=1&position='.(int)($tr['position'] + 1).'&token='.$this->token,
'position_url_up' => self::$currentIndex. 'position_url_up' => self::$currentIndex.
'&'.$key_to_get.'='.(int)($id_category).'&'.$this->identifiersDnd[$this->identifier].'='.$id. '&'.$key_to_get.'='.(int)$id_category.'&'.$this->identifiersDnd[$this->identifier].'='.$id.
'&way=0&position='.(int)($tr['position'] - 1).'&token='.$this->token '&way=0&position='.(int)($tr['position'] - 1).'&token='.$this->token
); );
} }
@@ -218,21 +234,25 @@ class HelperListCore extends Helper
$image = new Image((int)$tr['id_image']); $image = new Image((int)$tr['id_image']);
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType; $path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType;
}else }else
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)($tr['id_image']) : '').'.'.$this->imageType; $path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)$tr['id_image'] : '').'.'.$this->imageType;
$this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType); $this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType);
} }
elseif (isset($params['icon']) AND (isset($params['icon'][$tr[$key]]) OR isset($params['icon']['default']))) else if (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default'])))
$this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default']; $this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'];
elseif (isset($params['price'])) else if (isset($params['price']))
$this->_list[$index][$key] = Tools::displayPrice($tr[$key], (isset($params['currency']) ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency), false); $this->_list[$index][$key] = Tools::displayPrice($tr[$key], (isset($params['currency'])
elseif (isset($params['float'])) ?
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.'); Currency::getCurrencyInstance($tr['id_currency'])
elseif (isset($params['type']) AND $params['type'] == 'date') :
$this->context->currency), false);
else if (isset($params['float']))
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
else if (isset($params['type']) && $params['type'] == 'date')
$this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id); $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id);
elseif (isset($params['type']) AND $params['type'] == 'datetime') else if (isset($params['type']) && $params['type'] == 'datetime')
$this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true); $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true);
elseif (isset($tr[$key])) else if (isset($tr[$key]))
{ {
if ($key == 'price') if ($key == 'price')
$echo = round($tr[$key], 2); $echo = round($tr[$key], 2);
@@ -241,15 +261,21 @@ class HelperListCore extends Helper
else else
$echo = $tr[$key]; $echo = $tr[$key];
$this->_list[$index][$key] = isset($params['callback']) ? call_user_func_array(array((isset($params['callback_object'])) ? $params['callback_object'] : $this->context->controller, $params['callback']), array($echo, $tr)) : $echo; $this->_list[$index][$key] = isset($params['callback'])
?
call_user_func_array(array((isset($params['callback_object']))
?
$params['callback_object']
:
$this->context->controller, $params['callback']), array($echo, $tr))
:
$echo;
} }
} }
} }
if(isset($this->_listSkipDelete)) if (isset($this->_listSkipDelete))
{
$this->context->smarty->assign('listSkipDelete', $this->_listSkipDelete); $this->context->smarty->assign('listSkipDelete', $this->_listSkipDelete);
}
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'is_dnd_identifier' => $this->is_dnd_identifier, 'is_dnd_identifier' => $this->is_dnd_identifier,
@@ -257,58 +283,86 @@ class HelperListCore extends Helper
'id_category' => $id_category, 'id_category' => $id_category,
'bulk_actions' => $this->bulk_actions, 'bulk_actions' => $this->bulk_actions,
'key_to_get' => $key_to_get, 'key_to_get' => $key_to_get,
'positions' => isset($positions) ? $positions : NULL, 'positions' => isset($positions) ? $positions : null,
'is_cms' => $this->is_cms, 'is_cms' => $this->is_cms,
'fields_display' => $this->fieldsDisplay, 'fields_display' => $this->fieldsDisplay,
'list' => $this->_list, 'list' => $this->_list,
'actions' => $this->actions,
'no_link' => $this->noLink, 'no_link' => $this->noLink,
'current_index' => self::$currentIndex, 'current_index' => self::$currentIndex,
'view' => $this->view, 'view' => in_array('view', $this->actions),
'edit' => $this->edit, 'edit' => in_array('edit', $this->actions),
'has_actions' => $has_actions, 'has_actions' => (bool)count($this->actions),
)); ));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl'); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl');
} }
protected function _displayDuplicate($token = NULL, $id) protected function _displayDuplicateLink($token = null, $id)
{ {
$_cacheLang['Duplicate'] = $this->l('Duplicate'); if (!array_key_exists('Duplicate', self::$cache_lang))
$_cacheLang['Copy images too?'] = $this->l('Copy images too?', __CLASS__, TRUE, FALSE); self::$cache_lang['Duplicate'] = $this->l('Duplicate');
if (!array_key_exists('Copy images too?', self::$cache_lang))
self::$cache_lang['Copy images too?'] = $this->l('Copy images too?', __CLASS__, true, false);
$duplicate = self::$currentIndex.'&'.$this->identifier.'='.$id.'&duplicate'.$this->table; $duplicate = self::$currentIndex.'&'.$this->identifier.'='.$id.'&duplicate'.$this->table;
return ' $this->context->smarty->assign(array(
<a class="pointer" onclick="if (confirm(\''.$_cacheLang['Copy images too?'].'\')) document.location = \''.$duplicate.'&token='.($token!=NULL ? $token : $this->token).'\'; else document.location = \''.$duplicate.'&noimage=1&token='.($token ? $token : $this->token).'\';"> 'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token != null ? $token : $this->token),
<img src="../img/admin/duplicate.png" alt="'.$_cacheLang['Duplicate'].'" title="'.$_cacheLang['Duplicate'].'" /></a>'; 'action' => self::$cache_lang['Duplicate'],
'confirm' => self::$cache_lang['Copy images too?'],
'location_ok' => $duplicate.'&token='.($token != null ? $token : $this->token),
'location_ko' => $duplicate.'&noimage=1&token='.($token ? $token : $this->token).'\\',
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_duplicate.tpl');
} }
protected function _displayViewLink($token = NULL, $id) protected function _displayViewLink($token = null, $id)
{ {
$_cacheLang['View'] = $this->l('View'); if (!array_key_exists('View', self::$cache_lang))
self::$cache_lang['View'] = $this->l('View');
$this->context->smarty->assign(array(
'href' => self::$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/list_action_view.tpl');
return '
<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&view'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'">
<img src="../img/admin/details.gif" alt="'.$_cacheLang['View'].'" title="'.$_cacheLang['View'].'" /></a>';
} }
protected function _displayEditLink($token = NULL, $id) protected function _displayEditLink($token = null, $id)
{ {
$_cacheLang['Edit'] = $this->l('Edit'); if (!array_key_exists('Edit', self::$cache_lang))
self::$cache_lang['Edit'] = $this->l('Edit');
$this->context->smarty->assign(array(
'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
'action' => self::$cache_lang['Edit'],
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_edit.tpl');
return '
<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'">
<img src="../img/admin/edit.gif" alt="" title="'.$_cacheLang['Edit'].'" /></a>';
} }
protected function _displayDeleteLink($token = NULL, $id) protected function _displayDeleteLink($token = null, $id)
{ {
$_cacheLang['Delete'] = $this->l('Delete'); if (!array_key_exists('Delete', self::$cache_lang))
$_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE); 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(
'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
'confirm' => self::$cache_lang['DeleteItem'].$id.' ?'.(!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : ''),
'action' => self::$cache_lang['Delete'],
));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_delete.tpl');
return '
<a href="'.self::$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'" onclick="return confirm(\''.$_cacheLang['DeleteItem'].$id.' ?'.
(!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : '').'\');">
<img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a>';
} }
/** /**
@@ -318,25 +372,37 @@ class HelperListCore extends Helper
{ {
$id_cat = Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category'); $id_cat = Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category');
if (!isset($token) OR empty($token)) if (!isset($token) || empty($token))
$token = $this->token; $token = $this->token;
/* Determine total page number */ /* Determine total page number */
$total_pages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : $this->_pagination[0]))); $total_pages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($this->context->cookie->{$this->table.'_pagination'})
?
$this->context->cookie->{$this->table.'_pagination'}
:
$this->_pagination[0])));
if (!$total_pages) $total_pages = 1; if (!$total_pages) $total_pages = 1;
$action = self::$currentIndex $action = self::$currentIndex
.(Tools::getIsset($this->identifier) ? '&'.$this->identifier.'='.(int)(Tools::getValue($this->identifier)) : '') .(Tools::getIsset($this->identifier)
.'&token='.$token ? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier)
.(Tools::getIsset($this->table.'Orderby') ? '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay)) : '') : '')
.'#'.$this->table; .'&token='.$token
.(Tools::getIsset($this->table.'Orderby')
? '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay))
: '')
.'#'.$this->table;
/* Determine current page number */ /* Determine current page number */
$page = (int)(Tools::getValue('submitFilter'.$this->table)); $page = (int)Tools::getValue('submitFilter'.$this->table);
if (!$page) $page = 1; if (!$page) $page = 1;
/* Choose number of results per page */ /* Choose number of results per page */
$selected_pagination = Tools::getValue('pagination', (isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : NULL)); $selected_pagination = Tools::getValue(
'pagination',
isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : null
);
/*$is_dnd_identifier = array_key_exists($this->identifier,$this->identifiersDnd); /*$is_dnd_identifier = array_key_exists($this->identifier,$this->identifiersDnd);
@@ -355,13 +421,10 @@ class HelperListCore extends Helper
if (Tools::getValue($this->table.'Orderby') && Tools::getValue($this->table.'Orderway')) if (Tools::getValue($this->table.'Orderby') && Tools::getValue($this->table.'Orderway'))
self::$currentIndex = preg_replace('/&'.$this->table.'Orderby=([a-z _]*)&'.$this->table.'Orderway=([a-z]*)/i', '', self::$currentIndex); self::$currentIndex = preg_replace('/&'.$this->table.'Orderby=([a-z _]*)&'.$this->table.'Orderway=([a-z]*)/i', '', self::$currentIndex);
// Check if object can be modified, deleted or detailed if (array_key_exists($this->identifier, $this->identifiersDnd) && (int)Tools::getValue($this->identifiersDnd[$this->identifier], 1))
$has_actions = ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) ? true : false; $table_id = substr($this->identifier, 3, strlen($this->identifier));
if (array_key_exists($this->identifier,$this->identifiersDnd) && (int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1))) if (array_key_exists($this->identifier, $this->identifiersDnd) && ($this->_orderBy != 'position' && $this->_orderWay != 'DESC'))
$table_id = substr($this->identifier,3,strlen($this->identifier));
if (array_key_exists($this->identifier,$this->identifiersDnd) && ($this->_orderBy != 'position' && $this->_orderWay != 'DESC'))
$table_dnd = true; $table_dnd = true;
foreach ($this->fieldsDisplay as $key => $params) foreach ($this->fieldsDisplay as $key => $params)
@@ -379,14 +442,14 @@ class HelperListCore extends Helper
case 'datetime': case 'datetime':
if (is_string($value)) if (is_string($value))
$value = unserialize($value); $value = unserialize($value);
if (!Validate::isCleanHtml($value[0]) OR !Validate::isCleanHtml($value[1])) if (!Validate::isCleanHtml($value[0]) || !Validate::isCleanHtml($value[1]))
$value = ''; $value = '';
$name = $this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key); $name = $this->table.'Filter_'.(isset($params['filter_key']) ? $params['filter_key'] : $key);
$name_id = str_replace('!', '__', $name); $name_id = str_replace('!', '__', $name);
$this->context->controller->addJqueryUI('ui.datepicker'); $this->context->controller->addJqueryUI('ui.datepicker');
break; break;
case 'select': case 'select':
foreach ($params['select'] AS $option_value => $option_display) foreach ($params['select'] as $option_value => $option_display)
{ {
if (isset($_POST[$this->table.'Filter_'.$params['filter_key']]) if (isset($_POST[$this->table.'Filter_'.$params['filter_key']])
&& Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value && Tools::getValue($this->table.'Filter_'.$params['filter_key']) == $option_value
@@ -416,12 +479,12 @@ class HelperListCore extends Helper
'order_way' => $this->_orderWay, 'order_way' => $this->_orderWay,
'token' => $this->token, 'token' => $this->token,
'fields_display' => $this->fieldsDisplay, 'fields_display' => $this->fieldsDisplay,
'delete' => $this->delete, 'delete' => in_array('delete', $this->actions),
'identifier' => $this->identifier, 'identifier' => $this->identifier,
'id_cat' => $id_cat, 'id_cat' => $id_cat,
'shop_link_type' => $this->shopLinkType, 'shop_link_type' => $this->shopLinkType,
'has_actions' => $has_actions, 'has_actions' => (boolean)count($this->actions),
'add_button' => $this->edit AND (!isset($this->noAdd) OR !$this->noAdd), 'add_button' => in_array('edit', $this->actions) && (!isset($this->noAdd) || !$this->noAdd),
'table_id' => isset($table_id) ? $table_id : null, 'table_id' => isset($table_id) ? $table_id : null,
'table_dnd' => isset($table_dnd) ? $table_dnd : null, 'table_dnd' => isset($table_dnd) ? $table_dnd : null,
'name' => isset($name) ? $name : null, 'name' => isset($name) ? $name : null,
@@ -434,7 +497,7 @@ class HelperListCore extends Helper
/** /**
* Close list table and submit button * Close list table and submit button
*/ */
public function displayListFooter($token = NULL) public function displayListFooter($token = null)
{ {
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'token' => $this->token, 'token' => $this->token,
@@ -452,14 +515,14 @@ class HelperListCore extends Helper
* @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8') * @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
* @return string the translation if available, or the english default text. * @return string the translation if available, or the english default text.
*/ */
protected function l($string, $class = 'AdminTab', $addslashes = FALSE, $htmlentities = TRUE) protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
{ {
// if the class is extended by a module, use modules/[module_name]/xx.php lang file // if the class is extended by a module, use modules/[module_name]/xx.php lang file
$currentClass = get_class($this); $current_class = get_class($this);
if(Module::getModuleNameFromClass($currentClass)) if (Module::getModuleNameFromClass($current_class))
{ {
$string = str_replace('\'', '\\\'', $string); $string = str_replace('\'', '\\\'', $string);
return Module::findTranslation(Module::$classInModule[$currentClass], $string, $currentClass); return Module::findTranslation(Module::$classInModule[$current_class], $string, $current_class);
} }
global $_LANGADM; global $_LANGADM;
@@ -467,7 +530,9 @@ class HelperListCore extends Helper
$class = 'AdminTab'; $class = 'AdminTab';
$key = md5(str_replace('\'', '\\\'', $string)); $key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists(get_class($this).$key, $_LANGADM)) ? $_LANGADM[get_class($this).$key] : ((key_exists($class.$key, $_LANGADM)) ? $_LANGADM[$class.$key] : $string); $str = key_exists(get_class($this).$key, $_LANGADM)
? $_LANGADM[get_class($this).$key]
: ((key_exists($class.$key, $_LANGADM)) ? $_LANGADM[$class.$key] : $string);
$str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str; $str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str;
return str_replace('"', '&quot;', ($addslashes ? addslashes($str) : stripslashes($str))); return str_replace('"', '&quot;', ($addslashes ? addslashes($str) : stripslashes($str)));
} }
@@ -38,13 +38,14 @@ class AdminAddressesControllerCore extends AdminController
$this->table = 'address'; $this->table = 'address';
$this->className = 'Address'; $this->className = 'Address';
$this->lang = false; $this->lang = false;
$this->edit = true;
$this->delete = true;
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
$this->requiredDatabase = true; $this->requiredDatabase = true;
$this->addressType = 'customer'; $this->addressType = 'customer';
$this->context = Context::getContext(); $this->context = Context::getContext();
$this->addRowAction('edit');
$this->addRowAction('delete');
if (!Tools::getValue('realedit')) if (!Tools::getValue('realedit'))
$this->deleted = true; $this->deleted = true;
$this->_select = 'cl.`name` as country'; $this->_select = 'cl.`name` as country';