Skip to content

Commit 9fb4483

Browse files
committed
MC-3315: Banner/Slider: Image still display on Banner/Slider slide-out after deleted
- Initial fix
1 parent 01f4b40 commit 9fb4483

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/image-uploader.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ define([
1717
'use strict';
1818

1919
return Element.extend({
20+
/**
21+
* {@inheritDoc}
22+
*/
23+
initialize: function () {
24+
this._super();
25+
26+
// Listen for file deletions from the media browser
27+
$(window).on('fileDeleted.mediabrowser', this.onDeleteFile.bind(this));
28+
},
2029

2130
/**
2231
* Assign uid for media gallery
@@ -78,6 +87,40 @@ define([
7887
browser.openDialog(openDialogUrl, null, null, this.mediaGallery.openDialogTitle);
7988
},
8089

90+
/**
91+
* @param {jQuery.event} e
92+
* @param {Object} data
93+
* @returns {Object} Chainables
94+
*/
95+
onDeleteFile: function (e, data) {
96+
var fileId = this.getFileId(),
97+
deletedFileIds = data.ids;
98+
99+
if (fileId && $.inArray(fileId, deletedFileIds) > -1) {
100+
this.clear();
101+
}
102+
103+
return this;
104+
},
105+
106+
/**
107+
* {@inheritDoc}
108+
*/
109+
clear: function () {
110+
this.value([]);
111+
112+
return this;
113+
},
114+
115+
/**
116+
* Gets the ID of the file used if set
117+
*
118+
* @return {String|Null} ID
119+
*/
120+
getFileId: function () {
121+
return this.hasData() ? this.value()[0].id : null;
122+
},
123+
81124
/**
82125
* Trigger native browser file upload UI via clicking on 'Upload' button
83126
*

0 commit comments

Comments
 (0)