Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

[*] JS: Refactor fancybox errors to PrestaShop.showError module #202

Merged
merged 4 commits into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions themes/community-theme-16/js/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ function submitFunction() {
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var error = 'TECHNICAL ERROR: unable to load form.\n\nDetails:\nError thrown: ' + XMLHttpRequest + '\n' + 'Text status: ' + textStatus;
if (!!$.prototype.fancybox) {
$.fancybox.open([{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class=\'fancybox-error\'>' + error + '</p>'
}], {
padding: 0
});
} else {
alert(error);
}
PrestaShop.showError(
'TECHNICAL ERROR: unable to load form.\n\nDetails:\nError thrown: '
+ XMLHttpRequest + '\n' + 'Text status: ' + textStatus
);
}
});
}
158 changes: 17 additions & 141 deletions themes/community-theme-16/js/cart-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,7 @@ $(document).ready(function() {
'&allow_refresh=1',
success: function(jsonData) {
if (jsonData.hasError) {
var errors = '';
for (var error in jsonData.errors)
//IE6 bug fix
if (error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + '\n';
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + errors + '</p>'
}],
{
padding: 0
});
else
alert(errors);
PrestaShop.showError(jsonData.errors);
$('input[name=quantity_' + id + ']').val($('input[name=quantity_' + id + '_hidden]').val());
} else {
if (jsonData.refresh) {
Expand Down Expand Up @@ -163,20 +146,7 @@ function changeAddressDelivery(obj) {
'&allow_refresh=1',
success: function(jsonData) {
if (typeof(jsonData.hasErrors) != 'undefined' && jsonData.hasErrors) {
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + jsonData.error + '</p>'
}],
{
padding: 0
});
else
alert(jsonData.error);

PrestaShop.showError(jsonData.error);
// Reset the old address
$('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery);
} else {
Expand Down Expand Up @@ -211,19 +181,7 @@ function changeAddressDelivery(obj) {
{
// This test is will not usefull in the future
if (old_id_address_delivery == 0) {
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + txtSelectAnAddressFirst + '</p>'
}],
{
padding: 0
});
else
alert(txtSelectAnAddressFirst);
PrestaShop.showError(txtSelectAnAddressFirst);
return false;
}

Expand Down Expand Up @@ -255,20 +213,9 @@ function changeAddressDelivery(obj) {
'&token=' + static_token +
'&allow_refresh=1',
success: function(jsonData) {
if (jsonData.error && !!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + jsonData.error + '</p>'
}],
{
padding: 0
});
else
alert(jsonData.error);

if (jsonData.error) {
PrestaShop.showError(jsonData.error);
}
var line = $('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery);
var new_line = line.clone();
updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, new_line);
Expand Down Expand Up @@ -386,24 +333,7 @@ function deleteProductFromSummary(id) {
'&allow_refresh=1',
success: function(jsonData) {
if (jsonData.hasError) {
var errors = '';
for (var error in jsonData.errors)
//IE6 bug fix
if (error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + '\n';
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + errors + '</p>'
}],
{
padding: 0
});
else
alert(errors);
PrestaShop.showError(jsonData.errors);
} else {
if (jsonData.refresh) {
window.location.reload();
Expand Down Expand Up @@ -472,20 +402,10 @@ function deleteProductFromSummary(id) {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus !== 'abort') {
var error = 'TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: ' + XMLHttpRequest + '\n' + 'Text status: ' + textStatus;
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + error + '</p>'
}],
{
padding: 0
});
else
alert(error);
PrestaShop.showError(
'TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: '
+ XMLHttpRequest + '\n' + 'Text status: ' + textStatus
);
}
}
});
Expand Down Expand Up @@ -549,24 +469,7 @@ function upQuantity(id, qty) {
'&allow_refresh=1',
success: function(jsonData) {
if (jsonData.hasError) {
var errors = '';
for (var error in jsonData.errors)
//IE6 bug fix
if (error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + '\n';
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + errors + '</p>'
}],
{
padding: 0
});
else
alert(errors);
PrestaShop.showError(jsonData.errors);
$('input[name=quantity_' + id + ']').val($('input[name=quantity_' + id + '_hidden]').val());
} else {
if (jsonData.refresh) {
Expand All @@ -587,20 +490,10 @@ function upQuantity(id, qty) {
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (textStatus !== 'abort') {
error = 'TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: ' + XMLHttpRequest + '\n' + 'Text status: ' + textStatus;
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + error + '</p>'
}],
{
padding: 0
});
else
alert(error);
PrestaShop.showError(
'TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: '
+ XMLHttpRequest + '\n' + 'Text status: ' + textStatus
);
}
}
});
Expand Down Expand Up @@ -653,24 +546,7 @@ function downQuantity(id, qty) {
'&allow_refresh=1',
success: function(jsonData) {
if (jsonData.hasError) {
var errors = '';
for (var error in jsonData.errors)
//IE6 bug fix
if (error !== 'indexOf')
errors += $('<div />').html(jsonData.errors[error]).text() + '\n';
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + errors + '</p>'
}],
{
padding: 0
});
else
alert(errors);
PrestaShop.showError(jsonData.errors);
$('input[name=quantity_' + id + ']').val($('input[name=quantity_' + id + '_hidden]').val());
} else {
if (jsonData.refresh) {
Expand Down
43 changes: 43 additions & 0 deletions themes/community-theme-16/js/global.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
/* global quickView, page_name, FancyboxI18nClose, FancyboxI18nNext, FancyboxI18nPrev, highDPI, request, url */

var PrestaShop = (function() {

function showWindowAlert(msg, title) {
var content = title ? title + "\n\n" : '';
content += $.isArray(msg) ? msg.join("\n") : msg;
alert(content);
}

function showFancyboxAlert(msg, title, wrapperClass) {
if ($.isArray(msg)) {
msg = '<ul><li>' + msg.join('</li><li>') + '</li><ul>';
}
$.fancybox.open([{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<div class="fancybox-error' + (wrapperClass ? ' ' + wrapperClass : '') + '">'
+ (title ? '<p><b>' + title + '</b></p>' : '') + msg + '</div>'
}], {
padding: 0
});
}

return {
showError : function (msg, title) {
if (!!$.prototype.fancybox) {
showFancyboxAlert(msg, title);
} else {
showWindowAlert(msg, title);
}
},
showSuccess : function (msg, title) {
if (!!$.prototype.fancybox) {
showFancyboxAlert(msg, title, 'fancybox-success');
} else {
showWindowAlert(msg, title);
}
}
};

})();

$(function() {

var touch = !!isTouchDevice();
Expand Down
74 changes: 8 additions & 66 deletions themes/community-theme-16/js/modules/blockcart/ajax-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,7 @@ var ajaxCart = {
window.parent.location.href = window.location.href.replace('content_only=1', '');
return;
}
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + fieldRequired + '</p>'
}
], {
padding: 0
});
else
alert(fieldRequired);
PrestaShop.showError(fieldRequired);
return;
}

