From 4a948ed384794178b6178c9cea8912909b6fe8d6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 4 Oct 2010 09:19:26 -0400 Subject: [PATCH] Fix all the path joining nastiness by writing a smart helper armadillo.App.joinPath(). --- web_frontend/main.js | 18 ++++++++++++++++++ web_frontend/path_control.js | 20 +++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/web_frontend/main.js b/web_frontend/main.js index df72ec3..5220143 100644 --- a/web_frontend/main.js +++ b/web_frontend/main.js @@ -138,6 +138,24 @@ armadillo.App.prototype.stripLastPathComponent = function(path) { return '/'; }; +/** + * Joins all the arguments together as a path. + * @param {string...} varargs Components to join + */ +armadillo.App.prototype.joinPath = function() { + var path = ''; + var sep = '/'; + var last = arguments.length - 1; + goog.array.forEach(arguments, function (c, i) { + if (c == sep && i != 0) + return; + path += c; + if (c[c.length - 1] != sep && i != last) + path += sep; + }); + return path; +}; + /** * Clears the error message. */ diff --git a/web_frontend/path_control.js b/web_frontend/path_control.js index dd863bc..9d00f0e 100644 --- a/web_frontend/path_control.js +++ b/web_frontend/path_control.js @@ -95,15 +95,9 @@ armadillo.PathControl.prototype.decorateInternal = function(element) { this.element_ = element; var components = this.path_.split('/'); - if (components.length == 2) { - // If this is an item that lives at the root, generate a special node for - // moving between items at the top level. - components[0] = '/'; - } else { - // Otherwise, just remove it as the first node will list all items at the - // root. - goog.array.removeAt(components, 0); - } + // If this is an item that lives at the root, generate a special node for + // moving between items at the top level. + components[0] = '/'; // If the last component is emtpy, do not use it because it means a directory // is being moved. @@ -111,10 +105,10 @@ armadillo.PathControl.prototype.decorateInternal = function(element) { goog.array.removeAt(components, components.length - 1); } - var path = '/'; + var path = ''; goog.array.forEach(components, function (part, i) { this.addChild(this.createComponentNode_(path, part), true); - path += part + '/'; + path = app.joinPath(path, part); }, this); if (this.editableLastComponent_) { @@ -174,14 +168,14 @@ armadillo.PathControl.prototype.fetchMenuContents_ = function(path, name, menu) return; } var item = new goog.ui.MenuItem(caption); - item.setValue(path + caption); + item.setValue(app.joinPath(path, name, caption)); menu.addItem(item); if (caption == name) { menu.setHighlighted(item); } }); }; - app.sendRequest('list', {'path':path}, callback); + app.sendRequest('list', {'path' : app.joinPath(path, name)}, callback); }; /** -- 2.43.5