// fix update view.tpl in AdminRequestSqlController

This commit is contained in:
lLefevre
2011-11-07 09:25:26 +00:00
parent ccfc2af865
commit 88fb11cc70
2 changed files with 86 additions and 101 deletions
+39 -42
View File
@@ -24,47 +24,44 @@
* International Registered Trademark & Property of PrestaShop SA
*}
{if isset($view['error'])}
<p>{l s ='This query has no result.'}</p>
{else}
<h2>{$view['name']}</h2>
<table cellpadding="0" cellspacing="0" class="table" id="viewRequestSql">
<thead>
<tr>
{foreach $view['key'] AS $key}
<th align="center">{$key}</th>
{/foreach}
</tr>
</thead>
<tbody>
{foreach $view['results'] AS $result}
<tr>
{foreach $view['key'] AS $name}
{if isset($view['attributes'][$name])}
<td>{$view['attributes'][$name]}</td>
{else}
<td>{$result[$name]}</td>
{/if}
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
{extends file="helper/view/view.tpl"}
<script type="text/javascript">
$(function(){
var width = $('#viewRequestSql').width();
if (width > 990){
$('#viewRequestSql').css('display','block').css('overflow-x', 'scroll');
}
});
</script>
{/if}
<br /><br />
{if isset($back)}
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
{/if}
<br />
{block name="override_tpl"}
{if isset($view['error'])}
<p>{l s ='This query has no result.'}</p>
{else}
<h2>{$view['name']}</h2>
<table cellpadding="0" cellspacing="0" class="table" id="viewRequestSql">
<thead>
<tr>
{foreach $view['key'] AS $key}
<th align="center">{$key}</th>
{/foreach}
</tr>
</thead>
<tbody>
{foreach $view['results'] AS $result}
<tr>
{foreach $view['key'] AS $name}
{if isset($view['attributes'][$name])}
<td>{$view['attributes'][$name]}</td>
{else}
<td>{$result[$name]}</td>
{/if}
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
<script type="text/javascript">
$(function(){
var width = $('#viewRequestSql').width();
if (width > 990){
$('#viewRequestSql').css('display','block').css('overflow-x', 'scroll');
}
});
</script>
{/if}
{/block}
+47 -59
View File
@@ -35,16 +35,7 @@ class AdminRequestSqlControllerCore extends AdminController
$this->export = true;
$this->requiredDatabase = true;
$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->context = Context::getContext();
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')),
'export' => array('text' => $this->l('Export selected')));
if (!Tools::getValue('realedit'))
$this->deleted = false;
$this->fieldsDisplay = array(
'id_request_sql' => array('title' => $this->l('ID'), 'width' => 25),
@@ -52,6 +43,41 @@ class AdminRequestSqlControllerCore extends AdminController
'sql' => array('title' => $this->l('Request'), 'width' => 500)
);
parent::__construct();
}
public function initList()
{
$this->displayWarning($this->l('When saving the query, only the request type "SELECT" are allowed.'));
$this->displayInformation('
<strong>'.$this->l('How to create a new sql query?').'</strong>
<br />
<ul>
<li>'.$this->l('Click "Add new".').'<br /></li>
<li>'.$this->l('Fill in the fields and click "Save".').'</li>
<li>'.$this->l('You can then view the query results by clicking on the tab: ').' <img src="../img/admin/details.gif"></li>
<li>'.$this->l('You can then export the query results as a file. Csv file by clicking on the tab: ').' <img src="../img/admin/export.gif"></li>
</ul>
');
$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
),
'export' => array(
'text' => $this->l('Export selected')
)
);
return parent::initList();
}
public function initForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Request')
@@ -79,32 +105,35 @@ class AdminRequestSqlControllerCore extends AdminController
)
);
parent::__construct();
return parent::initForm();
}
public function viewRequestSql()
public function initView()
{
if (!($obj = $this->loadObject(true)))
return;
$content = array();
$view = array();
if ($results = Db::getInstance()->executeS($obj->sql))
{
foreach (array_keys($results[0]) as $key)
$tab_key[] = $key;
$content['name'] = $obj->name;
$content['key'] = $tab_key;
$content['results'] = $results;
$view['name'] = $obj->name;
$view['key'] = $tab_key;
$view['results'] = $results;
$request_sql = new RequestSql();
$content['attributes'] = $request_sql->attributes;
$view['attributes'] = $request_sql->attributes;
}
else
$content['error'] = true;
$view['error'] = true;
return $content;
$this->tpl_view_vars = array(
'view' => $view
);
return parent::initView();
}
public function _childValidation()
@@ -120,47 +149,6 @@ class AdminRequestSqlControllerCore extends AdminController
}
}
public function initContent()
{
$this->displayWarning($this->l('When saving the query, only the request type "SELECT" are allowed.'));
$this->displayInformation('
<strong>'.$this->l('How to create a new sql query?').'</strong>
<br />
<ul>
<li>'.$this->l('Click "Add new".').'<br /></li>
<li>'.$this->l('Fill in the fields and click "Save".').'</li>
<li>'.$this->l('You can then view the query results by clicking on the tab: ').' <img src="../img/admin/details.gif"></li>
<li>'.$this->l('You can then export the query results as a file. Csv file by clicking on the tab: ').' <img src="../img/admin/export.gif"></li>
</ul>
');
$smarty = $this->context->smarty;
if ($this->display != 'edit' && $this->display != 'add' && $this->display != 'view')
$this->display = 'list';
switch ($this->display)
{
case 'edit':
$this->informations = false;
break;
case 'view':
$this->warnings = false;
$this->informations = false;
if (Tools::getValue('back'))
$smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
else
$smarty->assign('back', Tools::safeOutput(self::$currentIndex.'&token='.$this->token));
$smarty->assign('view', $this->viewRequestSql());
break;
}
parent::initContent();
}
public function bulkexport($boxes)
{
if (!$boxes || count($boxes) > 1)