refacts & start of files drag&drop
This commit is contained in:
parent
2421ad51b2
commit
5de24ca5e5
3 changed files with 58 additions and 16 deletions
|
|
@ -1 +1 @@
|
||||||
<script src="/js/fs.js" asp-append-version="true"></script>
|
<script src="/js/yavsc-remote-fs.js" asp-append-version="true"></script>
|
||||||
|
|
@ -20,3 +20,17 @@ var updateMD = function(id,content) {
|
||||||
}
|
}
|
||||||
jQuery('#' + id).val(markdown);
|
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));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
// requires DropZone ª toMarkdown
|
// requires DropZone ª toMarkdown
|
||||||
if (typeof jQuery === 'undefined') {
|
if (typeof jQuery === 'undefined') {
|
||||||
throw new Error('YavscRemoteFs script requires jQuery');
|
throw new Error('yavsc-remote-fs script requires jQuery');
|
||||||
}
|
}
|
||||||
if (typeof Dropzone === 'undefined') {
|
if (typeof Dropzone === 'undefined') {
|
||||||
throw new Error('YavscRemoteFs requires Dropzone');
|
throw new Error('yavsc-remote-fs requires Dropzone');
|
||||||
}
|
}
|
||||||
if (typeof updateMD === 'undefined') {
|
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) {
|
(function($, Dropzone, updateMD) {
|
||||||
|
|
@ -24,12 +24,29 @@ if (typeof updateMD === 'undefined') {
|
||||||
$view.data('path', sub);
|
$view.data('path', sub);
|
||||||
InitDir($view);
|
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 InitDir = function ($view) {
|
||||||
|
|
||||||
var path = $view.data('path');
|
root = $view.data('path');
|
||||||
var owner = $view.data('owner');
|
var owner = $view.data('owner');
|
||||||
var fsiourl = path ? '/api/fs/' + path : '/api/fs';
|
var fsiourl = root ? '/api/fs/' + root : '/api/fs';
|
||||||
|
|
||||||
$view.empty();
|
$view.empty();
|
||||||
|
|
||||||
|
|
@ -40,29 +57,41 @@ if (typeof updateMD === 'undefined') {
|
||||||
|
|
||||||
var npath = null;
|
var npath = null;
|
||||||
|
|
||||||
if (path) $.each(path.split('/'), function () {
|
if (root) $.each(root.split('/'), function () {
|
||||||
var part = this;
|
var part = this;
|
||||||
if (npath) npath = npath + '/' + part;
|
if (npath == null) npath = part;
|
||||||
else npath = part;
|
else npath = npath + '/' + part;
|
||||||
$('<button>').append(part).click(function() {
|
$('<button/>').append(part).click(function() {
|
||||||
OpenDir($view, npath);
|
OpenDir($view, npath);
|
||||||
}).appendTo($view);
|
}).appendTo($view);
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each(data.SubDirectories, function () {
|
$.each(data.SubDirectories, function () {
|
||||||
var item = this;
|
var item = this;
|
||||||
var spath = (path) ? path + '/' + item.Name : item.Name;
|
var spath = (root) ? root + '/' + item.Name : item.Name;
|
||||||
$('<button>').append(item.Name).click(function() {
|
$('<button/>').append(item.Name).click(function() {
|
||||||
OpenDir($view, spath);
|
OpenDir($view, spath);
|
||||||
}).appendTo($view);
|
}).appendTo($view);
|
||||||
});
|
});
|
||||||
var $ftable = $('<table>').append('<tr class="fileheaders"><th>Nom</th><th>Taille</th><th>Modification</th></tr>');
|
var $divedit = $('<div></div>');
|
||||||
|
$('<button></button>').addClass('glyphicon').append().click(function() {
|
||||||
|
RemoveSelectedFiles();
|
||||||
|
}).appendTo($divedit);
|
||||||
|
$divedit.appendTo($view);
|
||||||
|
var $ftable = $('<table border="1">').css('border-spacing', '6px')
|
||||||
|
.css('border-collapse', 'separate')
|
||||||
|
.append('<tr class="fileheaders"><th>Nom</th><th>Taille</th><th>Modification</th></tr>');
|
||||||
$.each(data.Files, function () {
|
$.each(data.Files, function () {
|
||||||
var item = this;
|
var item = this;
|
||||||
var $tr = $('<tr></tr>');
|
var $tr = $('<tr class="fileentry"></tr>');
|
||||||
var $td = $('<td></td>');
|
var $td = $('<td></td>');
|
||||||
|
$('<input type="checkbox" />').addClass('check-box').click(function() {
|
||||||
|
SetItemSelected(item.Name, this.checked)
|
||||||
|
}).appendTo($td);
|
||||||
|
$td.append(' ');
|
||||||
$('<a></a>').append(item.Name).click(function() {
|
$('<a></a>').append(item.Name).click(function() {
|
||||||
document.location = '/' + owner + '/' + npath + '/' + item.Name;
|
if (root) document.location = '/' + owner + '/' + root + '/' + item.Name;
|
||||||
|
else document.location = '/files/' + owner + '/' + item.Name;
|
||||||
}).appendTo($td);
|
}).appendTo($td);
|
||||||
$td.appendTo($tr);
|
$td.appendTo($tr);
|
||||||
$('<td>' + item.Size + '</td>').appendTo($tr);
|
$('<td>' + item.Size + '</td>').appendTo($tr);
|
||||||
|
|
@ -95,6 +124,5 @@ if (typeof updateMD === 'undefined') {
|
||||||
},
|
},
|
||||||
url: '/api/fs'
|
url: '/api/fs'
|
||||||
};
|
};
|
||||||
|
|
||||||
})($, Dropzone, updateMD);
|
})($, Dropzone, updateMD);
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue