mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-05-07 13:45:56 +02:00
Added logic to support custom post data for file upload / file session remove
This commit is contained in:
@@ -106,6 +106,7 @@ export default class FilesField {
|
||||
if (!this.container.length) { return; }
|
||||
|
||||
this.urls = {};
|
||||
this.customPost = this.container.data('filePostAdd') || {};
|
||||
this.options = Object.assign({}, Dictionary, DropzoneMediaConfig, {
|
||||
klass: this,
|
||||
url: this.container.data('file-url-add') || config.current_url,
|
||||
@@ -158,7 +159,6 @@ export default class FilesField {
|
||||
dropzone.files.push(mock);
|
||||
dropzone.options.addedfile.call(dropzone, mock);
|
||||
if (mock.type.match(/^image\//)) {
|
||||
console.log('mock');
|
||||
dropzone.options.thumbnail.call(dropzone, mock, data.path);
|
||||
dropzone.createThumbnailFromUrl(mock, data.path);
|
||||
}
|
||||
@@ -174,10 +174,17 @@ export default class FilesField {
|
||||
}
|
||||
|
||||
onDropzoneSending(file, xhr, formData) {
|
||||
formData.append('name', this.options.dotNotation);
|
||||
if (Object.keys(this.customPost).length) {
|
||||
Object.keys(this.customPost).forEach((key) => {
|
||||
formData.append(key, this.customPost[key]);
|
||||
});
|
||||
} else {
|
||||
formData.append('name', this.options.dotNotation);
|
||||
formData.append('task', 'filesupload');
|
||||
formData.append('uri', this.getURI());
|
||||
}
|
||||
|
||||
formData.append('admin-nonce', config.admin_nonce);
|
||||
formData.append('task', 'filesupload');
|
||||
formData.append('uri', this.getURI());
|
||||
}
|
||||
|
||||
onDropzoneSuccess(file, response, xhr) {
|
||||
@@ -197,7 +204,6 @@ export default class FilesField {
|
||||
input.val(value + ' ');
|
||||
}
|
||||
|
||||
console.log(file.previewElement);
|
||||
$(file.previewElement).find('[data-dz-unset]').css('display', null);
|
||||
|
||||
return this.handleError({
|
||||
@@ -246,6 +252,17 @@ export default class FilesField {
|
||||
body.session = file.sessionParams;
|
||||
}
|
||||
|
||||
const customPost = this.container.data('filePostRemove') || {};
|
||||
if (Object.keys(customPost).length) {
|
||||
body = {};
|
||||
Object.keys(customPost).forEach((key) => {
|
||||
body[key] = customPost[key];
|
||||
});
|
||||
}
|
||||
|
||||
body['filename'] = file.name;
|
||||
body['admin-nonce'] = config.admin_nonce;
|
||||
|
||||
request(url, { method: 'post', body }, () => {
|
||||
if (!path) { return; }
|
||||
|
||||
|
||||
20
themes/grav/js/admin.min.js
vendored
20
themes/grav/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user