Move click handling into the File object.
[armadillo.git] / web_frontend / file.js
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
4 //
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.
8 //
9
10 goog.provide('armadillo.File');
11
12 goog.require('goog.Disposable');
13 goog.require('goog.dom');
14
15 /**
16 * A file in a directory listing.
17 * @param {string} File name.
18 * @constructor
19 */
20 armadillo.File = function(name) {
21 goog.Disposable.call(this);
22 this.name_ = name;
23 this.isDirectory_ = app.isDirectory(name);
24 };
25 goog.inherits(armadillo.File, goog.Disposable);
26
27 /**
28 * Disposer
29 * @protected
30 */
31 goog.Disposable.prototype.disposeInternal = function() {
32 armadillo.File.superClass_.disposeInternal.call(this);
33 this.element_ = null;
34 goog.events.unlistenByKey(this.clickListener_);
35 };
36
37 /**
38 * Constructs the Elements that make up the UI.
39 * @returns {Element} An element ready for insertion into DOM.
40 */
41 armadillo.File.prototype.draw = function() {
42 if (!this.element_) {
43 this.element_ = goog.dom.createElement('li');
44 this.element_.representedObject = this;
45 this.clickListener_ = goog.events.listen(this.element_,
46 goog.events.EventType.CLICK, this.clickHandler_, false, this);
47 }
48 goog.dom.removeChildren(this.element_);
49 goog.dom.setTextContent(this.element_, this.name_);
50 return this.element_;
51 };
52
53 /**
54 * Click handler for the ist element.
55 * @param {Event} e
56 */
57 armadillo.File.prototype.clickHandler_ = function(e) {
58 if (this.isDirectory_) {
59 app.navigate(this.name_);
60 }
61 };