// PI-116 - attribute default refactoring

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14525 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2012-04-06 11:59:29 +00:00
parent ef424cadc4
commit f5b4f351fa
6 changed files with 89 additions and 101 deletions
@@ -34,17 +34,4 @@
<li>{l s='A default combination must be designated for each product.'}</li>
</ul>
</div>
<script type="text/javascript">
var impact = getE('attribute_price_impact');
var impact2 = getE('attribute_weight_impact');
var s_attr_group = $('#span_new_group');
var s_attr_name = $('#span_new_attr');
var s_impact = $('#span_impact');
var s_impact2 = $('#span_weight_impact');
init_elems();
</script>
{/block}
@@ -23,6 +23,6 @@
* @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}" class="default" title="{$action}">
<a href="{$href}" class="default" title="{$action}" {if isset($name)}name="{$name}{/if}">
<img src="../img/admin/asterisk.gif" alt="{$action}" />
</a>
+4 -2
View File
@@ -197,6 +197,7 @@ class HelperListCore extends Helper
{
$id = $tr[$this->identifier];
$name = isset($tr['name']) ? $tr['name'] : null;
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'];
@@ -481,9 +482,10 @@ class HelperListCore extends Helper
self::$cache_lang['Default'] = $this->l('Default', 'Helper');
$tpl->assign(array_merge($this->tpl_delete_link_vars, array(
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token),
'href' => Tools::safeOutput($this->currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token != null ? $token : $this->token)),
'action' => self::$cache_lang['Default'],
'id' => $id,
'name' => Tools::safeOutput($name),
'id' => Tools::safeOutput($id),
)));
return $tpl->fetch();
@@ -3439,24 +3439,21 @@ class AdminProductsControllerCore extends AdminController
foreach ($comb_array as $id_product_attribute => $product_attribute)
{
$list = '';
$js_list = '';
/* In order to keep the same attributes order */
asort($product_attribute['attributes']);
foreach ($product_attribute['attributes'] as $attribute)
{
$list .= htmlspecialchars($attribute[0]).' - '.htmlspecialchars($attribute[1]).', ';
$js_list .= '\''.htmlspecialchars($attribute[0]).' : '.htmlspecialchars($attribute[1]).'\', \''.$attribute[2].'\', ';
}
$list = rtrim($list, ', ');
$js_list = rtrim($js_list, ', ');
$comb_array[$id_product_attribute]['image'] = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false;
$comb_array[$id_product_attribute]['available_date'] = $product_attribute['available_date'] != 0 ? date('Y-m-d', strtotime($product_attribute['available_date'])) : '0000-00-00';
$comb_array[$id_product_attribute]['attributes'] = $list;
if ($product_attribute['default_on'])
{
$this->list_skip_actions['default'][] = $product_attribute['id_product_attribute'];
$comb_array[$id_product_attribute]['name'] = 'is_default';
$comb_array[$id_product_attribute]['color'] = $color_by_default;
}
+79 -79
View File
@@ -55,7 +55,7 @@ product_tabs['Combinations'] = new function(){
$('#add_new_combination').show();
$('#attribute_quantity').show();
$('#product_att_list').html('');
removeButtonCombination('update');
self.removeButtonCombination('update');
$.scrollTo('#add_new_combination', 1200, { offset: -100 });
var wholesale_price = Math.abs(data[0]['wholesale_price']);
var price = Math.abs(data[0]['price']);
@@ -123,103 +123,103 @@ product_tabs['Combinations'] = new function(){
}
};
this.defaultProductAttribute = function(url, item){
$.ajax({
url: url,
data: {
id_product: id_product,
action: 'defaultProductAttribute',
ajax: true
},
context: document.body,
dataType: 'json',
context: this,
async: false,
success: function(data) {
if (data.status == 'ok')
{
showSuccessMessage(data.message);
// Reset previous default attribute display
var previous = $('a[name=is_default]');
previous.closest('tr').attr('style', '');
previous.show();
previous.attr('name', '');
// Update new default attribute display
$(item).closest('tr').css('background','#BDE5F8');
$(item).hide();
$(item).attr('name', 'is_default');
}
else
showErrorMessage(data.message);
}
});
};
this.bindDefault = function(){
$('a[name=is_default]').hide();
$('table[name=list_table]').delegate('a.default', 'click', function(e){
e.preventDefault();
defaultProductAttribute(this.href, $(this).closest('tr'));
self.defaultProductAttribute(this.href, this);
});
};
function defaultProductAttribute (url, parent){
$.ajax({
url: url,
data: {
id_product: id_product,
action: 'defaultProductAttribute',
ajax: true
},
context: document.body,
dataType: 'json',
context: this,
async: false,
success: function(data) {
if (data.status == 'ok')
{
showSuccessMessage(data.message);
$('table.table').find('tr').attr('style', function() {
var style = $(this).attr('style');
if (style)
{
$(this).attr('style', '');
var ids = $(this).find('a.edit').attr('ids');
var token = $(this).find('a.edit').attr('token');
$(this).find('a.edit').after("<a title=\"Default\" onclick=\"javascript:defaultProductAttribute('"+ids+"', '"+token+"', $(this).parent('td').parent('tr'));\" class=\"pointer default\"><img alt=\"Default\" src=\"../img/admin/asterisk.gif\"></a>");
}
});
parent.find('a.default').hide();
parent.css('background','#BDE5F8');
}
else
showErrorMessage(data.message);
this.deleteProductAttribute = function(url, parent){
$.ajax({
url: url,
data: {
id_product: id_product,
action: 'deleteProductAttribute',
ajax: true
},
context: document.body,
dataType: 'json',
context: this,
async: false,
success: function(data) {
if (data.status == 'ok')
{
showSuccessMessage(data.message);
parent.remove();
}
});
}
else
showErrorMessage(data.message);
}
});
};
this.bindDelete = function() {
$('table[name=list_table]').delegate('a.delete', 'click', function(e){
e.preventDefault();
deleteProductAttribute(this.href, $(this).closest('tr'));
self.deleteProductAttribute(this.href, $(this).closest('tr'));
});
};
function deleteProductAttribute(url, parent){
$.ajax({
url: url,
data: {
id_product: id_product,
action: 'deleteProductAttribute',
ajax: true
},
context: document.body,
dataType: 'json',
context: this,
async: false,
success: function(data) {
if (data.status == 'ok')
{
showSuccessMessage(data.message);
parent.remove();
}
else
showErrorMessage(data.message);
}
});
}
this.removeButtonCombination = function(item)
{
$('#add_new_combination').show();
$('.process-icon-newCombination').removeClass('toolbar-new');
$('.process-icon-newCombination').addClass('toolbar-cancel');
$('#desc-product-newCombination div').html($('#ResetBtn').val());
$('id_product_attribute').val(0);
init_elems();
};
this.addButtonCombination = function(item)
{
$('#add_new_combination').hide();
$('.process-icon-newCombination').removeClass('toolbar-cancel');
$('.process-icon-newCombination').addClass('toolbar-new');
$('#desc-product-newCombination div').html(msg_new_combination);
};
this.bindToggleAddCombination = function (){
$('#desc-product-newCombination').click(function() {
if ($('.process-icon-newCombination').hasClass('toolbar-new'))
removeButtonCombination('add');
self.removeButtonCombination('add');
else
addButtonCombination('add');
function removeButtonCombination(item)
{
$('#add_new_combination').show();
$('.process-icon-newCombination').removeClass('toolbar-new');
$('.process-icon-newCombination').addClass('toolbar-cancel');
$('#desc-product-newCombination div').html($('#ResetBtn').val());
$('id_product_attribute').val(0);
init_elems();
}
function addButtonCombination(item)
{
$('#add_new_combination').hide();
$('.process-icon-newCombination').removeClass('toolbar-cancel');
$('.process-icon-newCombination').addClass('toolbar-new');
$('#desc-product-newCombination div').html(msg_new_combination);
}
self.addButtonCombination('add');
});
};
+2
View File
@@ -211,6 +211,8 @@ function check_unit_impact()
function init_elems()
{
var impact = getE('attribute_price_impact');
var impact2 = getE('attribute_weight_impact');
var elem = getE('product_att_list');
if (elem.length)