initial code to support dropping of files on a document

This commit is contained in:
Uwe Steinmann 2023-09-07 15:50:33 +02:00
parent 754a601e73
commit 9493d5e185
2 changed files with 128 additions and 46 deletions

View File

@ -894,26 +894,31 @@ function onAddClipboard(ev) { /* {{{ */
}
} else if(target_type == 'document' && target_id) {
/*
for (var i = 0; i < files.length; i++) {
if(files[i].size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('userfile', files[i]);
fd.append('command', 'uploaddocument');
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
if (item.isFile) {
item.file(function(file) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('userfile', files[i]);
fd.append('command', 'uploaddocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
SeedDMSUpload.sendFileToServer(fd,status);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
SeedDMSUpload.sendFileToServer(fd,status);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
});
}
}
@ -1118,11 +1123,47 @@ $(document).ready(function() { /* {{{ */
/* check for files, because items has an entry if no file was dropped */
if(files.length > 0) {
// console.log('Drop '+files.length+' files on '+target_type+' '+target_id);
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
if(files.length > 1) {
noty({
text: trans.must_drop_one_file,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
} else if(0) {
bootbox.dialog({
"message" : trans.confirm_upload_new_version,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"newversion" : {
"label" : "<i class='fa fa-link'></i> "+trans.upload_new_version,
"className" : "btn-danger",
"callback": function() {
console.log('Hallo');
/*
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1'));
*/
}
}
}
});
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
} else {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
source_type = source_info.type;

View File

@ -925,26 +925,31 @@ function onAddClipboard(ev) { /* {{{ */
}
} else if(target_type == 'document' && target_id) {
/*
for (var i = 0; i < files.length; i++) {
if(files[i].size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('userfile', files[i]);
fd.append('command', 'uploaddocument');
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
if (item.isFile) {
item.file(function(file) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('userfile', files[i]);
fd.append('command', 'uploaddocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
SeedDMSUpload.sendFileToServer(fd,status);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
SeedDMSUpload.sendFileToServer(fd,status);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
});
}
}
@ -1161,11 +1166,47 @@ $(document).ready(function() { /* {{{ */
/* check for files, because items has an entry if no file was dropped */
if(files.length > 0) {
// console.log('Drop '+files.length+' files on '+target_type+' '+target_id);
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
if(files.length > 1) {
noty({
text: trans.must_drop_one_file,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
} else if(0) {
bootbox.dialog({
"message" : trans.confirm_upload_new_version,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"newversion" : {
"label" : "<i class='fa fa-link'></i> "+trans.upload_new_version,
"className" : "btn-danger",
"callback": function() {
console.log('Hallo');
/*
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1'));
*/
}
}
}
});
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
} else {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
source_type = source_info.type;