// requires DropZone ª toMarkdown
if (typeof window.jQuery === 'undefined') {
throw new Error('yavsc-remote-fs script requires jQuery');
}
if (typeof XMLHttpRequest === 'undefined') {
throw new Error('yavsc-remote-fs script requires XMLHttpRequest');
}
(function ($) {
'use strict';
$.widget('psc.yarfs', {
options: {
fsnurl: '/api/fs'
},
root: null,
rmDialog: null,
mvDialog: null,
flist: null,
fmlist: null,
selection: [],
curDirBar: null,
subDirsBar: null,
destination: null,
rootDisplay: null,
setRoot: function(sub) {
this.root = sub;
if (!this.root) this.rootDisplay.addClass('hidden');
else
{
this.rootDisplay.removeClass('hidden');
this.rootDisplay.html('from ' + this.root + '');
}
},
openDir: function (sub) {
var _this = this;
this.setRoot(sub);
var owner = this.element.data('owner');
this.selection = [];
this.curDirBar.empty();
this.subDirsBar.empty();
$('')
.click(function () {
_this.openDir(null);
})
.appendTo(this.curDirBar);
var npath = null
if (_this.root) {
var dnames = _this.root.split('/');
$.each(dnames, function () {
var part = this;
if (npath == null) npath = encodeURIComponent(part);
else npath = npath + '/' + encodeURIComponent(part);
$('')
.append(part)
.click(function () {
_this.openDir(npath);
})
.appendTo(_this.curDirBar);
});
}
this.ftable.find('tr.fileinfo').remove();
var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs';
$.get(fsiourl, function (data) {
if (data.SubDirectories.length == 0 && data.Files.length == 0)
{
$('').click(
function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('DELETE', '/api/fs/' + _this.root, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function(event) {
// XMLHttpRequest.DONE === 4
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
var dnames = _this.root.split('/');
var dcnt = dnames.length;
var nroot = dnames.slice(0,dcnt-1).join('/');
_this.openDir(nroot);
}
}
}
}).appendTo(_this.subDirsBar);
}
else
{
$.each(data.SubDirectories, function () {
var item = this;
var spath = _this.root ? _this.root + '/' + encodeURIComponent(item.Name) : encodeURIComponent(item.Name);
$('')
.append(item.Name)
.click(function () {
_this.openDir(spath);
})
.appendTo(_this.subDirsBar);
});
$.each(data.Files, function () {
var item = this;
var $tr = $('
You´re about to remove these files :
'); this.flist = $('You´re about to move these files :
'); this.fmlist = $('to the folowing sub-directory
'); mdBody.append(rp); inputDest.appendTo(mdBody); mdCnt.append(mdBody); var moveBtn = $('').click(function () { _this.moveSelectedFiles(); }); var mdFooter = $(''); mdFooter.append(moveBtn); mdFooter.append(''); mdCnt.append(mdFooter); md.append(mdCnt); this.mvDialog.append(md); this.mvDialog.appendTo(this.element); }, _create: function () { var $view = this.element; var _this = this; this.curDirBar = $(''); this.curDirBar.appendTo($view); this.subDirsBar = $(''); this.subDirsBar.appendTo($view); this.ftable = $('| ').append(btnRm).append(btnMv)).append(' | Nom | Taille | Modification | '); _this.ftable.appendTo($view); this.createRmDialog(); this.createMvDialog(); this.openDir($view.data('path')); } }); })(window.jQuery);
|---|