mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(cloudfunc) buildFromJSON
This commit is contained in:
parent
84ce2b7481
commit
201112fed4
1 changed files with 45 additions and 38 deletions
|
|
@ -333,36 +333,38 @@ var Util;
|
|||
|
||||
/**
|
||||
* Функция строит таблицу файлв из JSON-информации о файлах
|
||||
* @param pJSON - информация о файлах
|
||||
* @param json - информация о файлах
|
||||
*
|
||||
* {name:'имя',size:'размер',mode:'права доступа'}]
|
||||
*/
|
||||
this.buildFromJSON = function(pJSON, pTemplate, pPathTemplate, pLinkTemplate) {
|
||||
var lFile, i, n, type, link, target, size, owner, mode,
|
||||
this.buildFromJSON = function(json, template, pathTemplate, linkTemplate) {
|
||||
var file, i, n, type, target, size, owner, mode,
|
||||
/* ссылка на верхний каталог*/
|
||||
dotDot, link,
|
||||
linkResult,
|
||||
files = pJSON.files,
|
||||
files = json.files,
|
||||
/* сохраняем путь каталога в котором мы сейчас находимся*/
|
||||
lPath = pJSON.path,
|
||||
path = json.path,
|
||||
|
||||
/*
|
||||
* Строим путь каталога в котором мы находимся
|
||||
* со всеми подкаталогами
|
||||
*/
|
||||
lHtmlPath = getDirPath(lPath),
|
||||
htmlPath = getDirPath(path),
|
||||
|
||||
/* Убираем последний слэш
|
||||
* с пути для кнопки обновить страницу
|
||||
* если он есть
|
||||
*/
|
||||
lRefreshPath = CloudFunc.rmLastSlash(lPath),
|
||||
refreshPath = CloudFunc.rmLastSlash(path),
|
||||
|
||||
lFileTable = Util.render(pPathTemplate, {
|
||||
link : FS + lRefreshPath,
|
||||
fullPath : lPath,
|
||||
path : lHtmlPath
|
||||
fileTable = Util.render(pathTemplate, {
|
||||
link : FS + refreshPath,
|
||||
fullPath : path,
|
||||
path : htmlPath
|
||||
}),
|
||||
|
||||
lHeader = Util.render(pTemplate, {
|
||||
lHeader = Util.render(template, {
|
||||
className : 'fm-header',
|
||||
type : '',
|
||||
name : 'name',
|
||||
|
|
@ -372,33 +374,31 @@ var Util;
|
|||
});
|
||||
|
||||
lHeader = Util.replaceStr(lHeader, 'li', 'div');
|
||||
lFileTable += lHeader;
|
||||
fileTable += lHeader;
|
||||
|
||||
/* сохраняем путь */
|
||||
CloudFunc.Path = lPath;
|
||||
CloudFunc.Path = path;
|
||||
|
||||
lFileTable += '<ul class="files">';
|
||||
fileTable += '<ul class="files">';
|
||||
/* Если мы не в корне */
|
||||
if (lPath !== '/') {
|
||||
/* ссылка на верхний каталог*/
|
||||
var lDotDot, lLink;
|
||||
if (path !== '/') {
|
||||
/* убираем последний слеш и каталог в котором мы сейчас находимся*/
|
||||
lDotDot = lPath.substr(lPath, lPath.lastIndexOf('/'));
|
||||
lDotDot = lDotDot.substr(lDotDot, lDotDot.lastIndexOf('/'));
|
||||
dotDot = path.substr(path, path.lastIndexOf('/'));
|
||||
dotDot = dotDot.substr(dotDot, dotDot.lastIndexOf('/'));
|
||||
/* Если предыдущий каталог корневой */
|
||||
if (lDotDot === '')
|
||||
lDotDot = '/';
|
||||
if (dotDot === '')
|
||||
dotDot = '/';
|
||||
|
||||
lLink = FS + lDotDot;
|
||||
link = FS + dotDot;
|
||||
|
||||
linkResult = Util.render(pLinkTemplate, {
|
||||
link : lLink,
|
||||
linkResult = Util.render(linkTemplate, {
|
||||
link : link,
|
||||
name : '..',
|
||||
target : ''
|
||||
});
|
||||
|
||||
/* Сохраняем путь к каталогу верхнего уровня*/
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
fileTable += Util.render(template,{
|
||||
className : '',
|
||||
type : 'directory',
|
||||
name : linkResult,
|
||||
|
|
@ -410,23 +410,30 @@ var Util;
|
|||
|
||||
n = files.length;
|
||||
for (i = 0; i < n; i++) {
|
||||
lFile = files[i];
|
||||
type = lFile.size === 'dir' ? 'directory' : 'text-file';
|
||||
link = FS + lPath + lFile.name;
|
||||
target = lFile.size === 'dir' ? '' : "_blank";
|
||||
size = lFile.size === 'dir' ? '<dir>' : CloudFunc.getShortSize(lFile.size);
|
||||
owner = lFile.owner ? lFile.owner : 'root';
|
||||
file = files[i];
|
||||
link = FS + path + file.name;
|
||||
|
||||
mode = CloudFunc.getSymbolicPermissions(lFile.mode);
|
||||
if (file.size === 'dir') {
|
||||
type = 'directory';
|
||||
target = '';
|
||||
size = '<dir>';
|
||||
} else {
|
||||
type = 'text-file';
|
||||
target = '_blank';
|
||||
size = CloudFunc.getShortSize(file.size);
|
||||
}
|
||||
|
||||
linkResult = Util.render(pLinkTemplate, {
|
||||
owner = file.owner || 'root';
|
||||
mode = CloudFunc.getSymbolicPermissions(file.mode);
|
||||
|
||||
linkResult = Util.render(linkTemplate, {
|
||||
link : link,
|
||||
name : lFile.name,
|
||||
name : file.name,
|
||||
target : target
|
||||
});
|
||||
|
||||
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
fileTable += Util.render(template,{
|
||||
className : '',
|
||||
/* Если папка - выводим пиктограмму папки *
|
||||
* В противоположном случае - файла */
|
||||
|
|
@ -438,9 +445,9 @@ var Util;
|
|||
});
|
||||
}
|
||||
|
||||
lFileTable += '</ul>';
|
||||
fileTable += '</ul>';
|
||||
|
||||
return lFileTable;
|
||||
return fileTable;
|
||||
};
|
||||
}
|
||||
})(this, Util);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue