2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
10 goog
.provide('armadillo.PathControl');
12 goog
.require('goog.ui.Component');
13 goog
.require('goog.ui.FilteredMenu');
14 goog
.require('goog.ui.LabelInput');
15 goog
.require('goog.ui.MenuButton');
16 goog
.require('goog.ui.MenuItem');
19 * Creates a new path editing control for a given path.
20 * @param {string} path The path to create an editor for
21 * @param {bool} editLastComponent Whether the last component should be shown as an edit box
22 * @param {DomHelper} opt_domHelper Optional DOM helper
25 armadillo
.PathControl
= function(path
, editLastComponent
, opt_domHelper
) {
26 goog
.ui
.Component
.call(this, opt_domHelper
);
29 * Full path of the control.
35 * Whether or not the last component is editable.
38 this.editableLastComponent_
= editLastComponent
;
41 * List of path components
44 this.components_
= new Array();
46 goog
.inherits(armadillo
.PathControl
, goog
.ui
.Component
);
52 armadillo
.PathControl
.prototype.disposeInternal
= function() {
53 armadillo
.PathControl
.superClass_
.disposeInternal
.call(this);
54 this.components_
= null;
58 * Creates a new path control object.
60 armadillo
.PathControl
.prototype.createDom
= function() {
61 this.decorateInternal(this.dom_
.createElement('div'));
67 armadillo
.PathControl
.prototype.canDecorate
= function() {
72 * Decorates the given element into a path control.
73 * @param {Element} element
75 armadillo
.PathControl
.prototype.decorateInternal
= function(element
) {
76 this.element_
= element
;
77 var components
= this.path_
.split('/');
78 delete components
[0]; // Don't create an empty item.
81 goog
.array
.forEach(components
, function (part
, i
) {
82 if (i
!= components
.length
- 1) {
83 this.addChild(this.createComponentNode_('/' + path
, part
), true);
85 var input
= new goog
.ui
.LabelInput(part
, this.dom_
);
86 this.addChild(input
, true);
87 input
.setEnabled(this.editableLastComponent_
);
95 * Creates a node for a single path component.
96 * @param {string} path The path up to this point.
97 * @param {string} name The current component after |path|.
99 armadillo
.PathControl
.prototype.createComponentNode_
= function(path
, name
) {
100 var menu
= new goog
.ui
.FilteredMenu();
101 menu
.setFilterLabel(name
);
102 menu
.setAllowMultiple(false);
103 this.fetchMenuContents_(path
, name
, menu
);
105 var button
= new goog
.ui
.MenuButton(name
, menu
, null, this.dom_
);
106 button
.setFocusablePopupMenu(true);
107 button
.setScrollOnOverflow(true);
108 button
.setVisible(true);
113 * Queries the back-end for all the items at a given path and attaches them to
115 * @param {string} path The path to get a list of items in
116 * @param {string} name The name to select
117 * @param {goog.ui.Menu} The menu to attach items to
119 armadillo
.PathControl
.prototype.fetchMenuContents_
= function(path
, name
, menu
) {
120 var callback
= function(e
) {
121 var data
= e
.target
.getResponseJson();
123 app
.showError(data
['message']);
126 goog
.array
.forEach(data
, function (caption
) {
127 var item
= new goog
.ui
.MenuItem(caption
);
129 if (caption
== name
) {
130 menu
.setHighlighted(item
);
134 app
.sendRequest('list', {'path':path
}, callback
);