add support for drag and drop of attachments

This commit is contained in:
Uwe Steinmann 2021-07-16 16:03:34 +02:00
parent 9c66a9350a
commit a113649be3
4 changed files with 192 additions and 92 deletions

View File

@ -70,6 +70,7 @@ if($view) {
$view->setParam('document', $document);
$view->setParam('accessobject', $accessop);
$view->setParam('viewonlinefiletypes', $settings->_viewOnlineFileTypes);
$view->setParam('enableDropUpload', $settings->_enableDropUpload);
$view->setParam('enableownerrevapp', $settings->_enableOwnerRevApp);
$view->setParam('enableremoverevapp', $settings->_enableRemoveRevApp);
$view->setParam('cachedir', $settings->_cacheDir);

View File

@ -177,6 +177,8 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Theme_Style {
$dms = $this->params['dms'];
$user = $this->params['user'];
$document = $this->params['document'];
$enableDropUpload = $this->params['enableDropUpload'];
$maxuploadsize = $this->params['maxuploadsize'];
header('Content-Type: application/javascript; charset=UTF-8');
parent::jsTranslations(array('js_form_error', 'js_form_errors', 'cancel', 'splash_move_document', 'confirm_move_document', 'move_document', 'confirm_transfer_link_document', 'transfer_content', 'link_document', 'splash_move_folder', 'confirm_move_folder', 'move_folder'));
@ -189,6 +191,17 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Theme_Style {
$this->printDeleteDocumentButtonJs();
/* Add js for catching click on document in one page mode */
$this->printClickDocumentJs();
if ($enableDropUpload && $document->getAccessMode($user) >= M_READWRITE) {
echo "SeedDMSUpload.setUrl('".$this->params['settings']->_httpRoot."op/op.Ajax.php');";
echo "SeedDMSUpload.setAbortBtnLabel('".getMLText("cancel")."');";
echo "SeedDMSUpload.setEditBtnLabel('');";
$mus2 = SeedDMS_Core_File::parse_filesize(ini_get("upload_max_filesize"));
if($maxuploadsize && $maxuploadsize < $mus2)
echo "SeedDMSUpload.setMaxFileSize($maxuploadsize);\n";
else
echo "SeedDMSUpload.setMaxFileSize($mus2);\n";
echo "SeedDMSUpload.setMaxFileSizeMsg('".getMLText("uploading_maxsize")."');";
}
?>
$(document).ready( function() {
$("#form1").validate({
@ -206,6 +219,111 @@ $(document).ready( function() {
<?php
} /* }}} */
function documentFiles() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$document = $this->params['document'];
$accessobject = $this->params['accessobject'];
$viewonlinefiletypes = $this->params['viewonlinefiletypes'];
$cachedir = $this->params['cachedir'];
$previewwidthdetail = $this->params['previewWidthDetail'];
$previewconverters = $this->params['previewConverters'];
$timeout = $this->params['timeout'];
$xsendfile = $this->params['xsendfile'];
$documentid = $document->getId();
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile);
$previewer->setConverters($previewconverters);
$latestContent = $this->callHook('documentLatestContent', $document);
if($latestContent === null)
$latestContent = $document->getLatestContent();
$files = $document->getDocumentFiles($latestContent->getVersion());
$files = SeedDMS_Core_DMS::filterDocumentFiles($user, $files);
if (count($files) > 0) {
print "<table class=\"table\">";
print "<thead>\n<tr>\n";
print "<th width='20%'></th>\n";
print "<th width='20%'>".getMLText("file")."</th>\n";
print "<th width='40%'>".getMLText("comment")."</th>\n";
print "<th width='20%'></th>\n";
print "</tr>\n</thead>\n<tbody>\n";
foreach($files as $file) {
$file_exists=file_exists($dms->contentDir . $file->getPath());
$responsibleUser = $file->getUser();
print "<tr>";
print "<td>";
$previewer->createPreview($file, $previewwidthdetail);
if($file_exists) {
if ($viewonlinefiletypes && (in_array(strtolower($file->getFileType()), $viewonlinefiletypes) || in_array(strtolower($file->getMimeType()), $viewonlinefiletypes))) {
if($accessobject->check_controller_access('ViewOnline', array('action'=>'run'))) {
print "<a target=\"_blank\" href=\"".$this->params['settings']->_httpRoot."op/op.ViewOnline.php?documentid=".$documentid."&file=". $file->getID()."\">";
}
} else {
if($accessobject->check_controller_access('Download', array('action'=>'file'))) {
print "<a href=\"".$this->params['settings']->_httpRoot."op/op.Download.php?documentid=".$documentid."&file=".$file->getID()."\">";
}
}
}
if($previewer->hasPreview($file)) {
print("<img class=\"mimeicon\" width=\"".$previewwidthdetail."\" src=\"".$this->params['settings']->_httpRoot."op/op.Preview.php?documentid=".$document->getID()."&file=".$file->getID()."&width=".$previewwidthdetail."\" title=\"".htmlspecialchars($file->getMimeType())."\">");
} else {
print "<img class=\"mimeicon\" width=\"".$previewwidthdetail."\" src=\"".$this->getMimeIcon($file->getFileType())."\" title=\"".htmlspecialchars($file->getMimeType())."\">";
}
if($file_exists) {
if($accessobject->check_controller_access('Download', array('action'=>'run')) || $accessobject->check_controller_access('ViewOnline', array('action'=>'run')))
print "</a>";
}
print "</td>";
print "<td><ul class=\"actions unstyled\">\n";
print "<li>".htmlspecialchars($file->getName())."</li>\n";
if($file->getName() != $file->getOriginalFileName())
print "<li>".htmlspecialchars($file->getOriginalFileName())."</li>\n";
if ($file_exists)
print "<li>".SeedDMS_Core_File::format_filesize(filesize($dms->contentDir . $file->getPath())) ." bytes, ".htmlspecialchars($file->getMimeType())."</li>";
else print "<li>".htmlspecialchars($file->getMimeType())." - <span class=\"warning\">".getMLText("document_deleted")."</span></li>";
print "<li>".getMLText("uploaded_by")." <a href=\"mailto:".htmlspecialchars($responsibleUser->getEmail())."\">".htmlspecialchars($responsibleUser->getFullName())."</a></li>";
print "<li>".getLongReadableDate($file->getDate())."</li>";
if($file->getVersion())
print "<li>".getMLText('linked_to_current_version')."</li>";
else
print "<li>".getMLText('linked_to_document')."</li>";
print "</ul></td>";
print "<td>".htmlspecialchars($file->getComment())."</td>";
print "<td><ul class=\"unstyled actions\">";
if ($file_exists) {
if($accessobject->check_controller_access('Download', array('action'=>'file'))) {
print "<li><a href=\"".$this->params['settings']->_httpRoot."op/op.Download.php?documentid=".$documentid."&file=".$file->getID()."\"><i class=\"fa fa-download\"></i>".getMLText('download')."</a></li>";
}
if ($viewonlinefiletypes && (in_array(strtolower($file->getFileType()), $viewonlinefiletypes) || in_array(strtolower($file->getMimeType()), $viewonlinefiletypes))) {
if($accessobject->check_controller_access('ViewOnline', array('action'=>'run'))) {
print "<li><a target=\"_blank\" href=\"".$this->params['settings']->_httpRoot."op/op.ViewOnline.php?documentid=".$documentid."&file=". $file->getID()."\"><i class=\"fa fa-star\"></i>" . getMLText("view_online") . "</a></li>";
}
}
}
echo "</ul><ul class=\"unstyled actions\">";
if (($document->getAccessMode($user) == M_ALL)||($file->getUserID()==$user->getID())) {
print $this->html_link('RemoveDocumentFile', array('documentid'=>$document->getID(), 'fileid'=>$file->getID()), array(), '<i class="fa fa-remove"></i>'.getMLText("delete"), false, true, array('<li>', '</li>'));
print $this->html_link('EditDocumentFile', array('documentid'=>$document->getID(), 'fileid'=>$file->getID()), array(), '<i class="fa fa-edit"></i>'.getMLText("edit"), false, true, array('<li>', '</li>'));
}
print "</ul></td>";
print "</tr>";
}
print "</tbody>\n</table>\n";
}
else $this->infoMsg(getMLText("no_attached_files"));
} /* }}} */
function documentInfos() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
@ -651,6 +769,7 @@ $(document).ready( function() {
$document = $this->params['document'];
$accessobject = $this->params['accessobject'];
$viewonlinefiletypes = $this->params['viewonlinefiletypes'];
$enableDropUpload = $this->params['enableDropUpload'];
$enableownerrevapp = $this->params['enableownerrevapp'];
$enableremoverevapp = $this->params['enableremoverevapp'];
$workflowmode = $this->params['workflowmode'];
@ -1325,102 +1444,28 @@ $(document).ready( function() {
<?php
}
?>
<div class="tab-pane <?php if($currenttab == 'attachments') echo 'active'; ?>" id="attachments" role="tabpanel">
<div class="tab-pane <?php if($currenttab == 'attachments') echo 'active'; ?>" id="attachments" role="tabpanel">
<?php
if (count($files) > 0) {
print "<table class=\"table\">";
print "<thead>\n<tr>\n";
print "<th width='20%'></th>\n";
print "<th width='20%'>".getMLText("file")."</th>\n";
print "<th width='40%'>".getMLText("comment")."</th>\n";
print "<th width='20%'></th>\n";
print "</tr>\n</thead>\n<tbody>\n";
foreach($files as $file) {
$file_exists=file_exists($dms->contentDir . $file->getPath());
$responsibleUser = $file->getUser();
print "<tr>";
print "<td>";
$previewer->createPreview($file, $previewwidthdetail);
if($file_exists) {
if ($viewonlinefiletypes && (in_array(strtolower($file->getFileType()), $viewonlinefiletypes) || in_array(strtolower($file->getMimeType()), $viewonlinefiletypes))) {
if($accessobject->check_controller_access('ViewOnline', array('action'=>'run'))) {
print "<a target=\"_blank\" href=\"".$this->params['settings']->_httpRoot."op/op.ViewOnline.php?documentid=".$documentid."&file=". $file->getID()."\">";
}
} else {
if($accessobject->check_controller_access('Download', array('action'=>'file'))) {
print "<a href=\"".$this->params['settings']->_httpRoot."op/op.Download.php?documentid=".$documentid."&file=".$file->getID()."\">";
}
}
}
if($previewer->hasPreview($file)) {
print("<img class=\"mimeicon\" width=\"".$previewwidthdetail."\" src=\"".$this->params['settings']->_httpRoot."op/op.Preview.php?documentid=".$document->getID()."&file=".$file->getID()."&width=".$previewwidthdetail."\" title=\"".htmlspecialchars($file->getMimeType())."\">");
} else {
print "<img class=\"mimeicon\" width=\"".$previewwidthdetail."\" src=\"".$this->getMimeIcon($file->getFileType())."\" title=\"".htmlspecialchars($file->getMimeType())."\">";
}
if($file_exists) {
if($accessobject->check_controller_access('Download', array('action'=>'run')) || $accessobject->check_controller_access('ViewOnline', array('action'=>'run')))
print "</a>";
}
print "</td>";
print "<td><ul class=\"actions unstyled\">\n";
print "<li>".htmlspecialchars($file->getName())."</li>\n";
if($file->getName() != $file->getOriginalFileName())
print "<li>".htmlspecialchars($file->getOriginalFileName())."</li>\n";
if ($file_exists)
print "<li>".SeedDMS_Core_File::format_filesize(filesize($dms->contentDir . $file->getPath())) ." bytes, ".htmlspecialchars($file->getMimeType())."</li>";
else print "<li>".htmlspecialchars($file->getMimeType())." - <span class=\"warning\">".getMLText("document_deleted")."</span></li>";
print "<li>".getMLText("uploaded_by")." <a href=\"mailto:".htmlspecialchars($responsibleUser->getEmail())."\">".htmlspecialchars($responsibleUser->getFullName())."</a></li>";
print "<li>".getLongReadableDate($file->getDate())."</li>";
if($file->getVersion())
print "<li>".getMLText('linked_to_current_version')."</li>";
else
print "<li>".getMLText('linked_to_document')."</li>";
print "</ul></td>";
print "<td>".htmlspecialchars($file->getComment())."</td>";
print "<td><ul class=\"unstyled actions\">";
if ($file_exists) {
if($accessobject->check_controller_access('Download', array('action'=>'file'))) {
print "<li><a href=\"".$this->params['settings']->_httpRoot."op/op.Download.php?documentid=".$documentid."&file=".$file->getID()."\"><i class=\"fa fa-download\"></i>".getMLText('download')."</a></li>";
}
if ($viewonlinefiletypes && (in_array(strtolower($file->getFileType()), $viewonlinefiletypes) || in_array(strtolower($file->getMimeType()), $viewonlinefiletypes))) {
if($accessobject->check_controller_access('ViewOnline', array('action'=>'run'))) {
print "<li><a target=\"_blank\" href=\"".$this->params['settings']->_httpRoot."op/op.ViewOnline.php?documentid=".$documentid."&file=". $file->getID()."\"><i class=\"fa fa-star\"></i>" . getMLText("view_online") . "</a></li>";
}
}
}
echo "</ul><ul class=\"unstyled actions\">";
if (($document->getAccessMode($user) == M_ALL)||($file->getUserID()==$user->getID())) {
print $this->html_link('RemoveDocumentFile', array('documentid'=>$document->getID(), 'fileid'=>$file->getID()), array(), '<i class="fa fa-remove"></i>'.getMLText("delete"), false, true, array('<li>', '</li>'));
print $this->html_link('EditDocumentFile', array('documentid'=>$document->getID(), 'fileid'=>$file->getID()), array(), '<i class="fa fa-edit"></i>'.getMLText("edit"), false, true, array('<li>', '</li>'));
}
print "</ul></td>";
print "</tr>";
}
print "</tbody>\n</table>\n";
}
else $this->infoMsg(getMLText("no_attached_files"));
$this->rowStart();
$this->columnStart(9);
?>
<div class="ajax" data-view="ViewDocument" data-action="documentFiles" data-no-spinner="true" <?php echo ($document ? "data-query=\"documentid=".$document->getID()."\"" : "") ?>></div>
<?php
$this->columnEnd();
$this->columnStart(3);
if($accessobject->check_controller_access('AddFile')) {
if ($document->getAccessMode($user) >= M_READWRITE){
if(0){
if($enableDropUpload){
?>
<div id="_draganddrophandler" class="droptarget well alert" data-droptarget="attachment_<?= $document->getID(); ?>" data-target="<?= $document->getID(); ?>" data-uploadformtoken="<?= createFormKey(''); ?>"><?php printMLText('drop_files_here'); echo $this->html_link("AddFile", array('documentid'=>$document->getID()), array(), getMLText('add')); ?></div>
<div id="draganddrophandler" class="well alert alert-warning" data-droptarget="attachment_<?= $document->getID(); ?>" data-target="<?= $document->getID(); ?>" data-uploadformtoken="<?= createFormKey('addfile'); ?>"><?php echo $this->html_link('AddFile', array('documentid'=>$documentid), array('class'=>'alert alert-warning'), getMLText('drop_files_here_or_click'), false, true); ?></div>
<?php
} else {
print $this->html_link('AddFile', array('documentid'=>$documentid), array('class'=>'btn btn-primary'), getMLText("add"), false, true)."\n";
}
print $this->html_link('AddFile', array('documentid'=>$documentid), array('class'=>'btn btn-primary'), getMLText("add"), false, true)."\n";
}
}
$this->columnEnd();
$this->rowEnd();
?>
</div>
<div class="tab-pane <?php if($currenttab == 'links') echo 'active'; ?>" id="links" role="tabpanel">

View File

@ -713,7 +713,8 @@ function onAddClipboard(ev) { /* {{{ */
theme: 'defaultTheme',
timeout: 1500
});
status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-primary">' + editBtnLabel + '</a>'));
if(editBtnLabel)
status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-primary">' + editBtnLabel + '</a>'));
if(callback) {
callback();
}
@ -839,6 +840,32 @@ function onAddClipboard(ev) { /* {{{ */
}
}
*/
} else if(target_type == 'attachment' && 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', 'addfile');
var status = new createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
sendFileToServer(fd,status, function(){
$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});
});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
}
}
}
}( window.SeedDMSUpload = window.SeedDMSUpload || {}, jQuery )); /* }}} */
@ -1074,9 +1101,9 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'attachment') {
console.log('attachment');
var files = e.originalEvent.dataTransfer.files;
if(files.length > 0) {
SeedDMSUpload.handleFileUpload(files,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
}
});

