lots of drag&drop improvements

This commit is contained in:
Uwe Steinmann 2025-12-01 14:11:38 +01:00
parent a8e0ace046
commit 62145c2f4e
2 changed files with 452 additions and 438 deletions

View File

@ -767,7 +767,7 @@ $(document).ready( function() {
function onAddClipboard(ev) { /* {{{ */
ev.preventDefault();
var source_info = JSON.parse(ev.originalEvent.dataTransfer.getData("text"));
var source_info = JSON.parse(ev.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
@ -1004,16 +1004,7 @@ function onAddClipboard(ev) { /* {{{ */
}
}
SeedDMSUpload.handleUrlUpload = function(target_id, target_type, url, obj) {
var afterupload = obj.data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
} else {
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
SeedDMSUpload.handleUrlUpload = function(target_id, target_type, url, obj, status, afteruploadfunc) {
if(target_type == 'folder' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
@ -1040,7 +1031,6 @@ function onAddClipboard(ev) { /* {{{ */
theme: 'defaultTheme',
timeout: 1500
});
// $("div.ajax[data-action='folderList']").trigger('update', {folderid: target_id});
// if(editBtnLabel)
// status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-sm btn-primary">' + editBtnLabel + '</a>'));
if(afteruploadfunc) {
@ -1058,19 +1048,73 @@ function onAddClipboard(ev) { /* {{{ */
}
}
});
} else if(target_type == 'document' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'updateremotedocument');
fd.append('remoteurl', url);
} else if(target_type == 'attachment' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'addremotefile');
fd.append('remoteurl', url);
}
}
SeedDMSUpload.handleFileUpload = function(target_id, target_type, items,obj,statusbar) {
/* target is set for the quick upload area */
// var target_id = obj.data('target');
// var target_type = 'folder';
/* droptarget is set for folders and documents in lists */
// var droptarget = obj.data('droptarget');
// if(droptarget) {
// target_type = droptarget.split("_")[0];
// target_id = droptarget.split("_")[1];
// }
/* Upload a new file into a folder, as a new document version, or as
* a new attachment
*/
SeedDMSUpload.handleFileUpload = function(target_id, target_type, file, obj, statusbar, afteruploadfunc) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
if (target_type == "folder") {
fd.append('folderid', target_id);
fd.append('command', 'uploaddocument');
} else if (target_type == "document") {
fd.append('documentid', target_id);
fd.append('command', 'updatedocument');
} else if (target_type == "attachment") {
fd.append('documentid', target_id);
fd.append('command', 'addfile');
}
fd.append('formtoken', obj.data('uploadformtoken'));
if (typeof obj.data('comment') !== 'undefined') {
fd.append('comment', obj.data('comment'));
}
if (typeof obj.data('keywords') !== 'undefined') {
fd.append('keywords', obj.data('keywords'));
}
fd.append('userfile', file);
SeedDMSUpload.getFormData(fd, obj.data('attributes'), 'attributes');
SeedDMSUpload.getFormData(fd, obj.data('categories'), 'categories');
statusbar.parent().show();
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status,afteruploadfunc);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
}
/* Upload several files (of type FileSystemEntry) as new documents
* into a folder, or as attachments, or as a new document version.
* items may contain elements of type FileSystemFileEntry or
* FileSystemDirectoryEntry.
*/
SeedDMSUpload.handleFilesUpload = function(target_id, target_type, items, obj, statusbar) {
var afterupload = obj.data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
@ -1082,40 +1126,10 @@ function onAddClipboard(ev) { /* {{{ */
}
if(target_type == 'folder' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
if (item.isFile) {
item.file(function(file) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('folderid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
if (typeof obj.data('comment') !== 'undefined') {
fd.append('comment', obj.data('comment'));
}
if (typeof obj.data('keywords') !== 'undefined') {
fd.append('keywords', obj.data('keywords'));
}
fd.append('userfile', file);
fd.append('command', 'uploaddocument');
SeedDMSUpload.getFormData(fd, obj.data('attributes'), 'attributes');
SeedDMSUpload.getFormData(fd, obj.data('categories'), 'categories');
// fd.append('path', file.webkitRelativePath);
statusbar.parent().show();
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status,afteruploadfunc);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, afteruploadfunc);
});
} else if(item.isDirectory) {
var fd = new FormData();
@ -1131,7 +1145,7 @@ function onAddClipboard(ev) { /* {{{ */
// obj.data('afterupload', '()=>{}');
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(fid, 'folder', entries, obj, statusbar);
SeedDMSUpload.handleFilesUpload(fid, 'folder', entries, obj, statusbar);
});
}
/* Just reload the parent folder */
@ -1142,62 +1156,19 @@ function onAddClipboard(ev) { /* {{{ */
}
} else if(target_type == 'document' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
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', file);
fd.append('command', 'updatedocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status);
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, afteruploadfunc);
});
}
}
} else if(target_type == 'attachment' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
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', file);
fd.append('command', 'addfile');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status, function(){
$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});
});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, function(){$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});});
});
}
}
@ -1229,11 +1200,20 @@ $(document).ready(function() { /* {{{ */
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
var afterupload = $(this).data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
} else {
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
var items = e.originalEvent.dataTransfer.items;
newitems = [];
newsysfiles = [];
newfile = null;
if(items.length > 0) {
divupload = $(this);
/* Dropping an image from a web page will result in several items, containing
* the image as a file, the url with type text/uri-list and text/plain,
* the image tag with type text/html.
@ -1242,16 +1222,29 @@ $(document).ready(function() { /* {{{ */
// console.log('kind: '+item.kind);
// console.log('type: '+item.type);
if (item.kind === "file" && item.webkitGetAsEntry()) {
newitems.push(item.webkitGetAsEntry());
} else if (item.kind === "string" && item.type === "text/uri-list") {
item.getAsString((s) => {
console.log("string: "+s);
SeedDMSUpload.handleUrlUpload(target_id, target_type, s, divupload);
});
newsysfiles.push(item.webkitGetAsEntry());
} else if (item.kind === "file" && (f = item.getAsFile())) {
newfile = f;
}
}
if (newsysfiles.length > 0) {
SeedDMSUpload.handleFilesUpload(target_id, target_type, newsysfiles, $(this), $(this));
} else if (newfile) {
SeedDMSUpload.handleFileUpload(target_id, target_type, newfile, $(this), $(this), afteruploadfunc);
} else {
/* Do a second iteration because getAsString() seems to be aysnc */
for (const item of items) {
if (item.kind === "string" && item.type === "text/uri-list") {
item.getAsString((s) => {
try {
url = new URL(s);
SeedDMSUpload.handleUrlUpload(target_id, target_type, url.href, $(this), null, afteruploadfunc);
} catch(e) {
}
});
}
}
}
if (newitems)
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems, $(this), $(this));
}
});
@ -1280,109 +1273,123 @@ $(document).ready(function() { /* {{{ */
files = e.originalEvent.dataTransfer.files;
items = e.originalEvent.dataTransfer.items;
if(target_type == 'folder') {
/* 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());
newitems = [];
for (const item of items) {
console.log('kind: '+item.kind);
console.log('type: '+item.type);
if (item.kind === "file" && item.webkitGetAsEntry()) {
newitems.push(item.webkitGetAsEntry());
} else if (item.kind === "file" && (f=item.getAsFile())) {
// newitems.push(f);
// console.log(f);
}
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
if (newitems.length > 0) {
SeedDMSUpload.handleFilesUpload(target_id, target_type, newitems, $(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
} else {
/* The data is passed in dataTransfer. The items are meaning less. */
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
// console.log('Drop '+source_type+' '+source_id+' on '+target_type+' '+target_id);
if(source_type == 'document') {
var bootbox_message = trans.confirm_move_document;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog(bootbox_message, [{
"label" : "<i class='fa fa-remove'></i> "+trans.move_document,
"class" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movedocument', docid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-document-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}, {
"label" : trans.cancel,
"class" : "btn-cancel",
"callback": function() {
}
}]);
try {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
// console.log('Drop '+source_type+' '+source_id+' on '+target_type+' '+target_id);
if(source_type == 'document') {
var bootbox_message = trans.confirm_move_document;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog(bootbox_message, [{
"label" : "<i class='fa fa-remove'></i> "+trans.move_document,
"class" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movedocument', docid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-document-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}, {
"label" : trans.cancel,
"class" : "btn-cancel",
"callback": function() {
}
}]);
url = seeddms_webroot+"out/out.MoveDocument.php?documentid="+source_id+"&targetid="+target_id;
// document.location = url;
} else if(source_type == 'folder' && source_id != target_id) {
var bootbox_message = trans.confirm_move_folder;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog(bootbox_message, [{
"label" : "<i class='fa fa-arrow-right'></i> "+trans.move_folder,
"class" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movefolder', folderid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-folder-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}, {
"label" : trans.cancel,
"class" : "btn-cancel",
"callback": function() {
}
}]);
url = seeddms_webroot+"out/out.MoveDocument.php?documentid="+source_id+"&targetid="+target_id;
// document.location = url;
} else if(source_type == 'folder' && source_id != target_id) {
var bootbox_message = trans.confirm_move_folder;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog(bootbox_message, [{
"label" : "<i class='fa fa-arrow-right'></i> "+trans.move_folder,
"class" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movefolder', folderid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-folder-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}, {
"label" : trans.cancel,
"class" : "btn-cancel",
"callback": function() {
}
}]);
url = seeddms_webroot+"out/out.MoveFolder.php?folderid="+source_id+"&targetid="+target_id;
// document.location = url;
url = seeddms_webroot+"out/out.MoveFolder.php?folderid="+source_id+"&targetid="+target_id;
// document.location = url;
}
} catch(e) {
}
try {
url = new URL(e.originalEvent.dataTransfer.getData("text"));
console.log(url.href);
SeedDMSUpload.handleUrlUpload(target_id, target_type, url.href, $(e.currentTarget), $('div.statusbar-container h1'));
} catch(e) {
}
}
} else if(target_type == 'document') {
@ -1502,7 +1509,7 @@ $(document).ready(function() { /* {{{ */
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
SeedDMSUpload.handleFilesUpload(target_id, target_type, newitems, $(e.currentTarget), $('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
}
});
@ -1529,7 +1536,7 @@ $(document).ready(function() { /* {{{ */
timeout: 3000
});
*/
e.originalEvent.dataTransfer.setData("text", JSON.stringify(dragStartInfo));
e.originalEvent.dataTransfer.setData("text/json", JSON.stringify(dragStartInfo));
});
$(document).on('dragstart', '.table-row-document', function (e) {
@ -1542,7 +1549,7 @@ $(document).ready(function() { /* {{{ */
formtoken : $(e.target).attr('formtoken'),
name: $(e.target).data('name')+''
};
e.originalEvent.dataTransfer.setData("text", JSON.stringify(dragStartInfo));
e.originalEvent.dataTransfer.setData("text/json", JSON.stringify(dragStartInfo));
});
/* Dropping item on alert below clipboard */
@ -1591,7 +1598,7 @@ $(document).ready(function() { /* {{{ */
$(e.target).parent().css('border', '1px solid white');
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;

View File

@ -816,7 +816,7 @@ $(document).ready( function() {
function onAddClipboard(ev) { /* {{{ */
ev.preventDefault();
var source_info = JSON.parse(ev.originalEvent.dataTransfer.getData("text"));
var source_info = JSON.parse(ev.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
@ -1053,16 +1053,7 @@ function onAddClipboard(ev) { /* {{{ */
}
}
SeedDMSUpload.handleUrlUpload = function(target_id, target_type, url, obj) {
var afterupload = obj.data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
} else {
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
SeedDMSUpload.handleUrlUpload = function(target_id, target_type, url, obj, status, afteruploadfunc) {
if(target_type == 'folder' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
@ -1089,7 +1080,6 @@ function onAddClipboard(ev) { /* {{{ */
theme: 'defaultTheme',
timeout: 1500
});
// $("div.ajax[data-action='folderList']").trigger('update', {folderid: target_id});
// if(editBtnLabel)
// status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-sm btn-primary">' + editBtnLabel + '</a>'));
if(afteruploadfunc) {
@ -1107,19 +1097,73 @@ function onAddClipboard(ev) { /* {{{ */
}
}
});
} else if(target_type == 'document' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'updateremotedocument');
fd.append('remoteurl', url);
} else if(target_type == 'attachment' && target_id) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('documentid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'addremotefile');
fd.append('remoteurl', url);
}
}
SeedDMSUpload.handleFileUpload = function(target_id, target_type, items,obj,statusbar) {
/* target is set for the quick upload area */
// var target_id = obj.data('target');
// var target_type = 'folder';
/* droptarget is set for folders and documents in lists */
// var droptarget = obj.data('droptarget');
// if(droptarget) {
// target_type = droptarget.split("_")[0];
// target_id = droptarget.split("_")[1];
// }
/* Upload a new file into a folder, as a new document version, or as
* a new attachment
*/
SeedDMSUpload.handleFileUpload = function(target_id, target_type, file, obj, statusbar, afteruploadfunc) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
if (target_type == "folder") {
fd.append('folderid', target_id);
fd.append('command', 'uploaddocument');
} else if (target_type == "document") {
fd.append('documentid', target_id);
fd.append('command', 'updatedocument');
} else if (target_type == "attachment") {
fd.append('documentid', target_id);
fd.append('command', 'addfile');
}
fd.append('formtoken', obj.data('uploadformtoken'));
if (typeof obj.data('comment') !== 'undefined') {
fd.append('comment', obj.data('comment'));
}
if (typeof obj.data('keywords') !== 'undefined') {
fd.append('keywords', obj.data('keywords'));
}
fd.append('userfile', file);
SeedDMSUpload.getFormData(fd, obj.data('attributes'), 'attributes');
SeedDMSUpload.getFormData(fd, obj.data('categories'), 'categories');
statusbar.parent().show();
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status,afteruploadfunc);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
}
/* Upload several files (of type FileSystemEntry) as new documents
* into a folder, or as attachments, or as a new document version.
* items may contain elements of type FileSystemFileEntry or
* FileSystemDirectoryEntry.
*/
SeedDMSUpload.handleFilesUpload = function(target_id, target_type, items, obj, statusbar) {
var afterupload = obj.data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
@ -1131,40 +1175,10 @@ function onAddClipboard(ev) { /* {{{ */
}
if(target_type == 'folder' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
if (item.isFile) {
item.file(function(file) {
if(file.size <= maxFileSize) {
var fd = new FormData();
fd.append('targettype', target_type);
fd.append('folderid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
if (typeof obj.data('comment') !== 'undefined') {
fd.append('comment', obj.data('comment'));
}
if (typeof obj.data('keywords') !== 'undefined') {
fd.append('keywords', obj.data('keywords'));
}
fd.append('userfile', file);
fd.append('command', 'uploaddocument');
SeedDMSUpload.getFormData(fd, obj.data('attributes'), 'attributes');
SeedDMSUpload.getFormData(fd, obj.data('categories'), 'categories');
// fd.append('path', file.webkitRelativePath);
statusbar.parent().show();
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status,afteruploadfunc);
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, afteruploadfunc);
});
} else if(item.isDirectory) {
var fd = new FormData();
@ -1180,7 +1194,7 @@ function onAddClipboard(ev) { /* {{{ */
// obj.data('afterupload', '()=>{}');
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(fid, 'folder', entries, obj, statusbar);
SeedDMSUpload.handleFilesUpload(fid, 'folder', entries, obj, statusbar);
});
}
/* Just reload the parent folder */
@ -1191,62 +1205,19 @@ function onAddClipboard(ev) { /* {{{ */
}
} else if(target_type == 'document' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
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', file);
fd.append('command', 'updatedocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status);
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, afteruploadfunc);
});
}
}
} else if(target_type == 'attachment' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
var item = items[i];
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', file);
fd.append('command', 'addfile');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(file.name,file.size);
SeedDMSUpload.sendFileToServer(fd,status, function(){
$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});
});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
SeedDMSUpload.handleFileUpload(target_id, target_type, file, obj, statusbar, function(){$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});});
});
}
}
@ -1278,11 +1249,20 @@ $(document).ready(function() { /* {{{ */
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
var afterupload = $(this).data('afterupload');
if(afterupload) {
afteruploadfunc = eval(afterupload);
} else {
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
var items = e.originalEvent.dataTransfer.items;
newitems = [];
newsysfiles = [];
newfile = null;
if(items.length > 0) {
divupload = $(this);
/* Dropping an image from a web page will result in several items, containing
* the image as a file, the url with type text/uri-list and text/plain,
* the image tag with type text/html.
@ -1291,16 +1271,29 @@ $(document).ready(function() { /* {{{ */
// console.log('kind: '+item.kind);
// console.log('type: '+item.type);
if (item.kind === "file" && item.webkitGetAsEntry()) {
newitems.push(item.webkitGetAsEntry());
} else if (item.kind === "string" && item.type === "text/uri-list") {
item.getAsString((s) => {
console.log("string: "+s);
SeedDMSUpload.handleUrlUpload(target_id, target_type, s, divupload);
});
newsysfiles.push(item.webkitGetAsEntry());
} else if (item.kind === "file" && (f = item.getAsFile())) {
newfile = f;
}
}
if (newsysfiles.length > 0) {
SeedDMSUpload.handleFilesUpload(target_id, target_type, newsysfiles, $(this), $(this));
} else if (newfile) {
SeedDMSUpload.handleFileUpload(target_id, target_type, newfile, $(this), $(this), afteruploadfunc);
} else {
/* Do a second iteration because getAsString() seems to be aysnc */
for (const item of items) {
if (item.kind === "string" && item.type === "text/uri-list") {
item.getAsString((s) => {
try {
url = new URL(s);
SeedDMSUpload.handleUrlUpload(target_id, target_type, url.href, $(this), null, afteruploadfunc);
} catch(e) {
}
});
}
}
}
if (newitems)
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems, $(this), $(this));
}
});
@ -1329,121 +1322,135 @@ $(document).ready(function() { /* {{{ */
files = e.originalEvent.dataTransfer.files;
items = e.originalEvent.dataTransfer.items;
if(target_type == 'folder') {
/* 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());
newitems = [];
for (const item of items) {
console.log('kind: '+item.kind);
console.log('type: '+item.type);
if (item.kind === "file" && item.webkitGetAsEntry()) {
newitems.push(item.webkitGetAsEntry());
} else if (item.kind === "file" && (f=item.getAsFile())) {
// newitems.push(f);
// console.log(f);
}
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
if (newitems.length > 0) {
SeedDMSUpload.handleFilesUpload(target_id, target_type, newitems, $(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
} else {
/* The data is passed in dataTransfer. The items are meaning less. */
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
// console.log('Drop '+source_type+' '+source_id+' on '+target_type+' '+target_id);
if(source_type == 'document') {
var bootbox_message = trans.confirm_move_document;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog({
"message" : bootbox_message,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"move" : {
"label" : "<i class='fa fa-remove'></i> "+trans.move_document,
"className" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movedocument', docid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-document-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
try {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
// console.log('Drop '+source_type+' '+source_id+' on '+target_type+' '+target_id);
if(source_type == 'document') {
var bootbox_message = trans.confirm_move_document;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog({
"message" : bootbox_message,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"move" : {
"label" : "<i class='fa fa-remove'></i> "+trans.move_document,
"className" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movedocument', docid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-document-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}
}
}
});
});
url = seeddms_webroot+"out/out.MoveDocument.php?documentid="+source_id+"&targetid="+target_id;
// document.location = url;
} else if(source_type == 'folder' && source_id != target_id) {
var bootbox_message = trans.confirm_move_folder;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog({
"message" : bootbox_message,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"move" : {
"label" : "<i class='fa fa-arrow-right'></i> "+trans.move_folder,
"className" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movefolder', folderid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-folder-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
url = seeddms_webroot+"out/out.MoveDocument.php?documentid="+source_id+"&targetid="+target_id;
// document.location = url;
} else if(source_type == 'folder' && source_id != target_id) {
var bootbox_message = trans.confirm_move_folder;
if(source_info.name)
bootbox_message += "<p> "+escapeHtml(source_info.name)+' <i class="fa fa-arrow-right"></i> '+escapeHtml(target_name)+"</p>";
bootbox.dialog({
"message" : bootbox_message,
"buttons" : {
"cancel" : {
"label" : trans.cancel,
"className" : "btn-secondary",
"callback": function() {
}
},
"move" : {
"label" : "<i class='fa fa-arrow-right'></i> "+trans.move_folder,
"className" : "btn-danger",
"callback": function() {
$.get(seeddms_webroot+'op/op.Ajax.php',
{ command: 'movefolder', folderid: source_id, targetfolderid: target_id, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-folder-'+source_id).hide('slow');
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
},
'json'
);
}
}
}
}
});
});
url = seeddms_webroot+"out/out.MoveFolder.php?folderid="+source_id+"&targetid="+target_id;
// document.location = url;
url = seeddms_webroot+"out/out.MoveFolder.php?folderid="+source_id+"&targetid="+target_id;
// document.location = url;
}
} catch(e) {
}
try {
url = new URL(e.originalEvent.dataTransfer.getData("text"));
console.log(url.href);
SeedDMSUpload.handleUrlUpload(target_id, target_type, url.href, $(e.currentTarget), $('div.statusbar-container h1'));
} catch(e) {
}
}
} else if(target_type == 'document') {
@ -1477,14 +1484,14 @@ $(document).ready(function() { /* {{{ */
"label" : "<i class='fa fa-link'></i> "+trans.upload_new_version,
"className" : "btn-danger",
"callback": function() {
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1'));
SeedDMSUpload.handleFilesUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1'));
}
}
}
});
}
} else {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;
@ -1576,7 +1583,7 @@ $(document).ready(function() { /* {{{ */
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
SeedDMSUpload.handleFileUpload(target_id, target_type, newitems,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
SeedDMSUpload.handleFilesUpload(target_id, target_type, newitems, $(e.currentTarget), $('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
}
});
@ -1603,7 +1610,7 @@ $(document).ready(function() { /* {{{ */
timeout: 3000
});
*/
e.originalEvent.dataTransfer.setData("text", JSON.stringify(dragStartInfo));
e.originalEvent.dataTransfer.setData("text/json", JSON.stringify(dragStartInfo));
});
$(document).on('dragstart', '.table-row-document', function (e) {
@ -1616,7 +1623,7 @@ $(document).ready(function() { /* {{{ */
formtoken : $(e.target).attr('formtoken'),
name: $(e.target).data('name')+''
};
e.originalEvent.dataTransfer.setData("text", JSON.stringify(dragStartInfo));
e.originalEvent.dataTransfer.setData("text/json", JSON.stringify(dragStartInfo));
});
/* Dropping item on alert below clipboard */
@ -1665,7 +1672,7 @@ $(document).ready(function() { /* {{{ */
$(e.target).parent().css('border', '1px solid white');
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text/json"));
source_type = source_info.type;
source_id = source_info.id;
formtoken = source_info.formtoken;