Skip to content

Commit 2a32832

Browse files
committed
ACP2E-3122: refactored fix to cover all scenarios to add image
1 parent 930a31e commit 2a32832

File tree

1 file changed

+0
-120
lines changed

1 file changed

+0
-120
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/file-uploader.js

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -11,126 +11,6 @@ define([
1111
return function (Element) {
1212
return Element.extend({
1313

14-
/**
15-
* {@inheritDoc}
16-
*/
17-
initUploader: function (fileInput) {
18-
_.extend(this.uploaderConfig, {
19-
dropZone: $(fileInput).closest(this.dropZone),
20-
change: this.onFilesChoosed.bind(this),
21-
drop: this.onFilesChoosed.bind(this),
22-
add: this.onBeforeFileUpload.bind(this),
23-
fail: this.onFail.bind(this),
24-
done: this.onFileUploaded.bind(this),
25-
start: this.onLoadingStart.bind(this),
26-
stop: this.onLoadingStop.bind(this)
27-
});
28-
29-
// uppy implementation
30-
if (fileInput !== undefined) {
31-
let targetElement = $(fileInput).closest('.file-uploader-area')[0],
32-
dropTargetElement = $(fileInput).closest(this.dropZone)[0],
33-
formKey = window.FORM_KEY !== undefined ? window.FORM_KEY : $.cookie('form_key'),
34-
fileInputName = this.fileInputName,
35-
arrayFromObj = Array.from,
36-
options = {
37-
proudlyDisplayPoweredByUppy: false,
38-
target: targetElement,
39-
hideUploadButton: true,
40-
hideRetryButton: true,
41-
hideCancelButton: true,
42-
inline: true,
43-
showRemoveButtonAfterComplete: true,
44-
showProgressDetails: false,
45-
showSelectedFiles: false,
46-
allowMultipleUploads: false,
47-
hideProgressAfterFinish: true
48-
};
49-
50-
if (fileInputName === undefined) {
51-
fileInputName = $(fileInput).attr('name');
52-
}
53-
// handle input type file
54-
this.replaceInputTypeFile(fileInput);
55-
56-
const uppy = new Uppy.Uppy({
57-
autoProceed: true,
58-
59-
onBeforeFileAdded: (currentFile) => {
60-
let file = currentFile,
61-
allowed = this.isFileAllowed(file);
62-
63-
if (this.disabled()) {
64-
this.notifyError($t('The file upload field is disabled.'));
65-
return false;
66-
}
67-
68-
if (!allowed.passed) {
69-
this.aggregateError(file.name, allowed.message);
70-
this.uploaderConfig.stop();
71-
return false;
72-
}
73-
74-
// code to allow duplicate files from same folder
75-
const modifiedFile = {
76-
...currentFile,
77-
id: currentFile.id + '-' + Date.now()
78-
};
79-
80-
this.onLoadingStart();
81-
return modifiedFile;
82-
},
83-
84-
meta: {
85-
'form_key': formKey,
86-
'param_name': fileInputName,
87-
isAjax : true
88-
}
89-
});
90-
91-
// initialize Uppy upload
92-
uppy.use(Uppy.Dashboard, options);
93-
94-
// drop area for file upload
95-
uppy.use(Uppy.DropTarget, {
96-
target: dropTargetElement,
97-
onDragOver: () => {
98-
// override Array.from method of legacy-build.min.js file
99-
Array.from = null;
100-
},
101-
onDragLeave: () => {
102-
Array.from = arrayFromObj;
103-
}
104-
});
105-
106-
// upload files on server
107-
uppy.use(Uppy.XHRUpload, {
108-
endpoint: this.uploaderConfig.url,
109-
fieldName: fileInputName
110-
});
111-
112-
uppy.on('upload-success', (file, response) => {
113-
let data = {
114-
files : [response.body],
115-
result : response.body
116-
};
117-
118-
this.onFileUploaded('', data);
119-
});
120-
121-
uppy.on('upload-error', (file, error) => {
122-
console.error(error.message);
123-
console.error(error.status);
124-
});
125-
126-
uppy.on('complete', () => {
127-
this.onLoadingStop();
128-
Array.from = arrayFromObj;
129-
});
130-
}
131-
return this;
132-
},
133-
13414
/**
13515
* {@inheritDoc}
13616
*/

0 commit comments

Comments
 (0)