add support for updating a document by dropping a file on a document, folder hierarchies can be uploaded by drag&drop

This commit is contained in:
Uwe Steinmann 2024-03-06 16:32:23 +01:00
parent 5d548bafcb
commit 484a95029c
2 changed files with 152 additions and 102 deletions

View File

@ -697,8 +697,6 @@ function onAddClipboard(ev) { /* {{{ */
// function sendFileToServer(formData,status,callback) {
SeedDMSUpload.sendFileToServer = function(formData,status,callback) {
var uploadURL = ajaxurl; //Upload URL
var extraData ={}; //Extra Data.
var jqXHR=$.ajax({
xhr: function() {
var xhrobj = $.ajaxSettings.xhr();
@ -716,7 +714,7 @@ function onAddClipboard(ev) { /* {{{ */
}
return xhrobj;
},
url: uploadURL,
url: ajaxurl,
type: "POST",
contentType: false,
dataType:"json",
@ -755,6 +753,43 @@ function onAddClipboard(ev) { /* {{{ */
status.setAbort(jqXHR);
}
SeedDMSUpload.addSubFolder = function(formData) {
var ret = false;
$.ajax({
url: ajaxurl,
type: "POST",
contentType: false,
dataType:"json",
processData: false,
cache: false,
async: false,
data: formData,
success: function(data, textStatus) {
if(data.success) {
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
ret = data.data;
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
}
});
return ret;
}
//function createStatusbar(obj) {
SeedDMSUpload.createStatusbar = function(obj) {
rowCount++;
@ -839,7 +874,7 @@ function onAddClipboard(ev) { /* {{{ */
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
}
if(target_type == 'folder' && target_id) {
for (var i = 0; i < items.length; i++) {
@ -879,24 +914,29 @@ function onAddClipboard(ev) { /* {{{ */
}
});
} else if(item.isDirectory) {
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(entries, obj, statusbar);
});
/*
noty({
text: 'Folders currently not supported',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
*/
var fd = new FormData();
fd.append('folderid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'addfolder');
fd.append('name', item.name);
var fid = SeedDMSUpload.addSubFolder(fd);
if(fid) {
obj.data('target', fid);
obj.data('droptarget', 'folder_'+fid);
/* Set void afterupload to prevent tons of noty messages */
obj.data('afterupload', '()=>{}');
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(entries, obj, statusbar);
});
}
/* Just reload the parent folder */
if(target_id == seeddms_folder) {
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
}
} else if(target_type == 'document' && target_id) {
/*
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
if (item.isFile) {
@ -906,15 +946,16 @@ function onAddClipboard(ev) { /* {{{ */
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');
fd.append('userfile', file);
fd.append('command', 'updatedocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
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>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
@ -925,7 +966,6 @@ function onAddClipboard(ev) { /* {{{ */
});
}
}
*/
} else if(target_type == 'attachment' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
@ -1012,9 +1052,9 @@ $(document).ready(function() { /* {{{ */
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
target_name = $(e.currentTarget).data('name')+''; // Force this to be a string
files = e.originalEvent.dataTransfer.files;
items = e.originalEvent.dataTransfer.items;
if(target_type == 'folder') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
/* 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);
@ -1121,8 +1161,6 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'document') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
/* 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);
@ -1135,37 +1173,23 @@ $(document).ready(function() { /* {{{ */
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'));
*/
}
}
}
});
} else if(1) {
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")*/);
bootbox.dialog(trans.confirm_upload_new_version, [{
"label" : "<i class='fa fa-arrow-right'></i> "+trans.upload_new_version,
"class" : "btn-danger",
"callback": function() {
SeedDMSUpload.handleFileUpload(newitems,$(e.currentTarget),$('div.statusbar-container h1'));
}
}, {
"label" : trans.cancel,
"class" : "btn-cancel",
"callback": function() {
}
}]);
}
} else {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
@ -1248,8 +1272,6 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'attachment') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
if(files.length > 0) {
newitems = [];
for (var i=0; i<items.length; i++) {
@ -1544,7 +1566,7 @@ $(document).ready(function() { /* {{{ */
}( window.SeedDMSAjax = window.SeedDMSAjax || {}, jQuery )); /* }}} */
(function( SeedDMSBox, $, undefined ) { /* {{{ */
/* Open dialog box and
/* Open confirm box (which has just one callback) and
* redirect to the given url if confirm was pressed
*/
SeedDMSBox.redirect = function(url, boxparams) {
@ -1562,7 +1584,7 @@ $(document).ready(function() { /* {{{ */
}]);
}
/* Open confirm box and
/* Open confirm box (which has just one callback) and
* calls the callback if the confirm button was pressed
*/
SeedDMSBox.callback = function(callback, boxparams) {

View File

@ -743,8 +743,6 @@ function onAddClipboard(ev) { /* {{{ */
// function sendFileToServer(formData,status,callback) {
SeedDMSUpload.sendFileToServer = function(formData,status,callback) {
var uploadURL = ajaxurl; //Upload URL
var extraData ={}; //Extra Data.
var jqXHR=$.ajax({
xhr: function() {
var xhrobj = $.ajaxSettings.xhr();
@ -762,7 +760,7 @@ function onAddClipboard(ev) { /* {{{ */
}
return xhrobj;
},
url: uploadURL,
url: ajaxurl,
type: "POST",
contentType: false,
dataType:"json",
@ -801,6 +799,43 @@ function onAddClipboard(ev) { /* {{{ */
status.setAbort(jqXHR);
}
SeedDMSUpload.addSubFolder = function(formData) {
var ret = false;
$.ajax({
url: ajaxurl,
type: "POST",
contentType: false,
dataType:"json",
processData: false,
cache: false,
async: false,
data: formData,
success: function(data, textStatus) {
if(data.success) {
noty({
text: data.message,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500
});
ret = data.data;
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500
});
}
}
});
return ret;
}
//function createStatusbar(obj) {
SeedDMSUpload.createStatusbar = function(obj) {
rowCount++;
@ -885,7 +920,7 @@ function onAddClipboard(ev) { /* {{{ */
afteruploadfunc = function() {
if(target_id == seeddms_folder)
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
}
if(target_type == 'folder' && target_id) {
for (var i = 0; i < items.length; i++) {
@ -925,24 +960,29 @@ function onAddClipboard(ev) { /* {{{ */
}
});
} else if(item.isDirectory) {
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(entries, obj, statusbar);
});
/*
noty({
text: 'Folders currently not supported',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
*/
var fd = new FormData();
fd.append('folderid', target_id);
fd.append('formtoken', obj.data('uploadformtoken'));
fd.append('command', 'addfolder');
fd.append('name', item.name);
var fid = SeedDMSUpload.addSubFolder(fd);
if(fid) {
obj.data('target', fid);
obj.data('droptarget', 'folder_'+fid);
/* Set void afterupload to prevent tons of noty messages */
obj.data('afterupload', '()=>{}');
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
SeedDMSUpload.handleFileUpload(entries, obj, statusbar);
});
}
/* Just reload the parent folder */
if(target_id == seeddms_folder) {
$("div.ajax[data-action='folderList']").trigger('update', {folderid: seeddms_folder});
}
}
}
} else if(target_type == 'document' && target_id) {
/*
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
if (item.isFile) {
@ -952,15 +992,16 @@ function onAddClipboard(ev) { /* {{{ */
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');
fd.append('userfile', file);
fd.append('command', 'updatedocument');
var status = new SeedDMSUpload.createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
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>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
text: maxFileSizeMsg + '<br /><em>' + file.name + ' (' + file.size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
@ -971,7 +1012,6 @@ function onAddClipboard(ev) { /* {{{ */
});
}
}
*/
} else if(target_type == 'attachment' && target_id) {
for (var i = 0; i < items.length; i++) {
var item = items[i]; //.webkitGetAsEntry();
@ -1058,9 +1098,9 @@ $(document).ready(function() { /* {{{ */
target_type = attr_rel.split("_")[0];
target_id = attr_rel.split("_")[1];
target_name = $(e.currentTarget).data('name')+''; // Force this to be a string
files = e.originalEvent.dataTransfer.files;
items = e.originalEvent.dataTransfer.items;
if(target_type == 'folder') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
/* 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);
@ -1179,8 +1219,6 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'document') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
/* 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);
@ -1193,7 +1231,11 @@ $(document).ready(function() { /* {{{ */
theme: 'defaultTheme',
timeout: 5000
});
} else if(0) {
} else if(1) {
newitems = [];
for (var i=0; i<items.length; i++) {
newitems.push(items[i].webkitGetAsEntry());
}
bootbox.dialog({
"message" : trans.confirm_upload_new_version,
"buttons" : {
@ -1207,23 +1249,11 @@ $(document).ready(function() { /* {{{ */
"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")*/);
}
} else {
var source_info = JSON.parse(e.originalEvent.dataTransfer.getData("text"));
@ -1313,8 +1343,6 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'attachment') {
var files = e.originalEvent.dataTransfer.files;
var items = e.originalEvent.dataTransfer.items;
if(files.length > 0) {
newitems = [];
for (var i=0; i<items.length; i++) {