View File

@ -744,7 +744,8 @@ function onAddClipboard(ev) { /* {{{ */
theme: 'defaultTheme',
timeout: 1500
});
status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-primary">' + editBtnLabel + '</a>'));
if(editBtnLabel)
status.statusbar.after($('<a href="'+seeddms_webroot+'out/out.EditDocument.php?documentid=' + data.data + '" class="btn btn-mini btn-primary">' + editBtnLabel + '</a>'));
if(callback) {
callback();
}
@ -870,6 +871,32 @@ function onAddClipboard(ev) { /* {{{ */
}
}
*/
} else if(target_type == 'attachment' && 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', 'addfile');
var status = new createStatusbar(statusbar);
status.setFileNameSize(files[i].name,files[i].size);
sendFileToServer(fd,status, function(){
$("div.ajax[data-action='documentFiles']").trigger('update', {documentid: target_id});
});
} else {
noty({
text: maxFileSizeMsg + '<br /><em>' + files[i].name + ' (' + files[i].size + ' Bytes)</em>',
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 5000
});
}
}
}
}
}( window.SeedDMSUpload = window.SeedDMSUpload || {}, jQuery )); /* }}} */
@ -1124,9 +1151,9 @@ $(document).ready(function() { /* {{{ */
}
}
} else if(target_type == 'attachment') {
console.log('attachment');
var files = e.originalEvent.dataTransfer.files;
if(files.length > 0) {
SeedDMSUpload.handleFileUpload(files,$(e.currentTarget),$('div.statusbar-container h1')/*$(e.currentTarget).find("span")*/);
}
}
});