1 goog
.provide('armadillo');
3 goog
.require('goog.array');
4 goog
.require('goog.dom');
5 goog
.require('goog.net.XhrIo');
6 goog
.require('goog.Uri.QueryData');
8 armadillo
= function() {
10 this.listeners_
= new Array();
14 * Starts a new XHR service request from the backend.
15 * @param {string} action Action to perform.
16 * @param {Object} extra_data Extra data to add.
17 * @param {Function} callback XHR callback.
19 armadillo
.prototype.sendRequest_
= function(action
, extra_data
, callback
) {
20 var data
= new goog
.Uri
.QueryData();
21 data
.set('action', 'list');
22 data
.extend(extra_data
);
23 goog
.net
.XhrIo
.send('/service', callback
, 'POST', data
);
27 * Updates the directory listing for a given path.
28 * @param {string} path Path to list; relative to jail.
30 armadillo
.prototype.list
= function(path
) {
31 var callback
= function(e
) {
32 var data
= e
.target
.getResponseJson();
36 // Unlisten all current listeners.
37 goog
.array
.forEach(app
.listeners_
, function(e
) {
38 goog
.events
.unlistenByKey(e
);
41 // Update the listing.
42 goog
.dom
.setTextContent(goog
.dom
.getElement('pwd'), path
);
43 var list
= goog
.dom
.getElement('ls');
44 goog
.dom
.removeChildren(list
);
46 // Add items for each entry.
47 goog
.array
.forEach(data
, function(file
) {
48 var elm
= goog
.dom
.createElement('li');
49 goog
.dom
.setTextContent(elm
, file
);
50 goog
.dom
.appendChild(list
, elm
);
51 app
.listeners_
.push(goog
.events
.listen(elm
,
52 goog
.events
.EventType
.CLICK
, app
.clickHandler_
, false, app
));
55 this.sendRequest_('list', {'path':path
}, callback
);
59 * Click handler for elements.
62 armadillo
.prototype.clickHandler_
= function(e
) {
63 if (this.isDirectory_(goog
.dom
.getTextContent(e
.target
))) {
64 alert('this is a dir');
69 * Checks whether a path is a directory.
70 * @param {string} path
73 armadillo
.prototype.isDirectory_
= function(path
) {
74 return path
[path
.length
- 1] == '/';