[-] BO : fix bug #PSCFV-2307 - multishop: product modification applied to the wrong shop caused by race condition with ajax calls
This commit is contained in:
@@ -148,7 +148,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the tab has not already been loaded, load it now
|
// if the tab has not already been loaded, load it now
|
||||||
tabs_manager.display(id, true, 0, null);
|
tabs_manager.display(id, true);
|
||||||
|
|
||||||
tabs_manager.onLoad(id, function(){
|
tabs_manager.onLoad(id, function(){
|
||||||
$("#product-tab-content-"+id).show(0, function(){
|
$("#product-tab-content-"+id).show(0, function(){
|
||||||
@@ -208,8 +208,7 @@
|
|||||||
{/foreach}
|
{/foreach}
|
||||||
|
|
||||||
// Recursively load tabs starting with the first element of stack
|
// Recursively load tabs starting with the first element of stack
|
||||||
tabs_manager.display(tabs_to_preload[0], false, 0, tabs_to_preload);
|
tabs_manager.displayBulk(tabs_to_preload);
|
||||||
|
|
||||||
$('.productTabs').show();
|
$('.productTabs').show();
|
||||||
$('#product_form').show();
|
$('#product_form').show();
|
||||||
$('#product-tab-content-wait').hide();
|
$('#product-tab-content-wait').hide();
|
||||||
|
|||||||
@@ -1537,7 +1537,7 @@ tabs_manager.setTabs(product_tabs);
|
|||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// The manager schedules the onReady() methods of each tab to be called when the tab is loaded
|
// The manager schedules the onReady() methods of each tab to be called when the tab is loaded
|
||||||
tabs_manager.onReady();
|
tabs_manager.init();
|
||||||
|
|
||||||
updateCurrentText();
|
updateCurrentText();
|
||||||
|
|
||||||
|
|||||||
+38
-15
@@ -27,22 +27,30 @@
|
|||||||
* Handles loading of product tabs
|
* Handles loading of product tabs
|
||||||
*/
|
*/
|
||||||
function ProductTabsManager(){
|
function ProductTabsManager(){
|
||||||
this.product_tabs = [];
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
this.product_tabs = [];
|
||||||
|
this.current_request;
|
||||||
|
|
||||||
this.setTabs = function(tabs){
|
this.setTabs = function(tabs){
|
||||||
this.product_tabs = tabs;
|
this.product_tabs = tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule execution of onReady() function for each tab
|
* Schedule execution of onReady() function for each tab and bind events
|
||||||
*/
|
*/
|
||||||
this.onReady = function(){
|
this.init = function(){
|
||||||
for (var tab_name in this.product_tabs)
|
for (var tab_name in this.product_tabs)
|
||||||
{
|
{
|
||||||
if (this.product_tabs[tab_name].onReady !== undefined)
|
if (this.product_tabs[tab_name].onReady !== undefined)
|
||||||
this.onLoad(tab_name, this.product_tabs[tab_name].onReady);
|
this.onLoad(tab_name, this.product_tabs[tab_name].onReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(document).bind('change', function(){
|
||||||
|
if (self.current_request)
|
||||||
|
{
|
||||||
|
self.current_request.abort();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,14 +76,12 @@ function ProductTabsManager(){
|
|||||||
/**
|
/**
|
||||||
* Get a single tab or recursively get tabs in stack then display them
|
* Get a single tab or recursively get tabs in stack then display them
|
||||||
*
|
*
|
||||||
* @param int id position of the tab in the product page
|
* @param string tab_name name of the tab
|
||||||
* @param boolean selected is the tab selected
|
* @param boolean selected is the tab selected
|
||||||
* @param int index current index in the stack (or 0)
|
|
||||||
* @param array stack list of tab ids to load (or null)
|
|
||||||
*/
|
*/
|
||||||
this.display = function (id, selected, index, stack)
|
this.display = function (tab_name, selected)
|
||||||
{
|
{
|
||||||
var tab_selector = $("#product-tab-content-"+id);
|
var tab_selector = $("#product-tab-content-"+tab_name);
|
||||||
|
|
||||||
// Is the tab already being loaded?
|
// Is the tab already being loaded?
|
||||||
if (!tab_selector.hasClass('not-loaded') || tab_selector.hasClass('loading'))
|
if (!tab_selector.hasClass('not-loaded') || tab_selector.hasClass('loading'))
|
||||||
@@ -92,8 +98,8 @@ function ProductTabsManager(){
|
|||||||
if (save_error)
|
if (save_error)
|
||||||
data = post_data;
|
data = post_data;
|
||||||
|
|
||||||
$.ajax({
|
return $.ajax({
|
||||||
url : $('#link-'+id).attr("href")+"&ajax=1",
|
url : $('#link-'+tab_name).attr("href")+"&ajax=1",
|
||||||
async : true,
|
async : true,
|
||||||
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
|
cache: false, // cache needs to be set to false or IE will cache the page with outdated product values
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@@ -105,22 +111,19 @@ function ProductTabsManager(){
|
|||||||
|
|
||||||
if (selected)
|
if (selected)
|
||||||
{
|
{
|
||||||
$("#link-"+id).addClass('selected');
|
$("#link-"+tab_name).addClass('selected');
|
||||||
tab_selector.show();
|
tab_selector.show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
complete : function(data)
|
complete : function(data)
|
||||||
{
|
{
|
||||||
$("#product-tab-content-"+id).removeClass('loading');
|
tab_selector.removeClass('loading');
|
||||||
if (selected)
|
if (selected)
|
||||||
{
|
{
|
||||||
$('#product-tab-content-wait').hide();
|
$('#product-tab-content-wait').hide();
|
||||||
tab_selector.trigger('displayed');
|
tab_selector.trigger('displayed');
|
||||||
}
|
}
|
||||||
tab_selector.trigger('loaded');
|
tab_selector.trigger('loaded');
|
||||||
|
|
||||||
if (stack && stack[index + 1])
|
|
||||||
self.display(stack[index + 1], selected, index + 1, stack);
|
|
||||||
},
|
},
|
||||||
beforeSend : function(data)
|
beforeSend : function(data)
|
||||||
{
|
{
|
||||||
@@ -130,4 +133,24 @@ function ProductTabsManager(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an ajax call for each tab in the stack, binding each call to the "complete" event of the previous call
|
||||||
|
*
|
||||||
|
* @param array stack contains tab names as strings
|
||||||
|
*/
|
||||||
|
this.displayBulk = function(stack){
|
||||||
|
this.current_request = this.display(stack[0], false);
|
||||||
|
|
||||||
|
if (this.current_request !== undefined)
|
||||||
|
{
|
||||||
|
this.current_request.complete(function(request, status){
|
||||||
|
stack.shift();
|
||||||
|
if (stack.length !== 0 && status !== 'abort')
|
||||||
|
{
|
||||||
|
self.displayBulk(stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user