~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/browser/browser.js

  • Committer: mattgiuca
  • Date: 2008-01-11 05:36:45 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:181
browser.js: Added functions do_action, navigate, handle_response (stubs).
Top-level functions for interacting with the server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Date: 11/1/2008
21
21
 */
22
22
 
 
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.
 
28
 * No return value.
 
29
 *
 
30
 * \param action String. Name of the action to perform, as defined in the
 
31
 *     fileservice API.
 
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.
 
41
 */
 
42
function do_action(action, path, args, content_type)
 
43
{
 
44
    args.action = action;
 
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
 
48
     * user */
 
49
    /* TODO */
 
50
    /* Now read the response and set up the page accordingly */
 
51
    handle_response(path, response);
 
52
}
 
53
 
 
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.
 
60
 * No return value.
 
61
 */
 
62
function navigate(path)
 
63
{
 
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);
 
68
}
 
69
 
 
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.
 
80
 */
 
81
function handle_response(path, response)
 
82
{
 
83
}
 
84
 
23
85
/** Called when the page loads initially.
24
86
 */
25
87
window.onload = function()