Skip to content

Commit e8ba6de

Browse files
committed
AC-10720::Migration from outdated jquery/fileUpload library - Resolving Static Tests
1 parent 194ee50 commit e8ba6de

File tree

8 files changed

+231
-227
lines changed

8 files changed

+231
-227
lines changed

app/code/Magento/Backend/view/adminhtml/templates/media/uploader.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// phpcs:disable PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound
88
/** @var $block \Magento\Backend\Block\Media\Uploader */
9+
/** @var \Magento\Framework\Escaper $escaper */
910
?>
1011

1112
<div id="<?= $block->getHtmlId() ?>" class="uploader"
@@ -19,8 +20,8 @@
1920
}'
2021
>
2122
<div class="fileinput-button form-buttons button">
22-
<span><?= $block->escapeHtml(__('Browse Files...')) ?></span>
23-
<div id="fileUploader" data-url="<?= $block->escapeHtmlAttr($block->getConfig()->getUrl()) ?>"></div>
23+
<span><?= $escaper->escapeHtml(__('Browse Files...')) ?></span>
24+
<div id="fileUploader" data-url="<?= $escaper->escapeHtmlAttr($block->getConfig()->getUrl()) ?>"></div>
2425
</div>
2526
<div class="clear"></div>
2627
<script id="<?= $block->getHtmlId() ?>-template" type="text/x-magento-template" data-template="uploader">

app/code/Magento/Cms/view/adminhtml/templates/browser/content/uploader.phtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// phpcs:disable PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound
88
/** @var $block \Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Content\Uploader */
9+
/** @var \Magento\Framework\Escaper $escaper */
910

1011
$blockHtmlId = $block->getHtmlId();
1112
?>
@@ -21,12 +22,12 @@ $blockHtmlId = $block->getHtmlId();
2122
}'
2223
>
2324
<span class="fileinput-button form-buttons">
24-
<span><?= $block->escapeHtml(__('Upload Images')) ?></span>
25+
<span><?= $escaper->escapeHtml(__('Upload Images')) ?></span>
2526
<button id="fileUploader"
26-
name="<?= $block->escapeHtmlAttr($block->getConfig()->getFileField()) ?>"
27+
name="<?= $escaper->escapeHtmlAttr($block->getConfig()->getFileField()) ?>"
2728
value="Upload Images"
28-
data-url="<?= $block->escapeUrl($block->getConfig()->getUrl()) ?>"
29-
><?= $block->escapeHtml(__('Upload Images')) ?></button>
29+
data-url="<?= $escaper->escapeUrl($block->getConfig()->getUrl()) ?>"
30+
><?= $escaper->escapeHtml(__('Upload Images')) ?></button>
3031
</span>
3132
<div class="clear"></div>
3233
<script type="text/x-magento-template" id="<?= /* @noEscape */ $blockHtmlId ?>-template">

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml

