Skip to content

Commit

Permalink
v1.9.8: CLOUDINARY-184: Added alert on media-library errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pini-girit committed Sep 4, 2019
1 parent bf2b10c commit 8c5a490
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions view/adminhtml/web/js/cloudinary-media-library-modal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
define([
'jquery',
'productGallery',
'Magento_Ui/js/modal/alert',
'mage/backend/notification',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
'mage/translate',
'mage/backend/tree-suggest',
'mage/backend/validation',
'cloudinaryMediaLibraryAll',
'es6Promise'
], function($, productGallery) {
], function($, productGallery, uiAlert, notification, $t) {
'use strict';

$.widget('mage.cloudinaryMediaLibraryModal', {
Expand Down Expand Up @@ -39,6 +41,20 @@ define([
}
},

/**
* @param {Array} messages
*/
notifyError: function(messages) {
var data = {
content: messages.join('')
};
if (messages.length > 1) {
data.modalClass = '_image-box';
}
uiAlert(data);
return this;
},

/**
* @private
*/
Expand Down Expand Up @@ -76,9 +92,12 @@ define([
*/
cloudinaryInsertHandler: function(data) {
var widget = this;
var aggregatedErrorMessages = [];
var $i = data.assets.length;

data.assets.forEach(asset => {
//console.log(asset);
$i--;
if (widget.options.imageUploaderUrl) {
asset.asset_url = asset.asset_image_url = asset.secure_url;
if (asset.derived && asset.derived[0] && asset.derived[0].secure_url) {
Expand Down Expand Up @@ -140,15 +159,29 @@ define([
widget.options.callbackHandler[widget.options.callbackHandlerMethod](file);
}
} else {
alert($.mage.__('An error occured during ' + asset.resource_type + ' insert!'));
console.error(file);
notification().add({
error: true,
message: $t('An error occured during ' + asset.resource_type + ' insert (' + asset.public_id + ')!') + '%s%sError: ' + file.error.replace(/File:.*$/, ''),
insertMethod: function(constructedMessage) {
aggregatedErrorMessages.push(constructedMessage.replace('%s%s', '<br>'));
}
});
}
if (!$i && aggregatedErrorMessages.length) {
widget.notifyError(aggregatedErrorMessages);
}

}
).fail(
function(response) {
alert($.mage.__('An error occured during ' + asset.resource_type + ' insert!'));
console.error(response);
notification().add({
error: true,
message: $t('An error occured during ' + asset.resource_type + ' insert (' + asset.public_id + ')!')
});
if (!$i && aggregatedErrorMessages.length) {
widget.notifyError(aggregatedErrorMessages);
}
}
);
}
Expand Down

0 comments on commit 8c5a490

Please sign in to comment.