Skip to content
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

Fix broken JS on Cloud uploader when changing dirs #14542

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 2 additions & 1 deletion src/web/assets/admintable/dist/css/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/web/assets/admintable/dist/css/app.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/web/assets/admintable/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/admintable/dist/js/app.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/admintable/dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"app.css":"/css/app.css","app.js":"/js/app.js","app.js.map":"/js/app.js.map"}
{"app.css":"/css/app.css","app.js":"/js/app.js","app.css.map":"/css/app.css.map","app.js.map":"/js/app.js.map"}
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

21 changes: 4 additions & 17 deletions src/web/assets/cp/src/js/AssetIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,7 @@ Craft.AssetIndex = Craft.BaseElementIndex.extend(

createUploadInputs: function () {
this.$uploadButton?.remove();
// removing this input via this.uploader?.$fileInput and this.$uploadInput doesn't work;
// if the input gets multiplied in the source code, the event's won't fire as expected;
let $uploadInput = this.getButtonContainer().find(
'[name="assets-upload"]'
);
if ($uploadInput.length) {
$uploadInput.remove();
}
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
this.$uploadInput?.remove();

this.$uploadButton = $('<button/>', {
type: 'button',
Expand Down Expand Up @@ -257,7 +250,6 @@ Craft.AssetIndex = Craft.BaseElementIndex.extend(
Garnish.hasAttr(this.$source, 'data-can-upload')
) {
this.uploader?.destroy();
this.$uploadInput.insertBefore(this.$uploadButton);
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
this.$uploadButton.removeClass('disabled');

const options = {
Expand Down Expand Up @@ -301,14 +293,9 @@ Craft.AssetIndex = Craft.BaseElementIndex.extend(
this.currentFolderId = currentFolder?.folderId;

if (!this.settings.foldersOnly && this.currentFolderId) {
if (
this.uploader &&
typeof this.uploader.uploader.fileupload('instance') !== 'undefined'
) {
this.uploader.setParams({
folderId: this.currentFolderId,
});
}
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
this.uploader?.setParams({
folderId: this.currentFolderId,
});

// will the user be allowed to move items in this folder?
const canMoveSubItems = !!currentFolder.canMoveSubItems;
Expand Down
4 changes: 2 additions & 2 deletions src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1990,12 +1990,12 @@ Craft.BaseElementIndex = Garnish.Base.extend(
this.updateFilterBtn();
}

this.onSelectSource();

brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
this.sourcePath =
this.sourcePaths[this.sourceKey] ||
this.$source.data('default-source-path');

this.onSelectSource();

if (this.settings.context === 'index') {
const urlParams = Craft.getQueryParams();
urlParams.source = this.sourceKey;
Expand Down
17 changes: 7 additions & 10 deletions src/web/assets/cp/src/js/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@ Craft.Uploader = Craft.BaseUploader.extend(

this._onFileAdd = this.onFileAdd.bind(this);
this.$element.on('fileuploadadd', this._onFileAdd);

// Update our reference to this.$fileInput if it is being replaced on change
if (this.uploader.fileupload('option', 'replaceFileInput')) {
this.$element.bind('fileuploadchange', this.updateFileInput.bind(this));
}
},

updateFileInput: function (event, data) {
this.$fileInput = data.fileInputClone || data.fileInput;
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
},

/**
* Set uploader parameters.
*/
setParams: function (paramObject) {
this.base(paramObject);
this.uploader.fileupload('option', {formData: this.formData});

// Only set params if the uploader has been initialized
// It won't be if the input is disabled
if (this.uploader.data('blueimpFileupload')) {
this.uploader.fileupload('option', {formData: this.formData});
}
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
},

/**
Expand Down Expand Up @@ -128,6 +124,7 @@ Craft.Uploader = Craft.BaseUploader.extend(
autoUpload: false,
sequentialUploads: true,
maxFileSize: Craft.maxUploadSize,
replaceFileInput: false,
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
createAction: 'assets/upload',
replaceAction: 'assets/replace-file',
deleteAction: 'assets/delete-asset',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js.map

Large diffs are not rendered by default.