mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-08 17:13:56 +00:00
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:
parent
89d9f7a6ed
commit
228262bf70
@ -9,9 +9,7 @@
|
|||||||
CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
||||||
|
|
||||||
var lang = editor.lang.image2;
|
var lang = editor.lang.image2;
|
||||||
console.log(editor.lang);
|
4
|
||||||
console.log(lang.btnUpload);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
// Basic properties of the dialog window: title, minimum size.
|
// Basic properties of the dialog window: title, minimum size.
|
||||||
@ -46,6 +44,13 @@ CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
|||||||
// grab the file(s) from the file input tag and upload it using AJAX
|
// grab the file(s) from the file input tag and upload it using AJAX
|
||||||
var dialog = this.getDialog();
|
var dialog = this.getDialog();
|
||||||
var files = dialog.getContentElement("Upload", "upload").getInputElement().$.files;
|
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();
|
var formData = new FormData();
|
||||||
formData.append('drop-count', files.length); // number of files being uploaded
|
formData.append('drop-count', files.length); // number of files being uploaded
|
||||||
formData.append('acmd', "Upload"); // Command for the server to recognize this as an ajax upload
|
formData.append('acmd', "Upload"); // Command for the server to recognize this as an ajax upload
|
||||||
@ -70,7 +75,7 @@ CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
|||||||
if (evt.lengthComputable) {
|
if (evt.lengthComputable) {
|
||||||
var percentComplete = evt.loaded / evt.total;
|
var percentComplete = evt.loaded / evt.total;
|
||||||
//Do something with upload progress
|
//Do something with upload progress
|
||||||
// console.log(percentComplete);
|
console.log(percentComplete);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
@ -82,7 +87,11 @@ CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
|||||||
url: URL,
|
url: URL,
|
||||||
data: formData,
|
data: formData,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
if(data.attachments[0]) { // check if we have the correct response
|
||||||
dialog.getContentElement( 'Upload', 'src' ).setValue( data.attachments[0].fullName );
|
dialog.getContentElement( 'Upload', 'src' ).setValue( data.attachments[0].fullName );
|
||||||
|
} else {
|
||||||
|
console.log("Data returned is not json...");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fail: function() {
|
fail: function() {
|
||||||
console.log("error");
|
console.log("error");
|
||||||
@ -119,9 +128,6 @@ CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
|
|||||||
onOk: function() {
|
onOk: function() {
|
||||||
var dialog = this;
|
var dialog = this;
|
||||||
|
|
||||||
console.log(dialog.getValueOf( 'Upload', 'src' ));
|
|
||||||
console.log(dialog.getValueOf( 'Upload', 'name' ));
|
|
||||||
|
|
||||||
var file = editor.document.createElement( 'a' );
|
var file = editor.document.createElement( 'a' );
|
||||||
file.setAttribute( 'href', dialog.getValueOf( 'Upload', 'src' ) );
|
file.setAttribute( 'href', dialog.getValueOf( 'Upload', 'src' ) );
|
||||||
file.setText( dialog.getValueOf( 'Upload', 'name' ) );
|
file.setText( dialog.getValueOf( 'Upload', 'name' ) );
|
||||||
|
|||||||
@ -545,6 +545,13 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
|
|||||||
// grab the file(s) from the file input tag and upload it using AJAX
|
// grab the file(s) from the file input tag and upload it using AJAX
|
||||||
var dialog = this.getDialog();
|
var dialog = this.getDialog();
|
||||||
var files = dialog.getContentElement("Upload", "upload").getInputElement().$.files;
|
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();
|
var formData = new FormData();
|
||||||
formData.append('drop-count', files.length); // number of files being uploaded
|
formData.append('drop-count', files.length); // number of files being uploaded
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
@ -578,7 +585,11 @@ CKEDITOR.dialog.add( 'image2', function( editor ) {
|
|||||||
url: URL,
|
url: URL,
|
||||||
data: formData,
|
data: formData,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
if(data.attachments) { // check if we have the correct response
|
||||||
dialog.getContentElement( 'info', 'src' ).setValue( data.attachments[0].fullName );
|
dialog.getContentElement( 'info', 'src' ).setValue( data.attachments[0].fullName );
|
||||||
|
} else {
|
||||||
|
console.log("Data returned is not json...");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fail: function() {
|
fail: function() {
|
||||||
console.log("error");
|
console.log("error");
|
||||||
|
|||||||
@ -30,8 +30,8 @@ $(document).ready(function() {
|
|||||||
var dialogDefinition = ev.data.definition;
|
var dialogDefinition = ev.data.definition;
|
||||||
|
|
||||||
// Check if the definition is from the dialog we're
|
// Check if the definition is from the dialog we're
|
||||||
// interested in (the 'image2' and 'fileupload' dialog).
|
// interested in (the 'image2' and 'fileuploadDialog' dialog).
|
||||||
if ( dialogName == 'image2' || dialogName == 'fileupload') {
|
if ( dialogName == 'image2' || dialogName == 'fileuploadDialog') {
|
||||||
|
|
||||||
var dialogObj = dialogDefinition.dialog;
|
var dialogObj = dialogDefinition.dialog;
|
||||||
dialogObj.on("show", function() {
|
dialogObj.on("show", function() {
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user