46
39
"application/xml" : "text",
49
/* Mapping MIME types to icons, just the file's basename */
51
"text/directory": "dir.png",
52
"text/x-python": "py.png",
55
default_type_icon = "txt.png";
57
/* Relative to IVLE root */
58
type_icons_path = "media/images/mime";
59
type_icons_path_large = "media/images/mime/large";
61
/* Mapping SVN status to icons, just the file's basename */
64
"normal": "normal.png",
66
"missing": "missing.png",
67
"deleted": "deleted.png",
68
"modified": "modified.png",
71
/* Mapping SVN status to "nice" strings */
73
"unversioned": "Temporary file",
74
"normal": "Permanent file",
75
"added": "Temporary file (scheduled to be added)",
76
"missing": "Permanent file (missing)",
77
"deleted": "Permanent file (scheduled for deletion)",
78
"replaced": "Permanent file (replaced)",
79
"modified": "Permanent file (modified)",
80
"merged": "Permanent file (merged)",
81
"conflicted": "Permanent file (conflicted)",
84
default_svn_icon = null;
85
default_svn_nice = "Unknown status";
87
svn_icons_path = "media/images/svn";
89
42
/* List of MIME types considered "executable" by the system.
90
43
* Executable files offer a "run" link, implying that the "serve"
91
44
* application can interpret them.
139
87
* Called "navigate", can also be used for a simple refresh.
140
88
* Always makes a GET request.
141
89
* No return value.
142
* \param editmode Optional boolean. If true, then the user navigated here
143
* with an "edit" URL so we should favour using the editor.
145
function navigate(path, editmode)
91
function navigate(path)
147
93
/* Call the server and request the listing. This mutates the server. */
148
response = ajax_call(service_app, path, null, "GET");
94
response = ajax_call("fileservice", path, null, "GET");
149
95
/* Now read the response and set up the page accordingly */
150
handle_response(path, response, editmode);
153
/** Determines the "handler type" from a MIME type.
154
* The handler type is a string, either "text", "image", "audio" or "binary".
156
function get_handler_type(content_type)
160
if (content_type in type_handlers)
161
return type_handlers[content_type];
163
{ /* Based on the first part of the MIME type */
164
var handler_type = content_type.split('/')[0];
165
if (handler_type != "text" && handler_type != "image" &&
166
handler_type != "audio")
167
handler_type = "binary";
96
handle_response(path, response);
172
99
/** Given an HTTP response object, cleans up and rebuilds the contents of the
262
/** Deletes all "dynamic" content on the page.
263
* This returns the page back to the state it is in when the HTML arrives to
264
* the browser, ready for another handler to populate it.
268
dom_removechildren(document.getElementById("path"));
269
dom_removechildren(document.getElementById("filesbody"));
272
/** Deletes all "dynamic" content on the page necessary to navigate from
273
* one directory listing to another (does not clear as much as clearpage
275
* This is the equivalent of calling clearpage() then
276
* setup_for_dir_listing(), assuming the page is already on a dir listing.
278
function clearpage_dir()
280
dom_removechildren(document.getElementById("path"));
281
dom_removechildren(document.getElementById("files"));
282
dom_removechildren(document.getElementById("sidepanel"));
285
/** Sets the mode to either "file browser" or "text editor" mode.
286
* This modifies the window icon, and selected tab.
287
* \param editmode If True, editor mode. Else, file browser mode.
289
function setmode(editmode)
291
/* Find the DOM elements for the file browser and editor tabs */
292
var tabs = document.getElementById("apptabs");
293
var tab_files = null;
297
for (var i=0; i<tabs.childNodes.length; i++)
299
/* Find the href of the link within */
300
if (!tabs.childNodes[i].getElementsByTagName) continue;
301
a = tabs.childNodes[i].getElementsByTagName("a");
302
if (a.length == 0) continue;
303
href = a[0].getAttribute("href");
304
if (href == null) continue;
305
if (endswith(href, this_app))
306
tab_files = tabs.childNodes[i];
307
else if (endswith(href, edit_app))
308
tab_edit = tabs.childNodes[i];
313
tab_files.removeAttribute("class");
314
tab_edit.setAttribute("class", "thisapp");
318
tab_edit.removeAttribute("class");
319
tab_files.setAttribute("class", "thisapp");
323
176
/*** HANDLERS for different types of responses (such as dir listing, file,
326
179
function handle_error(message)
329
var files = document.getElementById("filesbody");
330
var txt_elem = dom_make_text_elem("div", "Error: "
331
+ message.toString() + ".")
332
txt_elem.setAttribute("class", "padding error");
333
files.appendChild(txt_elem);
336
/** Presents a path list (address bar inside the page) for clicking.
338
function presentpath(path)
340
var dom_path = document.getElementById("path");
341
var href_path = make_path(this_app);
345
/* Also set the document title */
346
document.title = path_basename(path) + " - IVLE";
347
/* Create all of the paths */
348
var pathlist = path.split("/");
349
for (var i=0; i<pathlist.length; i++)
352
if (dir == "") continue;
353
/* Make an 'a' element */
354
href_path = path_join(href_path, dir);
355
nav_path = path_join(nav_path, dir);
356
var link = dom_make_link_elem("a", dir, "Navigate to " + nav_path,
357
href_path/*, "navigate(" + repr(href_path) + ")"*/);
358
dom_path.appendChild(link);
359
dom_path.appendChild(document.createTextNode("/"));
361
dom_path.removeChild(dom_path.lastChild);
364
/** Given a mime type, returns the path to the icon.
365
* \param type String, Mime type.
366
* \param sizelarge Boolean, optional.
367
* \return Path to the icon. Has applied make_path, so it is relative to site
370
function mime_type_to_icon(type, sizelarge)
373
if (type in type_icons)
374
filename = type_icons[type];
376
filename = default_type_icon;
378
return make_path(path_join(type_icons_path_large, filename));
380
return make_path(path_join(type_icons_path, filename));
383
/** Given an svnstatus, returns the path to the icon.
384
* \param type String, svn status.
385
* \return Path to the icon. Has applied make_path, so it is relative to site
386
* root. May return null to indicate no SVN icon.
388
function svnstatus_to_icon(svnstatus)
391
if (svnstatus in svn_icons)
392
filename = svn_icons[svnstatus];
394
filename = default_svn_icon;
395
if (filename == null) return null;
396
return make_path(path_join(svn_icons_path, filename));
399
/** Given an svnstatus, returns the "nice" string.
401
function svnstatus_to_string(svnstatus)
403
if (svnstatus in svn_nice)
404
return svn_nice[svnstatus];
406
return default_svn_nice;
181
/* TODO: Rather than alert, rebuild the page into a page showing an error
183
alert("Error: " + message.toString() + ".");
186
/** Presents the directory listing.
188
function handle_dir_listing(path, listing)
194
/** Presents the text editor.
196
function handle_text(path, text)
409
202
/** Displays a download link to the binary file.
411
204
function handle_binary(path)
414
var files = document.getElementById("filesbody");
415
var div = document.createElement("div");
416
files.appendChild(div);
417
div.setAttribute("class", "padding");
418
var download_link = app_path(download_app, path);
419
var par1 = dom_make_text_elem("p",
420
"The file " + path + " is a binary file. To download this file, " +
421
"click the following link:");
422
var par2 = dom_make_link_elem("p",
423
"Download " + path, "Download " + path, download_link);
424
div.appendChild(par1);
425
div.appendChild(par2);
428
210
/** Called when the page loads initially.
430
212
window.onload = function()
432
/* Navigate (internally) to the path in the URL bar.
433
* This causes the page to be populated with whatever is at that address,
434
* whether it be a directory or a file.
436
var path = parse_url(window.location.href).path;
437
/* Strip out root_dir + "/files" from the front of the path */
438
var strip = make_path(this_app);
439
var editmode = false;
440
if (path.substr(0, strip.length) == strip)
441
path = path.substr(strip.length+1);
444
/* See if this is an edit path */
445
strip = make_path(edit_app);
446
if (path.substr(0, strip.length) == strip)
448
path = path.substr(strip.length+1);
453
if (path.length == 0)
455
/* Navigate to the user's home directory by default */
460
navigate(path, editmode);