Basic directory listing on the web.
[armadillo.git] / web_frontend / main.js
1 goog.provide('armadillo');
2
3 goog.require('goog.array');
4 goog.require('goog.dom');
5 goog.require('goog.net.XhrIo');
6 goog.require('goog.Uri.QueryData');
7
8 armadillo.Main = function() {
9 armadillo.List('/');
10 };
11
12 /**
13 * Starts a new XHR service request from the backend.
14 * @param {string} action Action to perform.
15 * @param {Object} extra_data Extra data to add.
16 * @param {Function} callback XHR callback.
17 */
18 armadillo.Request = function(action, extra_data, callback) {
19 var data = new goog.Uri.QueryData();
20 data.set('action', 'list');
21 data.extend(extra_data);
22 goog.net.XhrIo.send('/service', callback, 'POST', data);
23 };
24
25 /**
26 * Updates the directory listing for a given path.
27 * @param {string} path Path to list; relative to jail.
28 */
29 armadillo.List = function(path) {
30 var callback = function(e) {
31 var data = e.target.getResponseJson();
32 if (data['status']) {
33 return; // Error.
34 }
35 goog.dom.setTextContent(goog.dom.getElement('pwd'), path);
36 var list = goog.dom.getElement('ls');
37 goog.dom.removeChildren(list);
38 goog.array.forEach(data, function(file) {
39 var elm = goog.dom.createElement('li');
40 goog.dom.setTextContent(elm, file);
41 goog.dom.appendChild(list, elm);
42 });
43 }
44 armadillo.Request('list', {'path':path}, callback);
45 };