Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit e46a46f

Browse files
dazornilinkesch
authored andcommitted
Ability to add upload failed callback to options (#377)
1 parent 885d357 commit e46a46f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spec/images.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,34 @@ describe('Images addon', function () {
463463
files: [{ type: 'image/jpeg', size: 1001 }]
464464
});
465465
});
466+
467+
it('calls callback function after failing upload', function (done) {
468+
this.addon.options.fileUploadOptions.maxFileSize = 1000;
469+
this.addon.options.uploadFailed = function () {
470+
expect(true).toBe(true);
471+
done();
472+
};
473+
474+
this.$el.find('p').click();
475+
476+
this.addon.uploadAdd(null, {
477+
files: [{type: 'image/jpeg', size: 1001}]
478+
});
479+
});
480+
481+
it('show alert if callback is no function', function (done) {
482+
this.addon.options.fileUploadOptions.maxFileSize = 1000;
483+
this.addon.options.uploadFailed = "string";
484+
485+
spyOn(window, 'alert').and.callFake(function (text) {
486+
expect(text).not.toBe(null);
487+
done();
488+
});
489+
490+
this.$el.find('p').click();
491+
492+
this.addon.uploadAdd(null, {
493+
files: [{type: 'image/jpeg', size: 1001}]
494+
});
495+
});
466496
});

src/js/images.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
acceptFileTypesError: 'This file is not in a supported format: ',
7474
maxFileSizeError: 'This file is too big: '
7575
}
76+
// uploadError: function($el, data) {}
7677
// uploadCompleted: function ($el, data) {}
7778
};
7879

@@ -249,7 +250,14 @@
249250
uploadErrors.push(this.options.messages.maxFileSizeError + file.name);
250251
}
251252
if (uploadErrors.length > 0) {
253+
if (this.options.uploadFailed && typeof this.options.uploadFailed === "function") {
254+
this.options.uploadFailed(uploadErrors, data);
255+
256+
return;
257+
}
258+
252259
alert(uploadErrors.join("\n"));
260+
253261
return;
254262
}
255263

0 commit comments

Comments
 (0)