From a8a5816d2ff71929b584189c72c398cc7d8dbd7f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 4 Oct 2010 01:07:14 -0400 Subject: [PATCH] Separate the path from the name in PathComponent. First pass at updating the control. --- web_frontend/main.js | 4 ++-- web_frontend/path_control.js | 42 ++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/web_frontend/main.js b/web_frontend/main.js index 5ef1e14..df72ec3 100644 --- a/web_frontend/main.js +++ b/web_frontend/main.js @@ -90,7 +90,7 @@ armadillo.App.prototype.list = function(path) { */ armadillo.App.prototype.navigate = function(target) { if (target == '../') { - this.list(this.stripLastPathComponent_(this.currentPath_)); + this.list(this.stripLastPathComponent(this.currentPath_)); } else { this.list(this.currentPath_ + target); } @@ -127,7 +127,7 @@ armadillo.App.prototype.getCurrentPath = function() { * @param {string} path * @returns string */ -armadillo.App.prototype.stripLastPathComponent_ = function(path) { +armadillo.App.prototype.stripLastPathComponent = function(path) { for (var i = path.length - 1; i >= 0; --i) { if (path[i] == '/') { if (i != path.length - 1) { diff --git a/web_frontend/path_control.js b/web_frontend/path_control.js index 38701a6..dd863bc 100644 --- a/web_frontend/path_control.js +++ b/web_frontend/path_control.js @@ -30,7 +30,15 @@ armadillo.PathControl = function(path, editLastComponent, opt_domHelper) { * Full path of the control. * @type {string} */ - this.path_ = path; + this.path_ = null; + + /** + * The name of the file at the |path_|. + * @type {string} + */ + this.name_ = null; + + this.setPath(path); /** * Whether or not the last component is editable. @@ -55,6 +63,16 @@ armadillo.PathControl.prototype.disposeInternal = function() { this.components_ = null; }; +/** + * Sets the path. + * @param {string} path + */ +armadillo.PathControl.prototype.setPath = function(path) { + this.path_ = app.stripLastPathComponent(path); + this.name_ = path.substr(this.path_.length); + console.log(this.path_ + ' = ' + this.name_); +}; + /** * Creates a new path control object. */ @@ -95,16 +113,19 @@ armadillo.PathControl.prototype.decorateInternal = function(element) { var path = '/'; goog.array.forEach(components, function (part, i) { - if (i != components.length - 1) { - this.addChild(this.createComponentNode_(path, part), true); - } else { - var input = new goog.ui.LabelInput(part, this.dom_); - this.addChild(input, true); - input.setEnabled(this.editableLastComponent_); - input.setValue(part); - } + this.addChild(this.createComponentNode_(path, part), true); path += part + '/'; }, this); + + if (this.editableLastComponent_) { + var input = new goog.ui.Control(this.dom_.createDom('input')); + input.getElement().value = this.name_; + this.addChild(input, true); + } else { + var label = new goog.ui.Control(this.name_); + this.addChild(label, true); + goog.dom.classes.add(label.getElement(), 'goog-inline-block'); + } }; /** @@ -169,4 +190,7 @@ armadillo.PathControl.prototype.fetchMenuContents_ = function(path, name, menu) */ armadillo.PathControl.prototype.componentChanged_ = function(e) { console.log(e.target.getValue()); + this.path_ = e.target.getValue(); + this.removeChildren(true); + this.decorateInternal(this.element_); }; -- 2.43.5