180
/** Deletes all "dynamic" content on the page.
181
* This returns the page back to the state it is in when the HTML arrives to
182
* the browser, ready for another handler to populate it.
186
/* Note: For now clear just enough to repopulate with a dir listing.
187
* Later, will have to clear more to make way for other handlers.
188
* Possibly have a "full clear" for all handlers, and special
189
* less-violent clearers for each handler if the same handler is going to
190
* be used that was used last time. */
191
dom_removechildren(document.getElementById("path"));
192
dom_removechildren(document.getElementById("files"));
193
dom_removechildren(document.getElementById("sidepanel"));
176
196
/*** HANDLERS for different types of responses (such as dir listing, file,
179
199
function handle_error(message)
181
/* TODO: Rather than alert, rebuild the page into a page showing an error
183
alert("Error: " + message.toString() + ".");
201
/* TODO: Find a better place to put this message. */
202
var msg_elem = document.getElementById("path");
203
var txt_elem = dom_make_text_elem("span", "Error: "
204
+ message.toString() + ".")
205
txt_elem.setAttribute("class", "error");
206
msg_elem.appendChild(txt_elem)
209
/** Presents a path list (address bar inside the page) for clicking.
212
function presentpath(path)
214
var dom_path = document.getElementById("path");
216
var href_path = make_path(this_app);
218
/* Create all of the paths */
219
for each (dir in path.split("/"))
221
if (dir == "") continue;
223
/* Make an 'a' element */
224
href_path = path_join(href_path, dir);
225
var link = dom_make_link_elem("a", dir, href_path,
226
"navigate(" + href_path + ")");
227
dom_path.appendChild(link);
228
dom_path.appendChild(document.createTextNode("/"));
186
232
/** Presents the directory listing.
188
234
function handle_dir_listing(path, listing)
238
/* Nav through the top-level of the JSON to the actual listing object. */
239
var listing = listing.listing;
241
/* Get "." out, it's special */
242
var thisdir = listing["."];
244
/* Is this dir under svn? */
245
var under_subversion = "svnstatus" in thisdir;
247
var files = document.getElementById("files");
253
/* Create all of the files */
254
for (var filename in listing)
256
file = listing[filename];
257
/* Make a 'tr' element */
258
row = document.createElement("tr");
259
/* Column 1: Selection checkbox */
260
row.setAttribute("class", "row" + row_toggle.toString())
261
row_toggle = row_toggle == 1 ? 2 : 1;
262
td = document.createElement("td");
263
checkbox = document.createElement("input");
264
checkbox.setAttribute("type", "checkbox");
265
checkbox.setAttribute("title", "Select this file");
266
td.appendChild(checkbox);
270
/* Column 2: Filetype and subversion icons. */
271
td = document.createElement("td");
272
td.setAttribute("class", "thincol");
273
td.appendChild(document.createTextNode("dir"));
275
td = document.createElement("td");
276
td.setAttribute("class", "thincol");
277
if (under_subversion)
278
td.appendChild(document.createTextNode(file.svnstatus));
280
/* Column 3: Filename */
281
row.appendChild(dom_make_link_elem("td", filename,
282
make_path(path_join(this_app, path, filename)),
283
"navigate(" + path_join(path, filename) + ")"));
287
/* Column 2: Filetype and subversion icons. */
288
td = document.createElement("td");
289
td.setAttribute("class", "thincol");
290
td.appendChild(document.createTextNode(file.type));
292
td = document.createElement("td");
293
td.setAttribute("class", "thincol");
294
if (under_subversion)
295
td.appendChild(document.createTextNode(file.svnstatus));
297
/* Column 3: Filename */
298
row.appendChild(dom_make_text_elem("td", filename));
301
row.appendChild(dom_make_text_elem("td", nice_filesize(file.size)));
303
row.appendChild(dom_make_text_elem("td", file.mtime_nice));
304
files.appendChild(row);
194
309
/** Presents the text editor.