23
/** Calls the server using Ajax, performing an action on the server side.
24
* Receives the response from the server and performs a refresh of the page
25
* contents, updating it to display the returned data (such as a directory
26
* listing, file preview, or editor pane).
27
* Always makes a POST request.
30
* \param action String. Name of the action to perform, as defined in the
32
* \param path URL path to make the request to, within the application.
33
* \param args Argument object, as described in util.parse_url and friends.
34
* This should contain the arguments to the action, but NOT the action
35
* itself. (Also a minor side-effect; the "args" object will be mutated
36
* to include the action attribute).
37
* \param content_type String, optional.
38
* May be "application/x-www-form-urlencoded" or "multipart/form-data".
39
* Defaults to "application/x-www-form-urlencoded".
40
* "multipart/form-data" is recommended for large uploads.
42
function do_action(action, path, args, content_type)
45
/* Call the server and perform the action. This mutates the server. */
46
response = call_ajax("fileservice", path, args, "POST", content_type);
47
/* Check for action errors reported by the server, and report them to the
50
/* Now read the response and set up the page accordingly */
51
handle_response(path, response);
54
/** Calls the server using Ajax, requesting a directory listing. This should
55
* not modify the server in any way. Receives the response from the server and
56
* performs a refresh of the page contents, updating it to display the
57
* returned data (such as a directory listing, file preview, or editor pane).
58
* Called "navigate", can also be used for a simple refresh.
59
* Always makes a GET request.
62
function navigate(path)
64
/* Call the server and request the listing. This mutates the server. */
65
response = call_ajax("fileservice", path, null, "GET");
66
/* Now read the response and set up the page accordingly */
67
handle_response(path, response);
70
/** Given an HTTP response object, cleans up and rebuilds the contents of the
71
* page using the response data. This does not navigate away from the page, it
72
* merely rebuilds most of the data.
73
* Note that depending on the type of data returned, this could result in a
74
* directory listing, an image preview, an editor pane, etc.
75
* Figures out the type and calls the appropriate function.
76
* \param path URL path which the request was made for. This can (among other
77
* things) be used to update the URL in the location bar.
78
* \param response XMLHttpRequest object returned by the server. Should
79
* contain all the response data.
81
function handle_response(path, response)
23
85
/** Called when the page loads initially.
25
87
window.onload = function()