Expand Down Expand Up @@ -306,22 +294,11 @@ var ajaxCart = {

},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var error = 'Impossible to add the product to the cart.<br/>textStatus: \'' + textStatus + '\'<br/>errorThrown: \'' +
errorThrown + '\'<br/>responseText:<br/>' + XMLHttpRequest.responseText;
if (!!$.prototype.fancybox) {
$.fancybox.open([{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + error + '</p>'
}], {
padding: 0
});
} else {
alert(error);
}

//reactive the button when adding has finished
PrestaShop.showError(
'Impossible to add the product to the cart.<br/>textStatus: \'' + textStatus + '\'<br/>errorThrown: \'' +
errorThrown + '\'<br/>responseText:<br/>' + XMLHttpRequest.responseText
);
// Reactivate the button when adding has finished
if (addedFromProductPage) {
$productPageBtn.removeProp('disabled').removeClass('disabled');
} else {
Expand Down Expand Up @@ -352,19 +329,7 @@ var ajaxCart = {
}
},
error: function() {
var error = 'ERROR: unable to delete the product';
if (!!$.prototype.fancybox) {
$.fancybox.open([{
type: 'inline',
autoScale: true,
minHeight: 30,
content: error
}], {
padding: 0
});
} else {
alert(error);
}
PrestaShop.showError('ERROR: unable to delete the product');
}
});
},
Expand Down Expand Up @@ -744,30 +709,7 @@ var ajaxCart = {
updateCart: function(jsonData) {
//user errors display
if (jsonData.hasError) {
var errors = '';

for (var error in jsonData.errors) {
if (jsonData.errors.hasOwnProperty(error)) {
//IE6 bug fix
if (error != 'indexOf') {
errors += $('<div />').html(jsonData.errors[error]).text() + '\n';
}
}
}

if (!!$.prototype.fancybox) {
$.fancybox.open([{
type: 'inline',
autoScale: true,
minHeight: 30,
content: '<p class="fancybox-error">' + errors + '</p>'
}], {
padding: 0
});
} else {
alert(errors);
}

PrestaShop.showError(jsonData.errors);
} else {
ajaxCart.updateCartEverywhere(jsonData);
ajaxCart.hideOldProducts(jsonData);
Expand Down
Loading