drag & drop notes from the tree into relation map

This commit is contained in:
azivner 2018-11-12 13:05:09 +01:00
parent bbe36fc7fb
commit 340916d5da
2 changed files with 21 additions and 2 deletions

View file

@ -8,11 +8,21 @@ const dragAndDropSetup = {
return false; return false;
} }
// this is for dragging notes into relation map
data.dataTransfer.setData("text", JSON.stringify({
noteId: node.data.noteId,
title: node.data.title
}));
// This function MUST be defined to enable dragging for the tree. // This function MUST be defined to enable dragging for the tree.
// Return false to cancel dragging of node. // Return false to cancel dragging of node.
return true; return true;
}, },
dragEnter: (node, data) => true, // allow drop on any node dragEnter: (node, data) => {
// we don't allow moving root to any other location in the tree
// we allow it to be placed on the relation map though, that's handled in a different drop handler
return node.data.noteId === 'root';
}, // allow drop on any node
dragDrop: (node, data) => { dragDrop: (node, data) => {
// This function MUST be defined to enable dropping of items on the tree. // This function MUST be defined to enable dropping of items on the tree.
// data.hitMode is 'before', 'after', or 'over'. // data.hitMode is 'before', 'after', or 'over'.

View file

@ -456,10 +456,19 @@ function dragover_handler(ev) {
console.log("DRAGOVER"); console.log("DRAGOVER");
} }
function drop_handler(ev) { function drop_handler(ev) {
ev.preventDefault(); ev.preventDefault();
console.log("DROP!", ev); const note = JSON.parse(ev.originalEvent.dataTransfer.getData("text"));
let {x, y} = getMousePosition(ev);
// modifying position so that cursor is on the top-center of the box
x -= 80;
y -= 15;
createNoteBox(note.noteId, note.title, x, y);
} }
function getMousePosition(evt) { function getMousePosition(evt) {