Fixed a few bugs regarding sending empty responses. If no file is selected for upload an alert will appeart to notify the user.

This commit is contained in:
Dario Milicic
2014-08-11 11:19:47 +02:00
parent 89d9f7a6ed
commit 228262bf70
4 changed files with 28 additions and 11 deletions
@@ -545,6 +545,13 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
// grab the file(s) from the file input tag and upload it using AJAX
var dialog = this.getDialog();
var files = dialog.getContentElement("Upload", "upload").getInputElement().$.files;
// no files were selected
if(files.length == 0) {
alert("Please select a file!");
return false;
}
var formData = new FormData();
formData.append('drop-count', files.length); // number of files being uploaded
for (var i = 0; i < files.length; i++) {
@@ -578,7 +585,11 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
url: URL,
data: formData,
success: function(data) {
dialog.getContentElement( 'info', 'src' ).setValue( data.attachments[0].fullName );
if(data.attachments) { // check if we have the correct response
dialog.getContentElement( 'info', 'src' ).setValue( data.attachments[0].fullName );
} else {
console.log("Data returned is not json...");
}
},
fail: function() {
console.log("error");