[+] BO : #PSFV-94 - new controller AdminTags, thanks again to Julien Breux \!

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10162 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mMarinetti
2011-11-16 10:08:14 +00:00
parent effd1924f8
commit 58fbf5f9e8
4 changed files with 195 additions and 136 deletions
-136
View File
@@ -1,136 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminTags extends AdminTab
{
public function __construct()
{
$this->table = 'tag';
$this->className = 'Tag';
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_tag' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25, 'filter_key' => 'a!id_seller_message'),
'lang' => array('title' => $this->l('Language'), 'filter_key' => 'l!name'),
'name' => array('title' => $this->l('Name'), 'width' => 200, 'filter_key' => 'a!name'),
'products' => array('title' => $this->l('Products'), 'align' => 'right', 'havingFilter' => true));
$this->_select = 'l.name as lang, COUNT(pt.id_product) as products';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (a.`id_tag` = pt.`id_tag`)
LEFT JOIN `'._DB_PREFIX_.'lang` l ON (l.`id_lang` = a.`id_lang`)';
$this->_group = 'GROUP BY a.name, a.id_lang';
parent::__construct();
}
public function postProcess()
{
if ($this->tabAccess['edit'] === '1' AND Tools::getValue('submitAdd'.$this->table))
if ($id = (int)(Tools::getValue($this->identifier)) AND $obj = new $this->className($id) AND Validate::isLoadedObject($obj))
$obj->setProducts($_POST['products']);
return parent::postProcess();
}
public function displayForm($isMainTab = true)
{
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$products1 = $obj->getProducts(true);
$products2 = $obj->getProducts(false);
echo '
<form id="formTag" action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" class="width5">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/t/AdminTags.gif" />'.$this->l('Tag').'</legend>
<label>'.$this->l('Name').' </label>
<div class="margin-form">
<input type="text" size="33" name="name" value="'.htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
</div>
<label>'.$this->l('Language').' </label>
<div class="margin-form">
<select name="id_lang">
<option value="">-</option>';
foreach ($this->_languages as $language)
echo ' <option value="'.$language['id_lang'].'" '.($language['id_lang'] == $this->getFieldValue($obj, 'id_lang') ? 'selected="selected"' : '').'>'.$language['name'].'</option>';
echo ' </select> <sup>*</sup>
</div>
<h3>'.$this->l('Products').' </h3>
<table>
<tr>
<td>
<select multiple id="select1" name="products[]" style="width:300px;height:160px;">';
foreach ($products1 as $product)
echo ' <option value="'.$product['id_product'].'">'.$product['name'].'</option>';
echo ' </select><br /><br />
<a href="#" id="add"
style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
'.$this->l('Remove').' &gt;&gt;
</a>
</td>
<td style="padding-left:20px;">
<select multiple id="select2" style="width:300px;height:160px;">';
foreach ($products2 as $product)
echo ' <option value="'.$product['id_product'].'">'.$product['name'].'</option>';
echo ' </select><br /><br />
<a href="#" id="remove"
style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px">
&lt;&lt; '.$this->l('Add').'
</a>
</div>
</td>
</tr>
</table>
<div class="clear">&nbsp;</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>
<script type="text/javascript">
$().ready(function() {
$(\'#add\').click(function() {
return !$(\'#select1 option:selected\').remove().appendTo(\'#select2\');
});
$(\'#remove\').click(function() {
return !$(\'#select2 option:selected\').remove().appendTo(\'#select1\');
});
});
$(\'#formTag\').submit(function() {
$(\'#select1 option\').each(function(i) {
$(this).attr("selected", "selected");
});
});
</script>';
}
}
+2
View File
@@ -19,6 +19,8 @@ input[type="text"],input[type="password"],input[type="file"],textarea {border:1p
select { border:1px solid #ccc;}
select[disabled="disabled"], input[disabled="disabled"],textarea[disabled="disabled"] {border: 1px solid #CCCCCC;color: #AAAAAA}
.header_module{background:url(header_module.png);padding-left: 0.5em;padding-top: 0.8em;height:20px;color: #812143;border:solid 1px #CCC;}
.double_select select{width:300px;height:160px;}
.double_select a{text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px}
/*BUTTON*/
.button{background: -moz-linear-gradient(center top , #F9F9F9, #E3E3E3) repeat scroll 0 0 transparent;
+87
View File
@@ -0,0 +1,87 @@
{*
* 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$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{extends file="helper/form/form.tpl"}
{block name="other_input"}
{if $key eq 'selects'}
<div class="margin-form">
<h3>{l s='Products'}</h3>
<table class="double_select">
<tr>
<td>
<select multiple id="select_left" name="products[]">
{foreach from=$field.products item='product'}
<option value="{$product.id_product}">{$product.name}</option>
{/foreach}
</select>
<span class="hint" name="help_box">{l s='double click to move to other column'}<span class="hint-pointer">&nbsp;</span></span>
<br /><br />
<a href="#" id="move_to_right" class="multiple_select_remove">
{l s='Remove'} &gt;&gt;
</a>
</td>
<td style="padding-left:20px;">
<select multiple id="select_right">
{foreach from=$field.products_unselected item='product'}
<option value="{$product.id_product}">{$product.name}</option>
{/foreach}
</select>
<span class="hint" name="help_box">{l s='double click to move to other column'}<span class="hint-pointer">&nbsp;</span></span>
<br /><br />
<a href="#" id="move_to_left" class="multiple_select_add">
&lt;&lt; {l s='Add'}
</a>
</div>
</td>
</tr>
</table>
</div>
<div class="clear">&nbsp;</div>
<script type="text/javascript">
$(document).ready(function(){
$('#move_to_right').click(function(){
return !$('#select_left option:selected').remove().appendTo('#select_right');
})
$('#move_to_left').click(function(){
return !$('#select_right option:selected').remove().appendTo('#select_left');
});
$('#select_left option').live('dblclick', function(){
$(this).remove().appendTo('#select_right');
});
$('#select_right option').live('dblclick', function(){
$(this).remove().appendTo('#select_left');
});
});
$('#tag_form').submit(function()
{
$('#select_left option').each(function(i){
$(this).attr("selected", "selected");
});
});
</script>
{/if}
{/block}
+106
View File
@@ -0,0 +1,106 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminTagsControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'tag';
$this->className = 'Tag';
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array(
'delete' => array('text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?'))
);
$this->fieldsDisplay = array(
'id_tag' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25, 'filter_key' => 'a!id_seller_message'),
'lang' => array('title' => $this->l('Language'), 'filter_key' => 'l!name'),
'name' => array('title' => $this->l('Name'), 'width' => 200, 'filter_key' => 'a!name'),
'products' => array('title' => $this->l('Products'), 'align' => 'right', 'havingFilter' => true));
$this->_select = 'l.name as lang, COUNT(pt.id_product) as products';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (a.`id_tag` = pt.`id_tag`)
LEFT JOIN `'._DB_PREFIX_.'lang` l ON (l.`id_lang` = a.`id_lang`)';
$this->_group = 'GROUP BY a.name, a.id_lang';
parent::__construct();
}
public function postProcess()
{
if ($this->tabAccess['edit'] === '1' AND Tools::getValue('submitAdd'.$this->table))
if ($id = (int)(Tools::getValue($this->identifier)) AND $obj = new $this->className($id) AND Validate::isLoadedObject($obj))
$obj->setProducts($_POST['products']);
return parent::postProcess();
}
public function initForm()
{
if (!($obj = $this->loadObject(true)))
return;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Tag')
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name:'),
'name' => 'name',
'required' => true
),
array(
'type' => 'select',
'label' => $this->l('Language:'),
'name' => 'id_lang',
'required' => true,
'options' => array(
'query' => Language::getLanguages(false),
'id' => 'id_lang',
'name' => 'name'
)
),
),
'selects' => array(
'products' => $obj->getProducts(true),
'products_unselected' => $obj->getProducts(false)
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
return parent::initForm();
}
}