From eec0fc34d2bf34a573d19fa6adae232e83b354cc Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 May 2019 21:22:31 +1000 Subject: [PATCH] Provide function callback when file is dropped - https://stackoverflow.com/questions/6756583/prevent-browser-from-loading-a-drag-and-dropped-file - --- InvenTree/part/templates/part/part_base.html | 12 ++++++++++ .../static/script/inventree/inventree.js | 24 ++++++++++++++++++- InvenTree/templates/base.html | 11 --------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index c1836b9f8f..c1c64dddea 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -101,6 +101,18 @@ {% block js_ready %} {{ block.super }} + + $('#part-thumb').on('drop', function(event) { + + var transfer = event.originalEvent.dataTransfer; + + var files = transfer.files; + + console.log('dropped'); + + //$(this).removeClass('dragover'); + }); + $("#show-qr-code").click(function() { launchModalForm( "{% url 'part-qr' part.id %}", diff --git a/InvenTree/static/script/inventree/inventree.js b/InvenTree/static/script/inventree/inventree.js index e47e8f218b..35f446f9ef 100644 --- a/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/static/script/inventree/inventree.js @@ -3,6 +3,16 @@ function inventreeDocReady() { * This will be called for every page that extends "base.html" */ + window.addEventListener("dragover",function(e){ + e = e || event; + e.preventDefault(); + },false); + + window.addEventListener("drop",function(e){ + e = e || event; + e.preventDefault(); + },false); + /* Add drag-n-drop functionality to any element * marked with the class 'dropzone' */ @@ -10,7 +20,19 @@ function inventreeDocReady() { $(this).addClass('dragover'); }); - $('.dropzone').on('dragleave', function() { + $('.dropzone').on('dragleave drop', function() { $(this).removeClass('dragover'); }); + + // Callback to launch the 'About' window + $('#launch-about').click(function() { + var modal = $('#modal-about'); + + modal.modal({ + backdrop: 'static', + keyboard: 'false', + }); + + modal.modal('show'); + }); } \ No newline at end of file diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 21b1779924..2bc5cc9cd2 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -88,17 +88,6 @@ $(document).ready(function () { * Ref: static/script/inventree/notification.js */ showCachedAlerts(); - - $('#launch-about').click(function() { - var modal = $('#modal-about'); - - modal.modal({ - backdrop: 'static', - keyboard: 'false', - }); - - modal.modal('show'); - }); });