Skip to content

#1390 Add related content information to the delete asset warning #1401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84eae32
Add related content information to the delete asset warning
ProkopovVitaliy May 29, 2020
e7889e5
corrected message text
ProkopovVitaliy May 30, 2020
f17ecca
Merge branch '2.0.0-stabilization' into #1390
ProkopovVitaliy May 30, 2020
3b0cd3c
changed message for delete confirmation
ProkopovVitaliy Jun 1, 2020
eedc6ab
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 1, 2020
ee31084
Merge branch '2.0.0-stabilization' into #1390
ProkopovVitaliy Jun 1, 2020
3a1c9d1
Update Provider.php
ProkopovVitaliy Jun 1, 2020
41a0c4a
corrected static test
ProkopovVitaliy Jun 1, 2020
ff3dd10
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 1, 2020
18fecea
processing of additional information for the removal process has been…
ProkopovVitaliy Jun 9, 2020
2d7b00f
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 9, 2020
1ac1e12
Update MediaGalleryUi/Ui/Component/Listing/Provider.php
ProkopovVitaliy Jun 10, 2020
7243241
apply code review recommendations
ProkopovVitaliy Jun 10, 2020
b94408d
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 10, 2020
fa88116
fixed failed static test
ProkopovVitaliy Jun 10, 2020
167d92e
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 10, 2020
05443d7
fixed confirmation message for deleting ffrom detail window
ProkopovVitaliy Jun 11, 2020
48d3a3e
fixed code style
ProkopovVitaliy Jun 11, 2020
c7e80a4
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 11, 2020
728ccbb
fixed eslint errors
ProkopovVitaliy Jun 12, 2020
5b1feeb
removed extra char
ProkopovVitaliy Jun 12, 2020
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
8 changes: 4 additions & 4 deletions MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ define([
*
* @param {Object} record
* @param {String} deleteUrl
* @param {String} confirmationContent
*/
deleteImageAction: function (record, deleteUrl) {
var baseContent = $.mage.__('Are you sure you want to delete "%s" image?'),
title = $.mage.__('Delete image'),
deleteImageAction: function (record, deleteUrl, confirmationContent) {
var title = $.mage.__('Delete image'),
cancelText = $.mage.__('Cancel'),
deleteImageText = $.mage.__('Delete Image'),
deleteImageCallback = this.deleteImage.bind(this);

confirmation({
title: title,
modalClass: 'media-gallery-delete-image-action',
content: baseContent.replace('%s', record.path),
content: confirmationContent,
buttons: [
{
text: cancelText,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'jquery',
'underscore',
'Magento_MediaGalleryUi/js/action/getDetails',
'Magento_MediaGalleryUi/js/action/deleteImage'
], function ($, _, getDetails, deleteImage) {
'use strict';

return {

/**
* Get information about image use
*
* @param {Object} record
* @param {String} imageDetailsUrl
* @param {String} deleteImageUrl
*/
deleteImageAction: function (record, imageDetailsUrl, deleteImageUrl) {
var confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?')
.replace('%2', record.path);

getDetails(imageDetailsUrl, record.id)
.then(function (imageDetails) {
confirmationContent = confirmationContent.replace(
'%1',
this.getConfirmationContentByImageDetails(imageDetails)
);
}.bind(this)).fail(function () {
confirmationContent = confirmationContent.replace('%1', '');
}).always(function () {
deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent);
});
},

/**
* Returns confirmation content with information about related content
*
* @param {Object} imageDetails
* @return String
*/
getConfirmationContentByImageDetails: function (imageDetails) {
var details = imageDetails.details;

if (_.isObject(details) && !_.isUndefined(details['6'])) {
return this.getRecordRelatedContentMessage(details['6'].value);
}

return '';
},

/**
* Get information about image use
*
* @param {Object|String} value
* @return {String}
*/
getRecordRelatedContentMessage: function (value) {
var usedInMessage = $.mage.__('This image is used in %s.'),
usedIn = '';

if (_.isObject(value) && !_.isEmpty(value)) {
_.each(value, function (numberOfTimeUsed, moduleName) {
usedIn += numberOfTimeUsed + ' ' + moduleName + ', ';
});
usedIn = usedIn.replace(/,\s*$/, '');

return usedInMessage.replace('%s', usedIn);
}

return '';
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ define([
'jquery',
'underscore',
'uiComponent',
'Magento_MediaGalleryUi/js/action/deleteImage',
'Magento_MediaGalleryUi/js/action/deleteImageWithDetailConfirmation',
'Magento_MediaGalleryUi/js/grid/columns/image/insertImageAction'
], function ($, _, Component, deleteImage, image) {
], function ($, _, Component, deleteImageWithDetailConfirmation, image) {
'use strict';

return Component.extend({
Expand Down Expand Up @@ -51,7 +51,7 @@ define([
initEvents: function () {
$(this.imageModel().addSelectedBtnSelector).click(function () {
image.insertImage(
this.imageModel().getSelected(),
this.imageModel().getSelected(),
{
onInsertUrl: this.imageModel().onInsertUrl,
storeId: this.imageModel().storeId
Expand All @@ -70,7 +70,10 @@ define([
* @param {Object} record
*/
deleteImageAction: function (record) {
deleteImage.deleteImageAction(record, this.imageModel().deleteImageUrl);
var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl,
deleteImageUrl = this.imageModel().deleteImageUrl;

deleteImageWithDetailConfirmation.deleteImageAction(record, imageDetailsUrl, deleteImageUrl);
},

/**
Expand Down
17 changes: 13 additions & 4 deletions MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ define([
'jquery',
'underscore',
'uiElement',
'Magento_MediaGalleryUi/js/action/deleteImage',
'Magento_MediaGalleryUi/js/action/deleteImageWithDetailConfirmation',
'Magento_MediaGalleryUi/js/grid/columns/image/insertImageAction'
], function ($, _, Element, deleteImage, addSelected) {
], function ($, _, Element, deleteImageWithDetailConfirmation, addSelected) {
'use strict';

return Element.extend({
defaults: {
modalSelector: '',
modalWindowSelector: '',
mediaGalleryImageDetailsName: 'mediaGalleryImageDetails',
template: 'Magento_MediaGalleryUi/image/actions',
modules: {
imageModel: '${ $.imageModelName }'
imageModel: '${ $.imageModelName }',
mediaGalleryImageDetails: '${ $.mediaGalleryImageDetailsName }'
}
},

Expand Down Expand Up @@ -52,7 +54,14 @@ define([
* Delete image action
*/
deleteImageAction: function () {
deleteImage.deleteImageAction(this.imageModel().getSelected(), this.imageModel().deleteImageUrl);
var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl,
deleteImageUrl = this.imageModel().deleteImageUrl;

deleteImageWithDetailConfirmation.deleteImageAction(
this.imageModel().getSelected(),
imageDetailsUrl,
deleteImageUrl
);
},

/**
Expand Down