Skip to content
Snippets Groups Projects
Commit 9772ef60 authored by Jean-Philippe Laverdure's avatar Jean-Philippe Laverdure
Browse files

Adds drag and drop capacity to annotations hstorefield

parent b47e4c28
No related branches found
No related tags found
1 merge request!36Adds drag and drop capacity to annotations hstorefield
......@@ -41,8 +41,48 @@ function activateDropzone(dzone) {
});
}
function handleFileSelect(event) {
event.stopPropagation();
event.preventDefault();
var files = event.dataTransfer.files; // files is a FileList of File objects
var reader = new FileReader();
reader.onload = function(e) {
var data = {};
var text = reader.result;
var lines = text.split('\n');
lines.map(function(item) {
var tabs = item.split('\t');
data[tabs[0]] = tabs[1];
});
var out = JSON.stringify(data)
console.log(out);
event.srcElement.value = out;
};
var file = files[0];
reader.readAsText(file);
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
$(function () {
// Setup the dnd listeners.
if (window.File && window.FileReader && window.FileList) {
// Great success! All the File APIs are supported.
var dropZone = document.getElementById('id_annotations');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
} else {
$(".no-file-api").addClass("d-none");
}
$.fn.datetimepicker.Constructor.Default.icons = {
time: 'far fa-clock',
date: 'far fa-calendar-alt',
......
......@@ -4,7 +4,7 @@ chardet==3.0.4
Django==2.0.13
django-auth-ldap==1.7.0
django-chartjs==1.3
django-crispy-forms==1.7.2
django-crispy-forms==1.8.1
django-model-utils==3.1.2
django-private-storage==2.2
flake8==3.6.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment