From 325af02867a9796f22bbaa73878d0f55d21841d3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 26 Dec 2011 17:01:51 -0500 Subject: [PATCH] Initial stab at rewriting path_control.js --- web_frontend/actor.js | 2 +- web_frontend/path_control.js | 62 ++++++++---------------------------- 2 files changed, 15 insertions(+), 49 deletions(-) diff --git a/web_frontend/actor.js b/web_frontend/actor.js index 222174f..86a9ea6 100644 --- a/web_frontend/actor.js +++ b/web_frontend/actor.js @@ -136,7 +136,7 @@ armadillo.Actor.prototype.tileClickHandler_ = function(option, e) { */ armadillo.Actor.prototype.performMove_ = function() { var editor = new armadillo.PathControl(this.file_.getFullPath(), true); - this.controlContainer_.append(editor.element_); + this.controlContainer_.append(editor.createDom()); var okCallback = function(e) { var newPath = editor.getPath(); diff --git a/web_frontend/path_control.js b/web_frontend/path_control.js index 8d705b2..7e4f792 100644 --- a/web_frontend/path_control.js +++ b/web_frontend/path_control.js @@ -8,7 +8,6 @@ // goog.provide('armadillo.PathControl'); -goog.provide('armadillo.PathControl.NameControlRenderer_'); goog.require('goog.array'); goog.require('goog.ui.Control'); @@ -27,9 +26,6 @@ goog.require('goog.ui.MenuItem'); armadillo.PathControl = function(path, editLastComponent, opt_domHelper) { goog.ui.Control.call(this, opt_domHelper); - this.setHandleMouseEvents(false); - this.setSupportedState(goog.ui.Component.State.FOCUSED, false); - /** * Full path of the control. * @type {string} @@ -104,14 +100,8 @@ armadillo.PathControl.prototype.getNameControl = function() { * Creates a new path control object. */ armadillo.PathControl.prototype.createDom = function() { - this.decorateInternal(this.dom_.createElement('div')); -}; - -/** - * @inheritDoc - */ -armadillo.PathControl.prototype.canDecorate = function() { - return true; + this.decorateInternal($.createDom('div')); + return this.element_; }; /** @@ -133,32 +123,25 @@ armadillo.PathControl.prototype.decorateInternal = function(element) { } var path = ''; - goog.array.forEach(components, function (part, i) { - this.addChild(this.createComponentNode_(path, part), true); + $.each(components, function (i, part) { + this.element_.append(this.createComponentNode_(path, part), true); path = app.joinPath(path, part); - }, this); + }.bind(this)); if (this.editableLastComponent_) { - var attrs = { + this.nameControl_ = $.createDom('input'); + this.nameControl_.attr({ 'type' : 'text', 'name' : 'pathName', 'value' : this.name_ - }; - this.nameControl_ = new goog.ui.Control(this.dom_.createDom('input', attrs), - new armadillo.PathControl.NameControlRenderer_()); - this.nameControl_.setAllowTextSelection(true); - this.nameControl_.setHandleMouseEvents(false); - this.addChild(this.nameControl_, true); + }); - this.eh_.listen(this.nameControl_.getElement(), goog.events.EventType.CHANGE, - this.nameChanged_, false, this); - this.eh_.listen(this.nameControl_.getElement(), goog.events.EventType.KEYDOWN, - this.nameChanged_, false, this); + this.nameControl_.bind('change keydown', this.nameChanged_.bind(this)); } else { - this.nameControl_ = new goog.ui.Control(this.name_); - this.addChild(this.nameControl_, true); + this.nameControl_ = $.createDom('span').text(this.name_); } - goog.dom.classes.add(this.nameControl_.getElement(), 'goog-inline-block'); + + this.element_.append(this.nameControl_); }; /** @@ -209,7 +192,7 @@ armadillo.PathControl.prototype.fetchMenuContents_ = function(path, name, menu) // moving items. goog.array.insertAt(data, '/', 0); } - goog.array.forEach(data, function (caption) { + $.each(data, function (i, caption) { // It only makes sense to be able to move into directories. if (!app.isDirectory(caption)) { return; @@ -231,7 +214,7 @@ armadillo.PathControl.prototype.fetchMenuContents_ = function(path, name, menu) */ armadillo.PathControl.prototype.componentChanged_ = function(e) { this.path_ = e.target.getValue(); - this.removeChildren(true); + this.element_.clear(); this.decorateInternal(this.element_); }; @@ -246,20 +229,3 @@ armadillo.PathControl.prototype.nameChanged_ = function(e) { e.stopPropagation(); return true; }; - -/** - * Renderer for the Name Control of the Path Control - * @constructor_ - */ -armadillo.PathControl.NameControlRenderer_ = function() { - goog.ui.ControlRenderer.call(this); -}; -goog.inherits(armadillo.PathControl.NameControlRenderer_, goog.ui.ControlRenderer); - -armadillo.PathControl.NameControlRenderer_.prototype.createDom = function(control) { - var content = control.getContent(); - if (content instanceof HTMLElement) { - return content; - } - return armadillo.PathControl.NameControlRenderer_.superClass_.createDom.call(this, control); -}; -- 2.43.5