From 4a1dabc3d712efda566520f22462de2ce483f54c Mon Sep 17 00:00:00 2001 From: hystepik Date: Fri, 17 Mar 2023 16:43:56 +0100 Subject: [PATCH] Upload works --- htdocs/core/js/lib_foot.js.php | 43 ------------------- htdocs/core/lib/files.lib.php | 71 +++++++++++++++++++++++++++++++ htdocs/core/lib/functions.lib.php | 4 +- 3 files changed, 74 insertions(+), 44 deletions(-) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index a6d48d10b8e..963e357199a 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -379,46 +379,3 @@ print ' }); }); '."\n"; - -// Code to manage the drag and drop file -//TODO: Find a way to display text over div -print "\n/* JS CODE TO ENABLE DRAG AND DROP OF FILE */\n"; -print ' - jQuery(document).ready(function() { - counterdragdrop = 0; - $(".cssDragDropArea").on("dragenter", function(ev) { - // Entering drop area. Highlight area - counterdragdrop++; - $(".cssDragDropArea").addClass("highlightDragDropArea"); - ev.preventDefault(); - }); - - $(".cssDragDropArea").on("dragleave", function(ev) { - // Going out of drop area. Remove Highlight - counterdragdrop--; - if (counterdragdrop === 0) { - $(".cssDragDropArea").removeClass("highlightDragDropArea"); - } - }); - - $(".cssDragDropArea").on("dragover", function(ev) { - ev.preventDefault(); - return false; - }); - - $(".cssDragDropArea").on("drop", function(e) { - console.log("Trigger event file droped"); - e.preventDefault(); - fd = new FormData(); - var dataTransfer = e.originalEvent.dataTransfer; - if(dataTransfer.files && dataTransfer.files.length){ - var droppedFiles = e.originalEvent.dataTransfer.files; - $.each(droppedFiles, function(index,file){ - fd.append("file",file,file.name) - }); - } - $(".cssDragDropArea").removeClass("highlightDragDropArea"); - counterdragdrop = 0; - }); - }); -'."\n"; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 60adcc64003..3e1c6892bbd 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3316,3 +3316,74 @@ function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path = '', $pathre return $file_list; } + +/** + * Function to manage the drag and drop file. + * We use global variable $object + * + * @return string Js script to display + */ +function dragAndDropFileUpload() +{ + global $object; + //TODO: Find a way to display text over div + $out = "\n"; + return $out; +} diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9a4ee8976ce..92ceba99563 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2042,7 +2042,9 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) { $out .= "\n".'
'."\n"; } - + if (!empty($dragdropfile)) { + print dragAndDropFileUpload(); + } $parameters = array('tabname' => $active, 'out' => $out); $reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead" if ($reshook > 0) {