Lines changed: 67 additions & 66 deletions
Large diffs are not rendered by default.

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/bulk.js

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,18 @@ define([
217217
*/
218218
getSectionValue: function (section, options) {
219219
switch (this.sections()[section].type()) {
220-
case 'each':
221-
return _.find(this.sections()[section].attribute().chosen, function (chosen) {
222-
return _.find(options, function (option) {
223-
return chosen.id == option.id; //eslint-disable-line eqeqeq
224-
});
225-
}).sections()[section];
220+
case 'each':
221+
return _.find(this.sections()[section].attribute().chosen, function (chosen) {
222+
return _.find(options, function (option) {
223+
return chosen.id == option.id; //eslint-disable-line eqeqeq
224+
});
225+
}).sections()[section];
226226

227-
case 'single':
228-
return this.sections()[section].value();
227+
case 'single':
228+
return this.sections()[section].value();
229229

230-
case 'none':
231-
return this[section];
230+
case 'none':
231+
return this[section];
232232
}
233233
},
234234

@@ -267,27 +267,27 @@ define([
267267
*/
268268
fillImagesSection: function () {
269269
switch (this.sections().images.type()) {
270-
case 'each':
271-
if (this.sections().images.attribute()) {
272-
this.sections().images.attribute().chosen.each(function (option) {
273-
option.sections().images = new this.makeImages(
274-
this.getImageProperty($('[data-role=step-gallery-option-' + option.id + ']')),
275-
'thumbnail'
276-
);
277-
}, this);
278-
}
279-
break;
280-
281-
case 'single':
282-
this.sections().images.value(new this.makeImages(
283-
this.getImageProperty($('[data-role=step-gallery-single]')),
284-
'thumbnail'
285-
));
286-
break;
287-
288-
default:
289-
this.sections().images.value(new this.makeImages());
290-
break;
270+
case 'each':
271+
if (this.sections().images.attribute()) {
272+
this.sections().images.attribute().chosen.each(function (option) {
273+
option.sections().images = new this.makeImages(
274+
this.getImageProperty($('[data-role=step-gallery-option-' + option.id + ']')),
275+
'thumbnail'
276+
);
277+
}, this);
278+
}
279+
break;
280+
281+
case 'single':
282+
this.sections().images.value(new this.makeImages(
283+
this.getImageProperty($('[data-role=step-gallery-single]')),
284+
'thumbnail'
285+
));
286+
break;
287+
288+
default:
289+
this.sections().images.value(new this.makeImages());
290+
break;
291291
}
292292
},
293293

@@ -311,19 +311,19 @@ define([
311311

312312
_.each(this.sections(), function (section) {
313313
switch (section.type()) {
314-
case 'each':
315-
if (!section.attribute()) {
316-
throw new Error($.mage.__('Please select attribute for {section} section.')
317-
.replace('{section}', section.label));
318-
}
319-
break;
314+
case 'each':
315+
if (!section.attribute()) {
316+
throw new Error($.mage.__('Please select attribute for {section} section.')
317+
.replace('{section}', section.label));
318+
}
319+
break;
320320

321-
case 'single':
322-
if (!section.value()) {
323-
throw new Error($.mage.__('Please fill in the values for {section} section.')
324-
.replace('{section}', section.label));
325-
}
326-
break;
321+
case 'single':
322+
if (!section.value()) {
323+
throw new Error($.mage.__('Please fill in the values for {section} section.')
324+
.replace('{section}', section.label));
325+
}
326+
break;
327327
}
328328
}, this);
329329
formValid = true;
@@ -341,19 +341,19 @@ define([
341341
*/
342342
validateImage: function () {
343343
switch (this.sections().images.type()) {
344-
case 'each':
345-
_.each(this.sections().images.attribute().chosen, function (option) {
346-
if (!option.sections().images.images.length) {
347-
throw new Error($.mage.__('Please select image(s) for your attribute.'));
348-
}
349-
});
350-
break;
351-
352-
case 'single':
353-
if (this.sections().images.value().file == null) {
354-
throw new Error($.mage.__('Please choose image(s).'));
344+
case 'each':
345+
_.each(this.sections().images.attribute().chosen, function (option) {
346+
if (!option.sections().images.images.length) {
347+
throw new Error($.mage.__('Please select image(s) for your attribute.'));
355348
}
356-
break;
349+
});
350+
break;
351+
352+
case 'single':
353+
if (this.sections().images.value().file == null) {
354+
throw new Error($.mage.__('Please choose image(s).'));
355+
}
356+
break;
357357
}
358358
},
359359

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/image-uploader.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,39 @@ define([
7272
hideProgressAfterFinish: true
7373
},
7474

75-
uppyDashboard = new Uppy.Uppy({
76-
autoProceed: true,
77-
78-
// validation before file get added
79-
onBeforeFileAdded: (currentFile) => {
80-
if (!this.isSizeExceeded(currentFile).passed) {
81-
this.addValidationErrorMessage(
82-
$t('Cannot upload "%1". File exceeds maximum file size limit.')
83-
.replace('%1', currentFile.name)
84-
);
85-
return false;
86-
} else if (!this.isFileNameLengthExceeded(currentFile).passed) {
87-
this.addValidationErrorMessage(
88-
$t('Cannot upload "%1". Filename is too long, must be 90 characters or less.')
89-
.replace('%1', currentFile.name)
90-
);
91-
return false;
75+
uppyDashboard = new Uppy.Uppy({
76+
autoProceed: true,
77+
// validation before file get added
78+
onBeforeFileAdded: (currentFile) => {
79+
if (!this.isSizeExceeded(currentFile).passed) {
80+
this.addValidationErrorMessage(
81+
$t('Cannot upload "%1". File exceeds maximum file size limit.')
82+
.replace('%1', currentFile.name)
83+
);
84+
return false;
85+
} else if (!this.isFileNameLengthExceeded(currentFile).passed) {
86+
this.addValidationErrorMessage(
87+
$t('Cannot upload "%1". Filename is too long, must be 90 characters or less.')
88+
.replace('%1', currentFile.name)
89+
);
90+
return false;
91+
}
92+
93+
// code to allow duplicate files from same folder
94+
const modifiedFile = {
95+
...currentFile,
96+
id: currentFile.id + '-' + Date.now()
97+
};
98+
99+
this.showLoader();
100+
this.count(1);
101+
return modifiedFile;
102+
},
103+
meta: {
104+
'isAjax': true,
105+
'form_key': window.FORM_KEY
92106
}
93-
94-
// code to allow duplicate files from same folder
95-
const modifiedFile = {
96-
...currentFile,
97-
id: currentFile.id + '-' + Date.now()
98-
};
99-
100-
this.showLoader();
101-
this.count(1);
102-
return modifiedFile;
103-
},
104-
meta: {
105-
'isAjax': true,
106-
'form_key': window.FORM_KEY
107-
}
108-
});
107+
});
109108

110109
// initialize Uppy upload
111110
uppyDashboard.use(Uppy.Dashboard, options);

app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ define([
6565
update: function () {
6666
var checkVideoID =
6767
this.element.find(this.options.container).find('.' + this.options.videoClass).data('code'),
68-
eventVideoData = {
69-
oldVideoId: checkVideoID ? checkVideoID.toString() : checkVideoID,
70-
newVideoId: this.options.videoId ? this.options.videoId.toString() : this.options.videoId
71-
};
68+
eventVideoData = {
69+
oldVideoId: checkVideoID ? checkVideoID.toString() : checkVideoID,
70+
newVideoId: this.options.videoId ? this.options.videoId.toString() : this.options.videoId
71+
};
7272

7373
if (checkVideoID && checkVideoID !== this.options.videoId) {
7474
this._doUpdate();
@@ -350,30 +350,30 @@ define([
350350
}
351351
self._onlyVideoPlayer = true;
352352
}, this))
353-
.createVideoPlayer({
354-
videoId: data.videoId,
355-
videoProvider: data.videoProvider,
356-
useYoutubeNocookie: data.useYoutubeNocookie,
357-
reset: false,
358-
metaData: {
359-
DOM: {
360-
title: '.video-information.title span',
361-
uploaded: '.video-information.uploaded span',
362-
uploader: '.video-information.uploader span',
363-
duration: '.video-information.duration span',
364-
all: '.video-information span',
365-
wrapper: '.video-information'
366-
},
367-
data: {
368-
title: data.title,
369-
uploaded: data.uploaded,
370-
uploader: data.channel,
371-
duration: data.duration,
372-
uploaderUrl: data.channelId
353+
.createVideoPlayer({
354+
videoId: data.videoId,
355+
videoProvider: data.videoProvider,
356+
useYoutubeNocookie: data.useYoutubeNocookie,
357+
reset: false,
358+
metaData: {
359+
DOM: {
360+
title: '.video-information.title span',
361+
uploaded: '.video-information.uploaded span',
362+
uploader: '.video-information.uploader span',
363+
duration: '.video-information.duration span',
364+
all: '.video-information span',
365+
wrapper: '.video-information'
366+
},
367+
data: {
368+
title: data.title,
369+
uploaded: data.uploaded,
370+
uploader: data.channel,
371+
duration: data.duration,
372+
uploaderUrl: data.channelId
373+
}
373374
}
374-
}
375-
})
376-
.off('finish_update_video finish_create_video');
375+
})
376+
.off('finish_update_video finish_create_video');
377377

378378
this._videoRequestComplete = true;
379379
},
@@ -558,10 +558,10 @@ define([
558558
*/
559559
_uploadImage: function (file, oldFile, callback) {
560560
var url = this.options.saveVideoUrl,
561-
data = {
562-
files: file,
563-
url: url
564-
};
561+
data = {
562+
files: file,
563+
url: url
564+
};
565565

566566
this._blockActionButtons(true, true);
567567
this._uploadFile(data, $.proxy(function (result) {
@@ -625,6 +625,7 @@ define([
625625
contentType: false,
626626
data: formData,
627627
success: function (result, textStatus, jqXHR) {
628+
// eslint-disable-next-line no-useless-call
628629
callback.call(null, result, textStatus, jqXHR);
629630
}
630631
});
@@ -678,26 +679,26 @@ define([
678679
modalClass: 'mage-new-video-dialog form-inline',
679680
title: $.mage.__('New Video'),
680681
buttons: [
681-
{
682-
text: $.mage.__('Save'),
683-
class: 'action-primary video-create-button',
684-
click: $.proxy(widget._onCreate, widget)
685-
},
686-
{
687-
text: $.mage.__('Cancel'),
688-
class: 'video-cancel-button',
689-
click: $.proxy(widget._onCancel, widget)
690-
},
691-
{
692-
text: $.mage.__('Delete'),
693-
class: 'video-delete-button',
694-
click: $.proxy(widget._onDelete, widget)
695-
},
696-
{
697-
text: $.mage.__('Save'),
698-
class: 'action-primary video-edit',
699-
click: $.proxy(widget._onUpdate, widget)
700-
}
682+
{
683+
text: $.mage.__('Save'),
684+
class: 'action-primary video-create-button',
685+
click: $.proxy(widget._onCreate, widget)
686+
},
687+
{
688+
text: $.mage.__('Cancel'),
689+
class: 'video-cancel-button',
690+
click: $.proxy(widget._onCancel, widget)
691+
},
692+
{
693+
text: $.mage.__('Delete'),
694+
class: 'video-delete-button',
695+
click: $.proxy(widget._onDelete, widget)
696+
},
697+
{
698+
text: $.mage.__('Save'),
699+
class: 'action-primary video-edit',
700+
click: $.proxy(widget._onUpdate, widget)
701+
}
701702
],
702703

703704
/**

0 commit comments

Comments
 (0)