// Update list generation

This commit is contained in:
tDidierjean
2011-09-30 10:00:20 +00:00
parent e30a6c379b
commit 6f2d02442d
5 changed files with 94 additions and 53 deletions
+8 -10
View File
@@ -28,8 +28,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('.filter').keypress(function(event){ $('.filter').keypress(function(event){
//alert('submitFilterButton_{$table}'); formSubmit(event, 'submitFilterButton{$table}')
//formSubmit(event, 'submitFilterButton{$table}')
}) })
}); });
</script> </script>
@@ -44,7 +43,9 @@
<script type="text/javascript" src="../js/admin-dnd.js"></script> <script type="text/javascript" src="../js/admin-dnd.js"></script>
{/if} {/if}
{if $add_button}
<br /><a href="{$currentIndex}&add{$table}&token={$token}"><img src="../img/admin/add.gif" border="0" />{l s='Add new'}</a><br /><br />
{/if}
<a name="{$table}">&nbsp;</a> <a name="{$table}">&nbsp;</a>
<form method="post" action="{$action}" class="form"> <form method="post" action="{$action}" class="form">
<input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/> <input type="hidden" id="submitFilter{$table}" name="submitFilter{$table}" value="0"/>
@@ -80,9 +81,8 @@
<tr> <tr>
<td> <td>
<table <table
{*(array_key_exists($this->identifier,$this->identifiersDnd) ? ' id="'.(((int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1))) ? substr($this->identifier,3,strlen($this->identifier)) : '').'"' : '' )*} {if $table_id} id={$table_id}{/if}
class="table" class="table {if $table_dnd}tableDnd{/if}"
{*(array_key_exists($this->identifier,$this->identifiersDnd) AND ($this->_orderBy != 'position 'AND $this->_orderWay != 'DESC')) ? ' tableDnD' : '' ).'"*}
cellpadding="0" cellspacing="0"> cellpadding="0" cellspacing="0">
<thead> <thead>
<tr class="nodrag nodrop"> <tr class="nodrag nodrop">
@@ -138,10 +138,8 @@
<option value="0" {if $params.value == 0 && $params.value != ''} selected="selected" {/if}>{l s='No'}</option> <option value="0" {if $params.value == 0 && $params.value != ''} selected="selected" {/if}>{l s='No'}</option>
</select> </select>
{elseif $params.type == 'date' || $params.type == 'datetime'} {elseif $params.type == 'date' || $params.type == 'datetime'}
{* {l s='From'} <input type="text" class="filter" id="{$name_id}_0" name="{$name}[0]" value="{if isset($value.0)}$value.0{/if}"{if isset($params.width)} style="width:{$params.width}px"{/if}/><br />
{l s='From'} <input type="text" id="'.$nameId.'_0" name="'.$name.'[0]" value="'.(isset($value[0]) ? $value[0] : '').'"'.$width.' '.$keyPress.' /><br /> {l s='To'} <input type="text" class="filter" id="{$name_id}_1" name="{$name}[1]" value="{if isset($value.1)}$value.1{/if}"{if isset($params.width)} style="width:{$params.width}px"{/if}/>
{l s='To'} <input type="text" id="'.$nameId.'_1" name="'.$name.'[1]" value="'.(isset($value[1]) ? $value[1] : '').'"'.$width.' '.$keyPress.' />
*}
{elseif $params.type == 'select'} {elseif $params.type == 'select'}
{if isset($params.filter_key)} {if isset($params.filter_key)}
<select onchange="$('#submitFilter{$table}').focus();$('#submitFilter{$table}').click();" name="{$table}Filter_{$params.filter_key}" {if isset($params.width)} style="width:{$params.width}px"{/if}> <select onchange="$('#submitFilter{$table}').focus();$('#submitFilter{$table}').click();" name="{$table}Filter_{$params.filter_key}" {if isset($params.width)} style="width:{$params.width}px"{/if}>
+20 -14
View File
@@ -84,6 +84,7 @@ class AdminControllerCore extends Controller
protected $colorOnBackground; protected $colorOnBackground;
/** @string Action to perform : 'edit', 'view', 'add', ... */ /** @string Action to perform : 'edit', 'view', 'add', ... */
protected $action; protected $action;
protected $display;
protected $_includeContainer = true; protected $_includeContainer = true;
public function __construct() public function __construct()
@@ -496,6 +497,7 @@ class AdminControllerCore extends Controller
else else
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$token); Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$token);
break; break;
default:
} }
} }
} }
@@ -821,7 +823,7 @@ class AdminControllerCore extends Controller
$this->content = $this->displayErrors(); $this->content = $this->displayErrors();
else else
{ {
if ($this->action == 'edit' && $this->id_entity) if ($this->display == 'edit')
{ {
$this->content .= $this->displayForm(); $this->content .= $this->displayForm();
if ($this->tabAccess['view']){ if ($this->tabAccess['view']){
@@ -833,7 +835,7 @@ class AdminControllerCore extends Controller
// move to form.tpl // move to form.tpl
$this->content .= '<br /><br /><a href="'.((Tools::getValue('back')) ? Tools::getValue('back') : self::$currentIndex.'&token='.$this->token).'"><img src="../img/admin/arrow2.gif" /> '.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'</a><br />'; $this->content .= '<br /><br /><a href="'.((Tools::getValue('back')) ? Tools::getValue('back') : self::$currentIndex.'&token='.$this->token).'"><img src="../img/admin/arrow2.gif" /> '.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'</a><br />';
} }
elseif ($this->action == 'list') elseif ($this->display == 'list')
{ {
$this->getList($this->context->language->id); $this->getList($this->context->language->id);
@@ -851,7 +853,6 @@ class AdminControllerCore extends Controller
$this->content .= $helper->generateList($this->_list, $this->fieldsDisplay); $this->content .= $helper->generateList($this->_list, $this->fieldsDisplay);
} }
} }
} }
/** /**
@@ -993,7 +994,6 @@ class AdminControllerCore extends Controller
} }
elseif (strncmp($key, $this->table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0) elseif (strncmp($key, $this->table.'Filter_', 7) === 0 OR strncmp($key, 'submitFilter', 12) === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value); $this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
if (isset($_GET) AND !empty($_GET) AND isset($this->table)) if (isset($_GET) AND !empty($_GET) AND isset($this->table))
foreach ($_GET AS $key => $value) foreach ($_GET AS $key => $value)
if (is_array($this->table)) if (is_array($this->table))
@@ -1047,7 +1047,23 @@ class AdminControllerCore extends Controller
$this->_errors[] = Tools::displayError('You do not have permission to delete here.'); $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
} }
elseif (Tools::getValue('submitAdd'.$this->table)) elseif (Tools::getValue('submitAdd'.$this->table))
{
$this->action = 'save'; $this->action = 'save';
$this->display = 'edit';
//$this->id_entity = (int)$_GET['id_'.$this->table];
}
elseif (isset($_GET['add'.$this->table]))
{
$this->action = 'new';
$this->display = 'edit';
}
elseif (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
{
if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee')))
$this->display = 'edit';
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
/* Cancel all filters for this tab */ /* Cancel all filters for this tab */
elseif (isset($_POST['submitReset'.$this->table])) elseif (isset($_POST['submitReset'.$this->table]))
$this->action = 'reset_filters'; $this->action = 'reset_filters';
@@ -1059,16 +1075,6 @@ class AdminControllerCore extends Controller
$this->action = 'update_filters'; $this->action = 'update_filters';
elseif(Tools::isSubmit('submitFields') AND $this->requiredDatabase AND $this->tabAccess['add'] === '1' AND $this->tabAccess['delete'] === '1') elseif(Tools::isSubmit('submitFields') AND $this->requiredDatabase AND $this->tabAccess['add'] === '1' AND $this->tabAccess['delete'] === '1')
$this->action = 'update_fields'; $this->action = 'update_fields';
elseif (isset($_GET['update'.$this->table]) && isset($_GET['id_'.$this->table]))
{
if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee')))
{
$this->action = 'edit';
$this->id_entity = (int)$_GET['id_'.$this->table];
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
} }
/** /**
+46 -2
View File
@@ -35,6 +35,12 @@ class HelperCore
'Home', 'selected', 'selecteds', 'Collapse All', 'Expand All', 'Check All', 'Uncheck All' 'Home', 'selected', 'selecteds', 'Collapse All', 'Expand All', 'Check All', 'Uncheck All'
); );
public function __construct()
{
$this->context = Context::getContext();
}
/** /**
* *
* @param type $trads values of translations keys * @param type $trads values of translations keys
@@ -63,7 +69,7 @@ class HelperCore
{ {
if (!$use_radio) if (!$use_radio)
$input_name = $input_name.'[]'; $input_name = $input_name.'[]';
$html = ' $html = '
<script src="../js/jquery/treeview/jquery.treeview.js" type="text/javascript"></script> <script src="../js/jquery/treeview/jquery.treeview.js" type="text/javascript"></script>
<script src="../js/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script> <script src="../js/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script>
@@ -159,7 +165,7 @@ class HelperCore
$select_html .= '<option value="">'.$select_options['empty'].'</option>'; $select_html .= '<option value="">'.$select_options['empty'].'</option>';
if (isset($select_options['selected']) && !is_array($select_options['selected'])) if (isset($select_options['selected']) && !is_array($select_options['selected']))
$select_options['selected'] = array($select_options['selected']); $select_options['selected'] = array($select_options['selected']);
// render options fields // render options fields
foreach ($values as $key => $value) foreach ($values as $key => $value)
{ {
@@ -196,5 +202,43 @@ class HelperCore
return rtrim($html, ' '); return rtrim($html, ' ');
} }
function bindDatepicker($id, $time)
{
if ($time)
echo '
var dateObj = new Date();
var hours = dateObj.getHours();
var mins = dateObj.getMinutes();
var secs = dateObj.getSeconds();
if (hours < 10) { hours = "0" + hours; }
if (mins < 10) { mins = "0" + mins; }
if (secs < 10) { secs = "0" + secs; }
var time = " "+hours+":"+mins+":"+secs;';
echo '
$(function() {
$("#'.$id.'").datepicker({
prevText:"",
nextText:"",
dateFormat:"yy-mm-dd"'.($time ? '+time' : '').'});
});';
}
// id can be a identifier or an array of identifiers
function includeDatepicker($id, $time = false)
{
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui-1.8.10.custom.min.js"></script>';
$iso = Db::getInstance()->getValue('SELECT iso_code FROM '._DB_PREFIX_.'lang WHERE `id_lang` = '.(int)Context::getContext()->language->id);
if ($iso != 'en')
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/datepicker/ui/i18n/ui.datepicker-'.$iso.'.js"></script>';
echo '<script type="text/javascript">';
if (is_array($id))
foreach ($id as $id2)
bindDatepicker($id2, $time);
else
bindDatepicker($id, $time);
echo '</script>';
}
} }
+15 -10
View File
@@ -1,5 +1,5 @@
<?php <?php
class HelperList class HelperListCore extends Helper
{ {
/** @var array Cache for query results */ /** @var array Cache for query results */
protected $_list = array(); protected $_list = array();
@@ -67,11 +67,6 @@ class HelperList
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');
public function __construct()
{
$this->context = Context::getContext();
}
/** /**
* Return an html list given the data to fill it up * Return an html list given the data to fill it up
* *
@@ -340,6 +335,12 @@ class HelperList
// Check if object can be modified, deleted or detailed // Check if object can be modified, deleted or detailed
$has_actions = ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) ? true : false; $has_actions = ($this->edit OR $this->delete OR ($this->view AND $this->view !== 'noActionColumn')) ? true : false;
if (array_key_exists($this->identifier,$this->identifiersDnd) && (int)(Tools::getValue($this->identifiersDnd[$this->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'))
$table_dnd = true;
foreach ($this->fieldsDisplay as $key => $params) foreach ($this->fieldsDisplay as $key => $params)
{ {
if (!isset($params['type'])) if (!isset($params['type']))
@@ -357,9 +358,9 @@ class HelperList
$value = unserialize($value); $value = unserialize($value);
if (!Validate::isCleanHtml($value[0]) OR !Validate::isCleanHtml($value[1])) if (!Validate::isCleanHtml($value[0]) OR !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);
//$nameId = str_replace('!', '__', $name); $name_id = str_replace('!', '__', $name);
//includeDatepicker(array($nameId.'_0', $nameId.'_1')); $this->includeDatepicker(array($name_id.'_0', $name_id.'_1'));
break; break;
case 'select': case 'select':
foreach ($params['select'] AS $option_value => $option_display) foreach ($params['select'] AS $option_value => $option_display)
@@ -397,7 +398,11 @@ class HelperList
'id_cat' => $id_cat, 'id_cat' => $id_cat,
'shop_link_type' => $this->shopLinkType, 'shop_link_type' => $this->shopLinkType,
'has_actions' => $has_actions, 'has_actions' => $has_actions,
'add_button' => $this->edit AND (!isset($this->noAdd) OR !$this->noAdd),
'table_id' => isset($table_id) ? $table_id : null,
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
'name' => isset($name) ? $name : null,
'name_id' => isset($name_id) ? $name_id : null,
)); ));
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_header.tpl'); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_header.tpl');
+5 -17
View File
@@ -157,9 +157,6 @@ class AdminAddressesControllerCore extends AdminController
else else
Tools::redirectAdmin(Tools::getValue('back').'&conf=4'); Tools::redirectAdmin(Tools::getValue('back').'&conf=4');
} }
if (!isset($this->action))
$this->action = 'list';
} }
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL) public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL)
@@ -506,21 +503,12 @@ class AdminAddressesControllerCore extends AdminController
return $out; return $out;
} }
/*public function initContent() public function initContent()
{ {
$this->getList($this->context->language->id); if ($this->display != 'edit')
$this->display = 'list';
$helper = new HelperList(); parent::initContent();
$helper->edit = $this->edit; }
$helper->delete = $this->delete;
$helper::$currentIndex = self::$currentIndex;
$helper->table = $this->table;
$helper->shopLink = $this->shopLink;
$helper->shopLinkType = $this->shopLinkType;
$helper->identifier = $this->identifier;
$helper->token = $this->token;
$this->context->smarty->assign(array('list' => $helper->generateList($this->_list, $this->fieldsDisplay)));
}*/
} }