mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
09a97779b2
refs https://github.com/TryGhost/Team/issues/1320 - fixed event handling in `gh-file-input` for test-initiated uploads - added `POST /members/upload/` API mock that emulates uploading a single member - it's enough for this particular test and can be expanded as needed - added acceptance test that does a simple 1-member, no Stripe, CSV upload with no mapping changes
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import XFileInput from 'emberx-file-input/components/x-file-input';
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
// TODO: remove this override and use {{x-file-input}} directly once we've
|
|
// upgraded to emberx-file-input@1.2.0
|
|
|
|
@classic
|
|
export default class GhFileInput extends XFileInput {
|
|
didInsertElement() {
|
|
super.didInsertElement(...arguments);
|
|
this.onInsert?.(this.element.querySelector('input[type="file"]'));
|
|
}
|
|
|
|
change(e) {
|
|
let action = this.action;
|
|
let files = this.files(e);
|
|
|
|
if (files.length && action) {
|
|
action(files, this.resetInput.bind(this));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets files from event object.
|
|
*
|
|
* @method
|
|
* @private
|
|
* @param {$.Event || Event}
|
|
*/
|
|
files(e) {
|
|
return (e.originalEvent || e).testingFiles || e.originalEvent?.files || e.target.files;
|
|
}
|
|
|
|
/**
|
|
* Resets the value of the input so you can select the same file
|
|
* multiple times.
|
|
*
|
|
* NOTE: fixes reset in Firefox which doesn't reset like other browsers
|
|
* when doing input.value = null;
|
|
*
|
|
* @method
|
|
*/
|
|
resetInput() {
|
|
let input = this.element.querySelector('.x-file--input');
|
|
input.removeAttribute('value');
|
|
input.value = null;
|
|
|
|
const clone = input.cloneNode(true);
|
|
input.parentNode.replaceChild(clone, input);
|
|
|
|
return clone;
|
|
}
|
|
}
|