Separate the path from the name in PathComponent. First pass at updating the control.
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 4 Oct 2010 05:07:14 +0000 (01:07 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 4 Oct 2010 05:07:14 +0000 (01:07 -0400)
web_frontend/main.js
web_frontend/path_control.js

index 5ef1e141f19c633c246b87499dfbd67a7619c814..df72ec37ef5747e20a8a54f0b72e82a3becd2ca2 100644 (file)
@@ -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) {
index 38701a6e6f2233547b74891413c2767ba7c27d4f..dd863bc62be36a160647bcba4c3e0ece15f78b60 100644 (file)
@@ -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_);
 };