yavsc/src/Yavsc/wwwroot/js/fs.js

100 lines
3 KiB
JavaScript
Raw Normal View History

2019-08-25 01:47:46 +01:00
// requires DropZone ª toMarkdown
2019-09-05 15:16:28 +01:00
if (typeof jQuery === 'undefined') {
throw new Error('YavscRemoteFs script requires jQuery');
}
if (typeof Dropzone === 'undefined') {
throw new Error('YavscRemoteFs requires Dropzone');
}
if (typeof updateMD === 'undefined') {
throw new Error('YavscRemoteFs requires md-helpers.js');
}
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
(function($, Dropzone, updateMD) {
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
window.RemoteFS = (function ($) {
/*
var Combine = function (patha, pathb) {
if (!patha) return pathb;
if (!pathb) return patha;
return patha + '/' + pathb;
}; */
var OpenDir = function ($view, sub) {
$view.data('path', sub);
InitDir($view);
};
2019-08-25 01:47:46 +01:00
var InitDir = function ($view) {
var path = $view.data('path');
var owner = $view.data('owner');
2019-09-05 15:16:28 +01:00
var fsiourl = path ? '/api/fs/' + path : '/api/fs';
2019-08-25 01:47:46 +01:00
$view.empty();
2019-09-05 15:16:28 +01:00
$.get(fsiourl, function(data) {
$('<button>' + owner + '</button>').click(function() {
OpenDir($view, null);
}).appendTo($view);
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
var npath = null;
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
if (path) $.each(path.split('/'), function () {
var part = this;
if (npath) npath = npath + '/' + part;
else npath = part;
$('<button>').append(part).click(function() {
OpenDir($view, npath);
}).appendTo($view);
});
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
$.each(data.SubDirectories, function () {
var item = this;
var spath = (path) ? path + '/' + item.Name : item.Name;
$('<button>').append(item.Name).click(function() {
OpenDir($view, spath);
}).appendTo($view);
});
var $ftable = $('<table>').append('<tr class="fileheaders"><th>Nom</th><th>Taille</th><th>Modification</th></tr>');
$.each(data.Files, function () {
var item = this;
var $tr = $('<tr></tr>');
var $td = $('<td></td>');
$('<a></a>').append(item.Name).click(function() {
document.location = '/' + owner + '/' + npath + '/' + item.Name;
}).appendTo($td);
$td.appendTo($tr);
$('<td>' + item.Size + '</td>').appendTo($tr);
$('<td>' + item.LastModified + '</td>').appendTo($tr);
$tr.appendTo($ftable);
});
$ftable.appendTo($view);
});
};
$(document).ready(function () {
OpenDir($('.dirinfo'));
});
})($);
2019-08-25 01:47:46 +01:00
2019-09-05 15:16:28 +01:00
Dropzone.options.postfiles = {
2019-08-25 01:47:46 +01:00
maxFilesize: 20, // MB TODO: let sell it.
autoProcessQueue: true,
accept: function(file, done) {
2019-09-05 15:16:28 +01:00
if (file.name == 'justinbieber.jpg') {
done('Naha, you don\'t.');
} else { done(); }
2019-08-25 01:47:46 +01:00
},
success: function (file, response) {
for (var i = 0; i < response.length; i++) {
var filer = response[i];
$('<p><a href="/files/@User.GetUserName()/' + filer.FileName + '">' + filer.FileName + '</a></p>').appendTo('#ql-editor-2');
2019-09-05 15:16:28 +01:00
updateMD('Content', $('#contentview').html());
2019-08-25 01:47:46 +01:00
}
},
url: '/api/fs'
};
2019-09-05 15:16:28 +01:00
})($, Dropzone, updateMD);
2019-08-25 01:47:46 +01:00