// Shop association area use tpl file
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11082 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
131
admin-dev/themes/template/helper/assoshop.tpl
Normal file
131
admin-dev/themes/template/helper/assoshop.tpl
Normal file
@@ -0,0 +1,131 @@
|
||||
{*
|
||||
* 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
|
||||
*}
|
||||
|
||||
<script type="text/javascript">
|
||||
$().ready(function() {
|
||||
// Click on "all shop"
|
||||
$('.input_all_shop').live('click', function() {
|
||||
var checked = $(this).attr('checked');
|
||||
$('.input_group_shop').attr('checked', checked);
|
||||
$('.input_shop').attr('checked', checked);
|
||||
});
|
||||
|
||||
// Click on a group shop
|
||||
$('.input_group_shop').live('click', function() {
|
||||
$('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked'));
|
||||
check_all_shop();
|
||||
});
|
||||
|
||||
// Click on a shop
|
||||
$('.input_shop').live('click', function() {
|
||||
check_group_shop_status($(this).val());
|
||||
check_all_shop();
|
||||
});
|
||||
|
||||
// Initialize checkbox
|
||||
$('.input_shop').each(function(k, v) {
|
||||
check_group_shop_status($(v).val());
|
||||
check_all_shop();
|
||||
});
|
||||
});
|
||||
|
||||
function check_group_shop_status(id_group) {
|
||||
var groupChecked = true;
|
||||
$('.input_shop[value='+id_group+']').each(function(k, v) {
|
||||
if (!$(v).attr('checked'))
|
||||
groupChecked = false;
|
||||
});
|
||||
$('.input_group_shop[value='+id_group+']').attr('checked', groupChecked);
|
||||
}
|
||||
|
||||
function check_all_shop() {
|
||||
var allChecked = true;
|
||||
$('.input_group_shop').each(function(k, v) {
|
||||
if (!$(v).attr('checked'))
|
||||
allChecked = false;
|
||||
});
|
||||
$('.input_all_shop').attr('checked', allChecked);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="assoShop">
|
||||
<table class="table" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<th>{if $input.type == 'group_shop'}{l s='Group shop'}{else}{l s='Shop'}{/if}</th>
|
||||
</tr>
|
||||
<tr {if $input.type == 'group_shop'}class="alt_row"{/if}>
|
||||
<td>
|
||||
<label class="t"><input class="input_all_shop" type="checkbox" /> {if $input.type == 'group_shop'}{l s='All group shops'}{else}{l s='All shops'}{/if}</label>
|
||||
</td>
|
||||
</tr>
|
||||
{foreach $input.values as $groupID => $groupData}
|
||||
{if ($input.type == 'group_shop' && (isset($fields_value.shop[$groupID]) || !$form_id))}
|
||||
{assign var=groupChecked value=true}
|
||||
{else}
|
||||
{assign var=groupChecked value=false}
|
||||
{/if}
|
||||
<tr {if $input.type == 'shop'}class="alt_row"{/if}>
|
||||
<td>
|
||||
<img style="vertical-align:middle;" alt="" src="../img/admin/lv2_b.gif" />
|
||||
<label class="t">
|
||||
<input class="input_group_shop"
|
||||
type="checkbox"
|
||||
name="checkBoxGroupShopAsso_{$table}[{$form_id}|intval][{$groupID|intval}]"
|
||||
value="{$groupID}"
|
||||
{if $groupChecked} checked="checked"{/if} />
|
||||
{$groupData['name']}
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{if $input.type == 'shop'}
|
||||
{assign var=j value=0}
|
||||
{foreach $groupData['shops'] as $shopID => $shopData}
|
||||
{if (isset($fields_value.shop[$shopID]) || !$form_id)}
|
||||
{assign var=checked value=true}
|
||||
{else}
|
||||
{assign var=checked value=false}
|
||||
{/if}
|
||||
<tr>
|
||||
<td>
|
||||
<img style="vertical-align:middle;" alt="" src="../img/admin/lv3_{if $j < count($groupData['shops']) - 1}b{else}f{/if}.png" />
|
||||
<label class="child">
|
||||
<input class="input_shop"
|
||||
type="checkbox"
|
||||
value="{$groupID}"
|
||||
name="checkBoxShopAsso_{$table}[{$form_id|intval}][{$shopID|intval}]"
|
||||
id="checkedBox_{$shopID}"
|
||||
{if $checked} checked="checked"{/if} />
|
||||
{$shopData['name']}
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
{assign var=j value=$j+1}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{/foreach}
|
||||
</table>
|
||||
</div>
|
||||
@@ -2253,12 +2253,12 @@ class AdminControllerCore extends Controller
|
||||
return;
|
||||
|
||||
$assos = array();
|
||||
foreach ($_POST as $k => $row)
|
||||
foreach ($_POST['checkBox'.Tools::toCamelCase($type, true).'Asso_'.$table] as $id_asso_object => $row)
|
||||
{
|
||||
if (!preg_match('/^checkBox'.Tools::toCamelCase($type, true).'Asso_'.$table.'_([0-9]+)?_([0-9]+)$/Ui', $k, $res))
|
||||
continue;
|
||||
$id_asso_object = (!empty($res[1]) ? $res[1] : $id_object);
|
||||
$assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$res[2]);
|
||||
if (!(int)$id_asso_object)
|
||||
$id_asso_object = $id_object;
|
||||
foreach ($row as $id_shop => $value)
|
||||
$assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$id_shop);
|
||||
}
|
||||
return array($assos, $type);
|
||||
}
|
||||
@@ -2276,21 +2276,9 @@ class AdminControllerCore extends Controller
|
||||
|
||||
$shop_asso = Shop::getAssoTables();
|
||||
$group_shop_asso = GroupShop::getAssoTables();
|
||||
if (isset($shop_asso[$this->table]) && $shop_asso[$this->table]['type'] == 'shop')
|
||||
$type = 'shop';
|
||||
else if (isset($group_shop_asso[$this->table]) && $group_shop_asso[$this->table]['type'] == 'group_shop')
|
||||
$type = 'group_shop';
|
||||
else
|
||||
return;
|
||||
|
||||
$assos = array();
|
||||
foreach ($_POST as $k => $row)
|
||||
{
|
||||
if (!preg_match('/^checkBox'.Tools::toCamelCase($type, true).'Asso_'.$this->table.'_([0-9]+)?_([0-9]+)$/Ui', $k, $res))
|
||||
continue;
|
||||
$id_asso_object = (!empty($res[1]) ? $res[1] : $id_object);
|
||||
$assos[] = array('id_object' => (int)$id_asso_object, 'id_'.$type => (int)$res[2]);
|
||||
}
|
||||
$assos_data = $this->getAssoShop($this->table, $id_object);
|
||||
$assos = $assos_data[0];
|
||||
$type = $assos_data[1];
|
||||
|
||||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : ''));
|
||||
|
||||
@@ -2324,137 +2312,6 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* displayAssoShop
|
||||
* @todo : create assoshop.tpl and use smarty var asso_shop in pages
|
||||
*
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
protected function displayAssoShop($type = 'shop')
|
||||
{
|
||||
if (!Shop::isFeatureActive() || (!$this->object && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
if ($type != 'shop' && $type != 'group_shop')
|
||||
$type = 'shop';
|
||||
|
||||
$assos = array();
|
||||
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`';
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]][] = $row[$this->identifier];
|
||||
|
||||
$html = <<<EOF
|
||||
<script type="text/javascript">
|
||||
$().ready(function()
|
||||
{
|
||||
// Click on "all shop"
|
||||
$('.input_all_shop').click(function()
|
||||
{
|
||||
var checked = $(this).attr('checked');
|
||||
$('.input_group_shop').attr('checked', checked);
|
||||
$('.input_shop').attr('checked', checked);
|
||||
});
|
||||
|
||||
// Click on a group shop
|
||||
$('.input_group_shop').click(function()
|
||||
{
|
||||
$('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked'));
|
||||
check_all_shop();
|
||||
});
|
||||
|
||||
// Click on a shop
|
||||
$('.input_shop').click(function()
|
||||
{
|
||||
check_group_shop_status($(this).val());
|
||||
check_all_shop();
|
||||
});
|
||||
|
||||
// Initialize checkbox
|
||||
$('.input_shop').each(function(k, v)
|
||||
{
|
||||
check_group_shop_status($(v).val());
|
||||
check_all_shop();
|
||||
});
|
||||
});
|
||||
|
||||
function check_group_shop_status(id_group)
|
||||
{
|
||||
var groupChecked = true;
|
||||
$('.input_shop[value='+id_group+']').each(function(k, v)
|
||||
{
|
||||
if (!$(v).attr('checked'))
|
||||
groupChecked = false;
|
||||
});
|
||||
$('.input_group_shop[value='+id_group+']').attr('checked', groupChecked);
|
||||
}
|
||||
|
||||
function check_all_shop()
|
||||
{
|
||||
var allChecked = true;
|
||||
$('.input_group_shop').each(function(k, v)
|
||||
{
|
||||
if (!$(v).attr('checked'))
|
||||
allChecked = false;
|
||||
});
|
||||
$('.input_all_shop').attr('checked', allChecked);
|
||||
}
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
$html .= '<div class="assoShop">';
|
||||
$html .= '<table class="table" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr><th>'.$this->l('Shop').'</th></tr>';
|
||||
$html .= '<tr'.(($type == 'group_shop') ? ' class="alt_row"' : '').'>
|
||||
<td>
|
||||
<label class="t">
|
||||
<input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'
|
||||
</label>
|
||||
</td>
|
||||
</tr>';
|
||||
foreach (Shop::getTree() as $group_id => $group_data)
|
||||
{
|
||||
$group_checked = ($type == 'group_shop' && ((isset($assos[$group_id]) && in_array($this->object->id, $assos[$group_id])) || !$this->object->id));
|
||||
$html .= '<tr'.(($type == 'shop') ? ' class="alt_row"' : '').'>';
|
||||
$html .= '<td>
|
||||
<img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" />
|
||||
<label class="t">
|
||||
<input class="input_group_shop" type="checkbox"
|
||||
name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->object->id.'_'.$group_id.'" value="'.$group_id.'" '.
|
||||
($group_checked ? 'checked="checked"' : '').' /> '.
|
||||
$group_data['name'].'
|
||||
</label>
|
||||
</td>';
|
||||
$html .= '</tr>';
|
||||
|
||||
if ($type == 'shop')
|
||||
{
|
||||
$total = count($group_data['shops']);
|
||||
$j = 0;
|
||||
foreach ($group_data['shops'] as $shop_id => $shop_data)
|
||||
{
|
||||
$checked = ((isset($assos[$shop_id]) && in_array($this->object->id, $assos[$shop_id])) || !$this->object->id);
|
||||
$html .= '<tr>';
|
||||
$html .= '<td>
|
||||
<img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" />
|
||||
<label class="child">';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$group_id.'"
|
||||
name="checkBoxShopAsso_'.$this->table.'_'.$this->object->id.'_'.$shop_id.'" id="checkedBox_'.$shop_id.'" '.
|
||||
($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= $shop_data['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '</table></div>';
|
||||
$this->context->smarty->assign('asso_shop', $html);
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Overload this method for custom checking
|
||||
*
|
||||
|
||||
@@ -364,7 +364,7 @@ class ConfigurationCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'configuration_lang`
|
||||
WHERE `id_configuration` = (
|
||||
WHERE `id_configuration` IN (
|
||||
SELECT `id_configuration`
|
||||
FROM `'._DB_PREFIX_.'configuration`
|
||||
WHERE `name` = \''.pSQL($key).'\'
|
||||
|
||||
@@ -293,8 +293,8 @@ class HelperCore
|
||||
}
|
||||
global $_LANGADM;
|
||||
|
||||
if ($class == __CLASS__)
|
||||
$class = 'AdminTab';
|
||||
if ($class == __CLASS__)
|
||||
$class = 'AdminTab';
|
||||
|
||||
$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);
|
||||
@@ -302,7 +302,14 @@ class HelperCore
|
||||
return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str)));
|
||||
}
|
||||
|
||||
protected function displayAssoShop($type = 'shop')
|
||||
/**
|
||||
* Render an area to determinate shop association
|
||||
*
|
||||
* @param string $type 'shop' or 'group_shop'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderAssoShop($type = 'shop')
|
||||
{
|
||||
if (!Shop::isFeatureActive() || (!$this->id && $this->context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
@@ -311,12 +318,33 @@ class HelperCore
|
||||
$type = 'shop';
|
||||
|
||||
$assos = array();
|
||||
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`';
|
||||
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]][] = $row[$this->identifier];
|
||||
|
||||
if ((int)$this->id)
|
||||
{
|
||||
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id;
|
||||
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]] = $row['id_'.$type];
|
||||
}
|
||||
|
||||
$tpl = $this->createTemplate('helper/assoshop.tpl');
|
||||
$tpl->assign(array(
|
||||
'input' => array(
|
||||
'type' => $type,
|
||||
'values' => Shop::getTree(),
|
||||
),
|
||||
'fields_value' => array(
|
||||
'shop' => $assos
|
||||
),
|
||||
'form_id' => $this->id,
|
||||
'table' => $this->table
|
||||
));
|
||||
return $tpl->fetch();
|
||||
|
||||
/*
|
||||
//$page = $this->context->smarty->fetch($tpl);
|
||||
$html = <<<EOF
|
||||
<script type="text/javascript">
|
||||
$().ready(function()
|
||||
@@ -404,6 +432,7 @@ EOF;
|
||||
}
|
||||
$html .= '</table></div>';
|
||||
return $html;
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,12 +68,11 @@ class HelperFormCore extends Helper
|
||||
if ($this->submit_action == '')
|
||||
$this->submit_action = 'submitAdd'.$this->table;
|
||||
|
||||
/* TODO : replace call method displayAssoShop() by form_shop.tpl */
|
||||
if (isset($this->fields_form[0]['form']['asso_shop']) && Shop::isFeatureActive())
|
||||
if ($this->fields_form[0]['asso_shop'] == 'group')
|
||||
$asso_shop = $this->displayAssoShop('group_shop');
|
||||
$asso_shop = $this->renderAssoShop('group_shop');
|
||||
else if ($this->fields_form[0]['form']['asso_shop'] == 'shop')
|
||||
$asso_shop = $this->displayAssoShop();
|
||||
$asso_shop = $this->renderAssoShop();
|
||||
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'form.js');
|
||||
|
||||
|
||||
@@ -2742,8 +2742,16 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
$cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute');
|
||||
$data->assign('feature_shop_active', Shop::isFeatureActive());
|
||||
// @todo : uses the helperform
|
||||
$data->assign('displayAssoShop', $this->displayAssoShop());
|
||||
|
||||
$helper = new Helper();
|
||||
if ($this->object && $this->object->id)
|
||||
$helper->id = $this->object->id;
|
||||
else
|
||||
$helper->id = null;
|
||||
$helper->table = $this->table;
|
||||
$helper->identifier = $this->identifier;
|
||||
|
||||
$data->assign('displayAssoShop', $helper->renderAssoShop());
|
||||
|
||||
$product_props = array();
|
||||
// global informations
|
||||
|
||||
Reference in New Issue
Block a user