From 3453ab1fe5ff27a406904ca30e0ab24e8abfbc6b Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Wed, 4 Jan 2012 10:00:07 +0000 Subject: [PATCH] // Product tabs position and ajax loading order are now independent --- .../themes/default/template/products/form.tpl | 24 ++++---- controllers/admin/AdminProductsController.php | 55 +++++++------------ 2 files changed, 31 insertions(+), 48 deletions(-) diff --git a/admin-dev/themes/default/template/products/form.tpl b/admin-dev/themes/default/template/products/form.tpl index 99fb38de0..df00ac87f 100644 --- a/admin-dev/themes/default/template/products/form.tpl +++ b/admin-dev/themes/default/template/products/form.tpl @@ -227,22 +227,18 @@ var tabs_preloaded = new Array(); $(window).bind("load", function() { - {foreach $tabs_preloaded as $k => $tab} - tabs_preloaded['{$k}'] = '{$tab}'; + {* Fill an array with tabs that need to be preloaded *} + var tabs_to_preload = new Array(); + {foreach $tabs_preloaded as $tab_name => $value} + {* If the tab was not given a loading priority number it will not be preloaded *} + {if (is_numeric($value))} + if ($("#product-tab-content-"+'{$tab_name}').hasClass('not-loaded')) + tabs_to_preload.push('{$tab_name}'); + {/if} {/foreach} - var stack = new Array(); - $('.product-tab-content').each(function(){ - var id = $(this).attr('id').substr(20); - var split_position = id.indexOf('-') + 1; - var btn_name = id.substr(split_position); - - if (tabs_preloaded[btn_name]) - if ($("#product-tab-content-"+id).hasClass('not-loaded')) - stack.push(id); - }); - // Recursively get tabs starting with the first element of stack - displayTabProductById(stack[0], false, 0, stack); + // Recursively load tabs starting with the first element of stack + displayTabProductById(tabs_to_preload[0], false, 0, tabs_to_preload); $('.productTabs').show(); $('#product_form').show(); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index d6ddeb345..b046fe02e 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -39,46 +39,32 @@ class AdminProductsControllerCore extends AdminController */ protected $tab_display; + /** + * The order in the array decides the order in the list of tab. If an element's value is a number, it will be preloaded. + * The tabs are preloaded from the smallest to the highest number. + * @var array Product tabs. + */ protected $available_tabs = array( - 'Informations', - 'Prices', - 'Seo', - 'Associations', - 'Images', - 'Shipping', - 'Combinations', - 'Features', - 'Customization', - 'Attachments', - 'Quantities', - 'Suppliers', - 'Warehouses', - 'Accounting', - 'Pack', - 'VirtualProduct' - ); - - protected $available_tabs_lang = array (); - - protected $tabs_preloaded = array( - 'Informations' => true, - 'Prices' => true, - 'Seo' => true, - 'Associations' => true, + 'Informations' => 0, + 'Pack' => 7, + 'VirtualProduct' => 8, + 'Prices' => 1, + 'Seo' => 2, + 'Associations' => 3, 'Images' => false, - 'Shipping' => true, - 'Combinations' => true, + 'Shipping' => 4, + 'Combinations' => 5, 'Features' => false, 'Customization' => false, 'Attachments' => false, - 'Quantities' => true, + 'Quantities' => 6, 'Suppliers' => false, 'Warehouses' => false, 'Accounting' => false, - 'Pack' => true, - 'VirtualProduct' => true, ); + protected $available_tabs_lang = array (); + public function __construct() { $this->table = 'product'; @@ -998,7 +984,7 @@ class AdminProductsControllerCore extends AdminController // Set tab to display if ($this->action) { - if (in_array($this->action, $this->available_tabs)) + if (in_array($this->action, array_keys($this->available_tabs))) $this->tab_display = $this->action; elseif ($this->action == 'new' || $this->action == 'save') $this->tab_display = 'Informations'; @@ -1877,7 +1863,7 @@ class AdminProductsControllerCore extends AdminController $advanced_stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'); $stock_management_active = Configuration::get('PS_STOCK_MANAGEMENT'); - foreach ($this->available_tabs as $product_tab) + foreach ($this->available_tabs as $product_tab => $value) { // if it's the quantities tab and stock management is disabled, continue if ($stock_management_active == 0 && $product_tab == 'Quantities') @@ -2124,8 +2110,9 @@ class AdminProductsControllerCore extends AdminController if(!method_exists($this, 'initForm'.$this->tab_display)) return; - // Used for loading each tab - $this->tpl_form_vars['tabs_preloaded'] = $this->tabs_preloaded; + // Sort the tabs that need to be preloaded by their priority number + asort($this->available_tabs, SORT_NUMERIC); + $this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs; $this->addJqueryUI('ui.datepicker'); // getLanguages init this->_languages