mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-08 02:28:23 +01:00
Upload works
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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 = "<script>";
|
||||
$out .= "\n/* JS CODE TO ENABLE DRAG AND DROP OF FILE */\n";
|
||||
$out .= '
|
||||
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();
|
||||
fd.append("fk_element","'.dol_escape_json($object->id).'");
|
||||
fd.append("element","'.dol_escape_json($object->element).'");
|
||||
fd.append("token","'.newToken().'");
|
||||
fd.append("action","uploadfile");
|
||||
var dataTransfer = e.originalEvent.dataTransfer;
|
||||
if(dataTransfer.files && dataTransfer.files.length){
|
||||
var droppedFiles = e.originalEvent.dataTransfer.files;
|
||||
$.each(droppedFiles, function(index,file){
|
||||
fd.append("files[]",file,file.name)
|
||||
});
|
||||
}
|
||||
$(".cssDragDropArea").removeClass("highlightDragDropArea");
|
||||
counterdragdrop = 0;
|
||||
$.ajax({
|
||||
url:"'.DOL_URL_ROOT.'/core/ajax/fileupload.php",
|
||||
type:"POST",
|
||||
processData:false,
|
||||
contentType: false,
|
||||
data:fd,
|
||||
success:function(){
|
||||
console.log("Uploaded.",arguments);
|
||||
window.location.href = "'.$_SERVER["PHP_SELF"].'?id='.dol_escape_json($object->id).'";
|
||||
},
|
||||
error:function(){ console.log("Error Uploading.",arguments) },
|
||||
})
|
||||
});
|
||||
});
|
||||
';
|
||||
$out .= "</script>\n";
|
||||
return $out;
|
||||
}
|
||||
|
||||
@@ -2042,7 +2042,9 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab
|
||||
if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) {
|
||||
$out .= "\n".'<div class="tabBar'.($notab == -1 ? '' : ($notab == -2 ? ' tabBarNoTop' : (($notab == -3 ? ' noborderbottom' : '').' tabBarWithBottom'))).(!empty($dragdropfile) ? ' cssDragDropArea' : '').'">'."\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) {
|
||||
|
||||
Reference in New Issue
Block a user