From 5de24ca5e579260b5a7db6798249c60df05b96d6 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 5 Sep 2019 21:06:45 +0100 Subject: [PATCH] refacts & start of files drag&drop --- .../Views/Shared/_FSScriptsPartial.cshtml | 2 +- src/Yavsc/wwwroot/js/md-helpers.js | 14 +++++ .../wwwroot/js/{fs.js => yavsc-remote-fs.js} | 58 ++++++++++++++----- 3 files changed, 58 insertions(+), 16 deletions(-) rename src/Yavsc/wwwroot/js/{fs.js => yavsc-remote-fs.js} (53%) diff --git a/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml index d955f1c3..4098d3ff 100644 --- a/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml +++ b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/Yavsc/wwwroot/js/md-helpers.js b/src/Yavsc/wwwroot/js/md-helpers.js index 8feb85a0..90d0f515 100644 --- a/src/Yavsc/wwwroot/js/md-helpers.js +++ b/src/Yavsc/wwwroot/js/md-helpers.js @@ -20,3 +20,17 @@ var updateMD = function(id,content) { } jQuery('#' + id).val(markdown); }; + +var allowDrop = function (ev) { + ev.preventDefault(); +} + +var drag = function (ev) { + ev.dataTransfer.setData('text', ev.target.id); +} + +var drop = function (ev) { + ev.preventDefault(); + var data = ev.dataTransfer.getData('text'); + ev.target.appendChild(document.getElementById(data)); +} diff --git a/src/Yavsc/wwwroot/js/fs.js b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js similarity index 53% rename from src/Yavsc/wwwroot/js/fs.js rename to src/Yavsc/wwwroot/js/yavsc-remote-fs.js index f0dc3134..6f541070 100644 --- a/src/Yavsc/wwwroot/js/fs.js +++ b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js @@ -1,12 +1,12 @@ // requires DropZone ยช toMarkdown if (typeof jQuery === 'undefined') { - throw new Error('YavscRemoteFs script requires jQuery'); + throw new Error('yavsc-remote-fs script requires jQuery'); } if (typeof Dropzone === 'undefined') { - throw new Error('YavscRemoteFs requires Dropzone'); + throw new Error('yavsc-remote-fs requires Dropzone'); } if (typeof updateMD === 'undefined') { - throw new Error('YavscRemoteFs requires md-helpers.js'); + throw new Error('yavsc-remote-fs requires md-helpers.js'); } (function($, Dropzone, updateMD) { @@ -24,12 +24,29 @@ if (typeof updateMD === 'undefined') { $view.data('path', sub); InitDir($view); }; + var root; + var selection = []; + + var SetItemSelected = function (name, selected) { + if (selected) selection.push(name); + else selection = selection.filter(function(ele) { + return ele != name; + }); + }; + + var RemoveSelectedFiles = function () { + var xmlhttp = new XMLHttpRequest(); + $.each(selection, function() { + xmlhttp.open('DELETE', '/api/fs/' + this, true); + xmlhttp.send(); + }); + }; var InitDir = function ($view) { - var path = $view.data('path'); + root = $view.data('path'); var owner = $view.data('owner'); - var fsiourl = path ? '/api/fs/' + path : '/api/fs'; + var fsiourl = root ? '/api/fs/' + root : '/api/fs'; $view.empty(); @@ -40,29 +57,41 @@ if (typeof updateMD === 'undefined') { var npath = null; - if (path) $.each(path.split('/'), function () { + if (root) $.each(root.split('/'), function () { var part = this; - if (npath) npath = npath + '/' + part; - else npath = part; - $('