|
|
@ -1,128 +1,136 @@
|
|
|
|
// requires DropZone ª toMarkdown
|
|
|
|
// requires DropZone ª toMarkdown
|
|
|
|
if (typeof jQuery === 'undefined') {
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof window.jQuery === 'undefined') {
|
|
|
|
throw new Error('yavsc-remote-fs script requires jQuery');
|
|
|
|
throw new Error('yavsc-remote-fs script requires jQuery');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof Dropzone === 'undefined') {
|
|
|
|
|
|
|
|
throw new Error('yavsc-remote-fs requires Dropzone');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof updateMD === 'undefined') {
|
|
|
|
|
|
|
|
throw new Error('yavsc-remote-fs requires md-helpers.js');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function($, Dropzone, updateMD) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.RemoteFS = (function ($) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
var Combine = function (patha, pathb) {
|
|
|
|
|
|
|
|
if (!patha) return pathb;
|
|
|
|
|
|
|
|
if (!pathb) return patha;
|
|
|
|
|
|
|
|
return patha + '/' + pathb;
|
|
|
|
|
|
|
|
}; */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var OpenDir = function ($view, sub) {
|
|
|
|
(function ($) {
|
|
|
|
$view.data('path', sub);
|
|
|
|
$.widget('psc.yarfs', {
|
|
|
|
InitDir($view);
|
|
|
|
options: {
|
|
|
|
};
|
|
|
|
fsnurl: '/api/fs'
|
|
|
|
var root;
|
|
|
|
},
|
|
|
|
var selection = [];
|
|
|
|
root: null,
|
|
|
|
|
|
|
|
rmAlert: null,
|
|
|
|
var SetItemSelected = function (name, selected) {
|
|
|
|
flist: null,
|
|
|
|
if (selected) selection.push(name);
|
|
|
|
selection: [],
|
|
|
|
else selection = selection.filter(function(ele) {
|
|
|
|
dirBar: null,
|
|
|
|
return ele != name;
|
|
|
|
openDir: function (sub) {
|
|
|
|
});
|
|
|
|
var _this = this;
|
|
|
|
};
|
|
|
|
this.root = sub;
|
|
|
|
|
|
|
|
var owner = this.element.data('owner');
|
|
|
|
var RemoveSelectedFiles = function () {
|
|
|
|
this.selection = [];
|
|
|
|
var xmlhttp = new XMLHttpRequest();
|
|
|
|
this.dirBar.empty();
|
|
|
|
$.each(selection, function() {
|
|
|
|
|
|
|
|
xmlhttp.open('DELETE', '/api/fs/' + this, true);
|
|
|
|
|
|
|
|
xmlhttp.send();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var InitDir = function ($view) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root = $view.data('path');
|
|
|
|
|
|
|
|
var owner = $view.data('owner');
|
|
|
|
|
|
|
|
var fsiourl = root ? '/api/fs/' + root : '/api/fs';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$view.empty();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.get(fsiourl, function(data) {
|
|
|
|
|
|
|
|
$('<button>' + owner + '</button>').click(function() {
|
|
|
|
$('<button>' + owner + '</button>').click(function() {
|
|
|
|
OpenDir($view, null);
|
|
|
|
_this.openDir(null);
|
|
|
|
}).appendTo($view);
|
|
|
|
}).appendTo(this.dirBar);
|
|
|
|
|
|
|
|
|
|
|
|
var npath = null;
|
|
|
|
var npath = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (root) $.each(root.split('/'), function () {
|
|
|
|
if (_this.root) {
|
|
|
|
|
|
|
|
var dnames = _this.root.split('/');
|
|
|
|
|
|
|
|
$.each(dnames, function () {
|
|
|
|
var part = this;
|
|
|
|
var part = this;
|
|
|
|
if (npath == null) npath = part;
|
|
|
|
if (npath == null) npath = part;
|
|
|
|
else npath = npath + '/' + part;
|
|
|
|
else npath = npath + '/' + part;
|
|
|
|
$('<button/>').append(part).click(function() {
|
|
|
|
$('<button/>').append(part).click(function() {
|
|
|
|
OpenDir($view, npath);
|
|
|
|
_this.OpenDir(npath);
|
|
|
|
}).appendTo($view);
|
|
|
|
}).appendTo(this.dirBar);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.ftable.find('tr.fileentry').remove();
|
|
|
|
|
|
|
|
var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs';
|
|
|
|
|
|
|
|
$.get(fsiourl, function(data) {
|
|
|
|
$.each(data.SubDirectories, function () {
|
|
|
|
$.each(data.SubDirectories, function () {
|
|
|
|
var item = this;
|
|
|
|
var item = this;
|
|
|
|
var spath = (root) ? root + '/' + item.Name : item.Name;
|
|
|
|
var spath = (_this.root) ? _this.root + '/' + item.Name : item.Name;
|
|
|
|
$('<button/>').append(item.Name).click(function() {
|
|
|
|
$('<button/>').append(item.Name).click(function() {
|
|
|
|
OpenDir($view, spath);
|
|
|
|
_this.openDir(spath);
|
|
|
|
}).appendTo($view);
|
|
|
|
}).appendTo(_this.dirBar);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
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 class="fileentry"></tr>');
|
|
|
|
var $tr = $('<tr class="fileentry"></tr>');
|
|
|
|
var $td = $('<td></td>');
|
|
|
|
var $td = $('<td></td>');
|
|
|
|
|
|
|
|
$td.appendTo($tr);
|
|
|
|
$('<input type="checkbox" />').addClass('check-box').click(function() {
|
|
|
|
$('<input type="checkbox" />').addClass('check-box').click(function() {
|
|
|
|
SetItemSelected(item.Name, this.checked)
|
|
|
|
_this.SetItemSelected(item.Name, this.checked);
|
|
|
|
}).appendTo($td);
|
|
|
|
}).appendTo($td);
|
|
|
|
$td.append(' ');
|
|
|
|
|
|
|
|
$('<a></a>').append(item.Name).click(function() {
|
|
|
|
$('<td></td>').append($('<a></a>').append(item.Name).click(function() {
|
|
|
|
if (root) document.location = '/' + owner + '/' + root + '/' + item.Name;
|
|
|
|
if (_this.root) document.location = '/' + owner + '/' + _this.root + '/' + item.Name;
|
|
|
|
else document.location = '/files/' + owner + '/' + item.Name;
|
|
|
|
else document.location = '/files/' + owner + '/' + item.Name;
|
|
|
|
}).appendTo($td);
|
|
|
|
})).appendTo($tr);
|
|
|
|
$td.appendTo($tr);
|
|
|
|
|
|
|
|
$('<td>' + item.Size + '</td>').appendTo($tr);
|
|
|
|
$('<td>' + item.Size + '</td>').appendTo($tr);
|
|
|
|
$('<td>' + item.LastModified + '</td>').appendTo($tr);
|
|
|
|
$('<td>' + item.LastModified + '</td>').appendTo($tr);
|
|
|
|
$tr.appendTo($ftable);
|
|
|
|
$tr.appendTo(_this.ftable);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$ftable.appendTo($view);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
$(document).ready(function () {
|
|
|
|
SetItemSelected: function (name, selected) {
|
|
|
|
OpenDir($('.dirinfo'));
|
|
|
|
if (selected) this.selection.push(name);
|
|
|
|
|
|
|
|
else this.selection = this.selection.filter(function(ele) {
|
|
|
|
|
|
|
|
return ele != name;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})($);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dropzone.options.postfiles = {
|
|
|
|
|
|
|
|
maxFilesize: 20, // MB TODO: let sell it.
|
|
|
|
|
|
|
|
autoProcessQueue: true,
|
|
|
|
|
|
|
|
accept: function(file, done) {
|
|
|
|
|
|
|
|
if (file.name == 'justinbieber.jpg') {
|
|
|
|
|
|
|
|
done('Naha, you don\'t.');
|
|
|
|
|
|
|
|
} else { done(); }
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
success: function (file, response) {
|
|
|
|
RemoveSelectedFiles: function () {
|
|
|
|
for (var i = 0; i < response.length; i++) {
|
|
|
|
$.each(this.selection, function() {
|
|
|
|
var filer = response[i];
|
|
|
|
var xmlhttp = new XMLHttpRequest();
|
|
|
|
$('<p><a href="/files/@User.GetUserName()/' + filer.FileName + '">' + filer.FileName + '</a></p>').appendTo('#ql-editor-2');
|
|
|
|
xmlhttp.open('DELETE', '/api/fs/' + this, true);
|
|
|
|
updateMD('Content', $('#contentview').html());
|
|
|
|
xmlhttp.send();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.selection = [];
|
|
|
|
|
|
|
|
// FIXME this could fail for a very long list of big files
|
|
|
|
|
|
|
|
setTimeout(500, function() { this.openDir(this.root); });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
url: '/api/fs'
|
|
|
|
askForRemoval: function () {
|
|
|
|
};
|
|
|
|
this.flist.empty();
|
|
|
|
})($, Dropzone, updateMD);
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
$.each(this.selection, function () {
|
|
|
|
|
|
|
|
_this.flist.append('<li>' + this + '</li>');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rmAlert.modal({ show: true });
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_create: function () {
|
|
|
|
|
|
|
|
var $view = this.element;
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
this.dirBar = $('<div></div>');
|
|
|
|
|
|
|
|
this.dirBar.appendTo($view);
|
|
|
|
|
|
|
|
this.ftable = $('<table border="1">').css('border-spacing', '6px')
|
|
|
|
|
|
|
|
.css('border-collapse', 'separate');
|
|
|
|
|
|
|
|
this.openDir($view.data('path'));
|
|
|
|
|
|
|
|
var btnRm = $('<button class="glyphicon"></button>').click(function() { _this.askForRemoval(); });
|
|
|
|
|
|
|
|
var tr = $('<tr class="fileheaders"></tr>');
|
|
|
|
|
|
|
|
_this.ftable.append(tr);
|
|
|
|
|
|
|
|
tr.append($('<th></th>').append(btnRm)).append('<th>Nom</th><th>Taille</th><th>Modification</th>');
|
|
|
|
|
|
|
|
_this.ftable.appendTo($view);
|
|
|
|
|
|
|
|
this.rmAlert = $('<div id="rmAlert" tabindex="-1" role="dialog"></div>');
|
|
|
|
|
|
|
|
this.rmAlert.addClass('modal');
|
|
|
|
|
|
|
|
this.rmAlert.addClass('fade');
|
|
|
|
|
|
|
|
var md = $('<div role="document"></div>');
|
|
|
|
|
|
|
|
md.addClass('modal-dialog');
|
|
|
|
|
|
|
|
this.rmAlert.append(md);
|
|
|
|
|
|
|
|
var mdCnt = $('<div class="modal-content"></div>');
|
|
|
|
|
|
|
|
mdCnt.addClass('modal-content');
|
|
|
|
|
|
|
|
var mdHeader = $('<div class="modal-header"></div>');
|
|
|
|
|
|
|
|
mdHeader.append('<h5 class="modal-title">File removal</h5>');
|
|
|
|
|
|
|
|
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>');
|
|
|
|
|
|
|
|
mdCnt.append(mdHeader);
|
|
|
|
|
|
|
|
var mdBody = $('<div class="modal-body"></div>');
|
|
|
|
|
|
|
|
mdBody.append('<p>You´re about to remove these files :</p>');
|
|
|
|
|
|
|
|
this.flist = $('<ul></ul>');
|
|
|
|
|
|
|
|
mdBody.append(this.flist);
|
|
|
|
|
|
|
|
mdCnt.append(mdBody);
|
|
|
|
|
|
|
|
var rmcBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do deletion</button>')
|
|
|
|
|
|
|
|
.click(function() { _this.RemoveSelectedFiles(); });
|
|
|
|
|
|
|
|
var mdFooter = $('<div class="modal-footer"></div>');
|
|
|
|
|
|
|
|
mdFooter.append(rmcBtn);
|
|
|
|
|
|
|
|
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
|
|
|
|
|
|
|
|
mdCnt.append(mdFooter);
|
|
|
|
|
|
|
|
md.append(mdCnt);
|
|
|
|
|
|
|
|
this.rmAlert.appendTo($view);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})(window.jQuery);
|
|
|
|
|
|
|
|
|
|
|
|