'+icon+'
'+ name +'
'+fileSize+'\
\
\

\
\
'+ name +''+fileSize+'\
\
\
\
\
');
let fileelement = file.appendTo(_this.fileList);
if (selected) {
$("input[type='radio'], input[type='checkbox']", fileelement).prop("checked", true);
}
}
render(data) {
var scannedFolders = [],
scannedFiles = [];
if(Array.isArray(data)) {
data.forEach(function (d) {
if (d.type === 'folder') {
scannedFolders.push(d);
}
else if (d.type === 'file') {
scannedFiles.push(d);
}
});
}
else if(typeof data === 'object') {
scannedFolders = data.folders;
scannedFiles = data.files;
}
// Empty the old result and make the new one
this.fileList.empty();//.hide();
if(!scannedFolders.length && !scannedFiles.length) {
this.filemanager.find('.nothingfound').show();
}
else {
this.filemanager.find('.nothingfound').hide();
}
let _this = this;
if(scannedFolders.length) {
scannedFolders.forEach(function(f) {
var itemsLength = f.items.length,
name = _this.escapeHTML(f.name),
icon = '
';
if(itemsLength) {
icon = '
';
}
if(itemsLength == 1) {
itemsLength += ' item';
}
else if(itemsLength > 1) {
itemsLength += ' items';
}
else {
itemsLength = 'Empty';
}
var folder = $('
'+icon+'' + name + ' ' + itemsLength + '
');
folder.appendTo(_this.fileList);
});
}
if(scannedFiles.length) {
scannedFiles.forEach(function(f) {
_this.addFile(f);
});
}
// Generate the breadcrumbs
var url = '';
if(this.filemanager.hasClass('searching')){
url = '
Search results: ';
this.fileList.removeClass('animated');
}
else {
this.fileList.addClass('animated');
this.breadcrumbsUrls.forEach(function (u, i) {
var name = u.split('/');
if (i !== _this.breadcrumbsUrls.length - 1) {
url += '
' + name[name.length-1] + ' → ';
}
else {
url += '
' + name[name.length-1] + '';
}
});
}
this.breadcrumbs.html('
home').append(url);
// Show the generated elements
this.fileList.animate({'display':'inline-block'});
}
// This function escapes special html characters in names
escapeHTML(text) {
return text.replace(/\&/g,'&').replace(/\/g,'>');
}
// Convert file sizes from bytes to human readable units
bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Bytes';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
}
/*
export {
MediaModal
}
*/