Create a new JS class for representing files in directory listings.
[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 };
35
36 /**
37 * Constructs the Elements that make up the UI.
38 * @returns {Element} An element ready for insertion into DOM.
39 */
40 armadillo.File.prototype.draw = function() {
41 if (!this.element_) {
42 this.element_ = goog.dom.createElement('li');
43 this.element_.representedObject = this;
44 }
45 goog.dom.removeChildren(this.element_);
46 goog.dom.setTextContent(this.element_, this.name_);
47 app.listeners_.push(goog.events.listen(this.element_,
48 goog.events.EventType.CLICK, app.clickHandler_, false, app));
49 return this.element_;
50 };