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

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/browser/media/browser.js

  • Committer: David Coles
  • Date: 2009-12-02 00:12:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1327.
  • Revision ID: coles.david@gmail.com-20091202001223-qn4bn3uj16rg4qz8
Small refactor of browser's JavaScript to allow do_action to be called from 
other applications.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
135
135
 *      Defaults to "application/x-www-form-urlencoded".
136
136
 *      "multipart/form-data" is recommended for large uploads.
 
137
 * \param callback, optional.
 
138
 *      A callback function for after the action has been handled.
137
139
 */
138
 
function do_action(action, path, args, content_type, ignore_response)
 
140
function do_action(action, path, args, content_type, callback)
139
141
{
140
142
    args.action = action;
141
143
    /* Callback action, when the server returns */
142
 
    var callback = function(response)
 
144
    var callback_inner = function(response)
143
145
        {
144
146
            /* Check for action errors reported by the server, and report them
145
147
             * to the user */
149
151
                 * allow multi-line error messages. Decode */
150
152
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
151
153
            /* Now read the response and set up the page accordingly */
152
 
            if (ignore_response != true)
153
 
                handle_response(path, response, true);
 
154
            if (callback != null)
 
155
                callback(path, response);
154
156
        }
155
157
    /* Call the server and perform the action. This mutates the server. */
156
 
    ajax_call(callback, service_app, path, args, "POST", content_type);
 
158
    ajax_call(callback_inner, service_app, path, args, "POST", content_type);
157
159
}
158
160
 
159
161
/** Calls the server using Ajax, requesting a directory listing. This should
954
956
     * This causes the page to be populated with whatever is at that address,
955
957
     * whether it be a directory or a file.
956
958
     */
 
959
    var path = get_path();
 
960
    navigate(path);
 
961
}
 
962
 
 
963
/** Gets the current path of the window */
 
964
function get_path() {
957
965
    var path = parse_url(window.location.href).path;
958
966
    /* Strip out root_dir + "/files" from the front of the path */
959
967
    var strip = make_path(this_app);
976
984
        path = username;
977
985
    }
978
986
 
979
 
    navigate(path);
 
987
    return path;
980
988
}