]>
src.bluestatic.org Git - armadillo.git/blob - web_frontend/file.js
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.File');
12 goog
.require('armadillo.Actor');
13 goog
.require('goog.Disposable');
14 goog
.require('goog.dom');
15 goog
.require('goog.ui.AnimatedZippy');
18 * A file in a directory listing.
19 * @param {string} File name.
20 * @param {string} The path the file resides at.
23 armadillo
.File = function(name
, path
) {
24 goog
.Disposable
.call(this);
28 this.isDirectory_
= app
.isDirectory(name
);
29 this.actor_
= new armadillo
.Actor(this);
32 goog
.inherits(armadillo
.File
, goog
.Disposable
);
34 armadillo
.File
.Highlight
= {
36 SELECTED : 'file-selected',
37 ACTIVE : 'file-active'
44 armadillo
.File
.prototype.disposeInternal = function() {
45 armadillo
.File
.superClass_
.disposeInternal
.call(this);
48 goog
.events
.unlistenByKey(this.linkListener_
);
49 goog
.events
.unlistenByKey(this.actorListener_
);
50 this.actor_
.dispose();
52 this.zippy_
.dispose();
56 * Returns the name of the file.
59 armadillo
.File
.prototype.getName = function() {
64 * Returns the path the file without the name. This is equivalent to calling
65 * dirname on the absolute path.
68 armadillo
.File
.prototype.getParentPath = function() {
73 * Gets the fully qualified path of the file, from the root of the jail to the
77 armadillo
.File
.prototype.getFullPath = function() {
78 return this.path_
+ this.name_
;
82 * Returns whether or not this is a directory.
85 armadillo
.File
.prototype.isDirectory = function() {
86 return this.isDirectory_
;
90 * Sets the highlight state.
92 armadillo
.File
.prototype.setHighlight = function(h
) {
95 goog.dom.classes.addRemove(this.element_, this.highlight_, h);
101 * Constructs the Elements that make up the UI.
102 * @returns {Element} An element ready for insertion into DOM.
104 armadillo
.File
.prototype.draw = function() {
105 // Create the element if it does not exist. If it does, remove all children.
106 if (!this.element_
) {
107 this.element_
= goog
.dom
.createElement('li');
108 this.element_
.representedObject
= this;
109 var handler
= (this.isSpecial_() ? this.clickHandler_ : this.actorHandler_
);
111 goog
.dom
.removeChildren(this.element_
);
113 // Set the name of the entry.
114 this.title_
= goog
.dom
.createDom('div', null);
115 if (this.isDirectory()) {
116 this.link_
= goog
.dom
.createDom('a', null, this.name_
);
117 this.linkListener_
= goog
.events
.listen(this.link_
,
118 goog
.events
.EventType
.CLICK
, this.clickHandler_
, false, this);
119 goog
.dom
.appendChild(this.title_
, this.link_
);
121 goog
.dom
.setTextContent(this.title_
, this.name_
);
123 goog
.dom
.appendChild(this.element_
, this.title_
);
124 this.actorListener_
= goog
.events
.listen(this.title_
,
125 goog
.events
.EventType
.CLICK
, handler
, false, this);
127 return this.element_
;
131 * Deletes the given file in the backend by sending a request. On return, it
132 * will re-query the directory.
134 armadillo
.File
.prototype.remove = function() {
136 var callback = function(data
) {
138 app
.showError(data
['message']);
143 app
.list(file
.path_
);
145 app
.sendRequest('remove', {'path':this.path_
+ this.name_
}, callback
);
149 * Moves a file from one absolute path to another. On success, it will navigate
151 * @param {string} dest The destination path.
153 armadillo
.File
.prototype.move = function(dest
) {
155 var callback = function(data
) {
157 app
.showError(data
['message']);
160 app
.list(app
.stripLastPathComponent(dest
));
163 app
.sendRequest('move', {'source':this.getFullPath(), 'target':dest
}, callback
);
167 * Click handler for the link element; only for directories.
170 armadillo
.File
.prototype.clickHandler_ = function(e
) {
171 if (this.isDirectory_
) {
172 app
.navigate(this.name_
);
178 * Click handler for the row, which brings up the Actor interface.
181 armadillo
.File
.prototype.actorHandler_ = function(e
) {
183 if (!this.actor_
.isInDocument())
184 this.actor_
.render(this.element_
);
186 this.zippy_
= new goog
.ui
.AnimatedZippy(this.title_
,
187 this.actor_
.getElement(), false);
188 this.zippy_
.toggle();
193 * Returns TRUE if this File is not a real file, but a special kind.
196 armadillo
.File
.prototype.isSpecial_ = function() {
197 return this.name_
== '../';