From f5b4f351fa5b1f401a366090c0fb9ff9e52aa062 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Fri, 6 Apr 2012 11:59:29 +0000 Subject: [PATCH] // PI-116 - attribute default refactoring git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14525 b9a71923-0436-4b27-9f14-aed3839534dd --- .../combination/helpers/list/list_footer.tpl | 13 -- .../helpers/list/list_action_default.tpl | 2 +- classes/helper/HelperList.php | 6 +- controllers/admin/AdminProductsController.php | 9 +- js/admin-products.js | 158 +++++++++--------- js/attributesBack.js | 2 + 6 files changed, 89 insertions(+), 101 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/combination/helpers/list/list_footer.tpl b/admin-dev/themes/default/template/controllers/products/combination/helpers/list/list_footer.tpl index 674c3f312..3cd7899c9 100644 --- a/admin-dev/themes/default/template/controllers/products/combination/helpers/list/list_footer.tpl +++ b/admin-dev/themes/default/template/controllers/products/combination/helpers/list/list_footer.tpl @@ -34,17 +34,4 @@
  • {l s='A default combination must be designated for each product.'}
  • - - - {/block} diff --git a/admin-dev/themes/default/template/helpers/list/list_action_default.tpl b/admin-dev/themes/default/template/helpers/list/list_action_default.tpl index e536fd255..ebd0ac3ce 100644 --- a/admin-dev/themes/default/template/helpers/list/list_action_default.tpl +++ b/admin-dev/themes/default/template/helpers/list/list_action_default.tpl @@ -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 *} - + {$action} \ No newline at end of file diff --git a/classes/helper/HelperList.php b/classes/helper/HelperList.php index f7588c616..b7e7b6c0c 100644 --- a/classes/helper/HelperList.php +++ b/classes/helper/HelperList.php @@ -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(); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index cc0c017f7..8cf6916a2 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -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; } diff --git a/js/admin-products.js b/js/admin-products.js index 636df2005..30a0e8d1d 100644 --- a/js/admin-products.js +++ b/js/admin-products.js @@ -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("\"Default\""); - } - }); - 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'); }); }; diff --git a/js/attributesBack.js b/js/attributesBack.js index b0f4b2777..600a55fdc 100644 --- a/js/attributesBack.js +++ b/js/attributesBack.js @@ -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)