Do not allow upload of invalid images to gallery

no issue
- added `onUploadStart` action to `{{gh-uploader}}` that is triggered when individual files start uploading
  - will not be triggered for any files that fail client-side validation
- changed `{{koenig-card-gallery}}` to only add images to the local gallery display when the uploader starts an upload
This commit is contained in:
Kevin Ansfield 2018-08-31 12:01:08 +01:00
parent a11ccccae0
commit bfe985abe2
3 changed files with 13 additions and 12 deletions

View File

@ -70,6 +70,7 @@ export default Component.extend({
onComplete() {},
onFailed() {},
onStart() {},
onUploadStart() {},
onUploadFailure() {},
onUploadSuccess() {},
@ -212,6 +213,8 @@ export default Component.extend({
let url = `${ghostPaths().apiRoot}${this.get('uploadUrl')}`;
try {
this.onUploadStart(file);
let response = yield ajax.post(url, {
data: formData,
processData: false,

View File

@ -117,6 +117,15 @@ export default Component.extend({
},
actions: {
addImage(file) {
let count = this.images.length + 1;
let row = Math.ceil(count / MAX_PER_ROW) - 1;
let image = this._readDataFromImageFile(file);
image.row = row;
this.images.pushObject(image);
},
setImageSrc(uploadResult) {
let image = this.images.findBy('fileName', uploadResult.fileName);
@ -212,18 +221,6 @@ export default Component.extend({
this.set('errorMessage', 'Galleries are limited to 9 images');
}
this.set('files', strippedFiles);
let count = this.images.length;
let row = Math.ceil(count / MAX_PER_ROW) - 1;
strippedFiles.forEach((file) => {
count = count + 1;
row = Math.ceil(count / MAX_PER_ROW) - 1;
let image = this._readDataFromImageFile(file);
image.row = row;
this.images.pushObject(image);
});
},
_readDataFromImageFile(file) {

View File

@ -18,6 +18,7 @@
files=files
accept=imageMimeTypes
extensions=imageExtensions
onUploadStart=(action "addImage")
onUploadSuccess=(action "setImageSrc")
onUploadFailure=(action "uploadFailed")
as |uploader|