From a4a18fe9201d67a1ac24ea44cc7d52ca3b210691 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 21 Jul 2015 11:06:57 -0400 Subject: [PATCH] feature(cloudfunc) rm rmLastSlash --- lib/client.js | 17 ++++------------- lib/client/dom.js | 15 +++++++-------- lib/client/konsole.js | 6 ------ lib/client/listeners.js | 2 -- lib/client/operation.js | 13 +++---------- lib/cloudfunc.js | 28 +--------------------------- 6 files changed, 15 insertions(+), 66 deletions(-) diff --git a/lib/client.js b/lib/client.js index 60be84c9..f8a66d6d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -49,22 +49,18 @@ var Util, DOM, CloudFunc, join; * @param callback */ this.loadDir = function(params, callback) { - var link, imgPosition, panelChanged, pathParams, + var imgPosition, panelChanged, noCurrent, isRefresh, panel, history, p = params; if (params) { - pathParams = p.path; isRefresh = p.isRefresh; panel = p.panel; history = p.history; noCurrent = p.noCurrent; } - if (pathParams) - link = pathParams; - if (!noCurrent) if (panel && panel !== Info.panel) { DOM.changePanel(); @@ -77,7 +73,7 @@ var Util, DOM, CloudFunc, join; Images.show.load(imgPosition, panel); /* загружаем содержимое каталога */ - ajaxLoad(link, { + ajaxLoad(p.path, { refresh : isRefresh, history : history, noCurrent : noCurrent @@ -296,9 +292,6 @@ var Util, DOM, CloudFunc, join; Listeners.initKeysPanel(); - /* Устанавливаем кэш корневого каталога */ - dirPath = CloudFunc.rmLastSlash(dirPath); - Storage.get(dirPath, function(error, data) { if (!data) { data = getJSONfromFileTable(); @@ -330,8 +323,7 @@ var Util, DOM, CloudFunc, join; var panel = panelParam || Info.panel, noCurrent, NEEDREFRESH = true, - path = DOM.getCurrentDirPath(panel), - notSlashlLink = CloudFunc.rmLastSlash(path); + path = DOM.getCurrentDirPath(panel); if (options) noCurrent = options.noCurrent; @@ -342,7 +334,7 @@ var Util, DOM, CloudFunc, join; } CloudCmd.loadDir({ - path : notSlashlLink, + path : path, isRefresh : NEEDREFRESH, history : false, panel : panel, @@ -511,7 +503,6 @@ var Util, DOM, CloudFunc, join; if (path !== parentPath) { path = parentPath; - path = CloudFunc.rmLastSlash(path); CloudCmd.loadDir({ path: path diff --git a/lib/client/dom.js b/lib/client/dom.js index 8102e928..77394a1c 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -500,13 +500,13 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; */ this.getCurrentDirName = function() { var ret, - lSubstr, + substr, /* получаем имя каталога в котором находимся */ - lHref = this.getCurrentDirPath(); + href = this.getCurrentDirPath(); - lHref = CloudFunc.rmLastSlash(lHref); - lSubstr = lHref.substr(lHref, lHref.lastIndexOf('/')); - ret = lHref.replace(lSubstr + '/', '') || '/'; + href = href.replace(/\/$/, ''); + substr = href.substr(href, href.lastIndexOf('/')); + ret = href.replace(substr + '/', '') || '/'; return ret; }; @@ -1418,13 +1418,12 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; }; RESTful.mv(files, function(error) { - var Storage = DOM.Storage, - path = CloudFunc.rmLastSlash(dirPath); + var Storage = DOM.Storage; if (!error) { DOM.setCurrentName(to, current); Cmd.updateCurrentInfo(); - Storage.remove(path); + Storage.remove(dirPath); if (isExist) CloudCmd.refresh(); diff --git a/lib/client/konsole.js b/lib/client/konsole.js index ab4ec148..0e9f71f0 100644 --- a/lib/client/konsole.js +++ b/lib/client/konsole.js @@ -50,8 +50,6 @@ 'P': function() { var command = Console.getPromptText(), path = DOM.getCurrentDirPath(); - - path = rmLastSlash(path); command += path; Console.setPromptText(command); @@ -59,10 +57,6 @@ }); } - function rmLastSlash(str) { - return str.replace(/\/$/, ''); - } - this.show = function(callback) { if (Loaded) CloudCmd.View.show(Element, { diff --git a/lib/client/listeners.js b/lib/client/listeners.js index fa3bd8be..3ae0eb5f 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -167,8 +167,6 @@ var Util, DOM, CloudFunc, CloudCmd; isDir = DOM.isCurrentIsDir(current), path = DOM.getCurrentPath(current); - path = CloudFunc.rmLastSlash(path); - if (isDir) { CloudCmd.loadDir({ path: path diff --git a/lib/client/operation.js b/lib/client/operation.js index 80203393..a1ba3073 100644 --- a/lib/client/operation.js +++ b/lib/client/operation.js @@ -31,10 +31,6 @@ Operation = this; - function rmLastSlash(str) { - return str.replace(/\/$/, ''); - } - function init() { showLoad(); @@ -295,8 +291,7 @@ deleteFn(path + query, names, function(error) { var Storage = DOM.Storage, - dirPath = Info.dirPath, - dir = rmLastSlash(dirPath); + dirPath = Info.dirPath; if (!error) { if (n > 1) @@ -304,7 +299,7 @@ else DOM.deleteCurrent(current); - Storage.removeMatch(dir); + Storage.removeMatch(dirPath); } }); } @@ -372,9 +367,7 @@ }; operation(files, function(error) { - var path = rmLastSlash(from); - - !error && DOM.Storage.remove(path, function() { + !error && DOM.Storage.remove(from, function() { var panel = Info.panel, panelPassive = Info.panelPassive, setCurrent = function() { diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index 0c0b500a..d035c6a6 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -69,30 +69,10 @@ var Util; else name = ''; - msg = msg + ': ' + status + name; return msg; }; - /** - * Функция убирает последний слеш, - * если он - последний символ строки - */ - this.rmLastSlash = function(path) { - var length, lastSlash, isEqual; - - if (typeof path !== 'string') - throw(Error('path should be a string!')); - - length = path.length - 1; - lastSlash = path.lastIndexOf('/'); - isEqual = lastSlash === length; - - if (length && isEqual) - path = path.substr(path, length); - - return path; - }; /** Функция возвращает заголовок веб страницы * @pPath @@ -173,14 +153,8 @@ var Util; */ htmlPath = getPathLink(path, template.pathLink), - /* Убираем последний слэш - * с пути для кнопки обновить страницу - * если он есть - */ - refreshPath = CloudFunc.rmLastSlash(path), - fileTable = rendy(template.path, { - link : FS + refreshPath, + link : FS + path, fullPath : path, path : htmlPath }),