~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-06-23 12:04:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:789
browser.js: Replaced the old "The server returned an invalid directory
    listing" error (which is an unexpected error but we see it all the time
    for one reason or another) with a more helpful screen which differs based
    on whether an action or a listing is being requested, and provides
    suggestions to the user and a refresh button (so it is clear to click the
    refresh button and move on, rather than just "it broke").

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
                alert("Error: " + decodeURIComponent(error.toString()) + ".");
149
149
            /* Now read the response and set up the page accordingly */
150
150
            if (ignore_response != true)
151
 
                handle_response(path, response);
 
151
                handle_response(path, response, true);
152
152
        }
153
153
    /* Call the server and perform the action. This mutates the server. */
154
154
    ajax_call(callback, service_app, path, args, "POST", content_type);
167
167
    callback = function(response)
168
168
        {
169
169
            /* Read the response and set up the page accordingly */
170
 
            handle_response(path, response, url.args);
 
170
            handle_response(path, response, false, url.args);
171
171
        }
172
172
    /* Get any query strings */
173
173
    url = parse_url(window.location.href);
213
213
 * things) be used to update the URL in the location bar.
214
214
 * \param response XMLHttpRequest object returned by the server. Should
215
215
 * contain all the response data.
 
216
 * \param is_action Boolean. True if this is the response to an action, false
 
217
 * if this is the response to a simple listing. This is used in handling the
 
218
 * error.
216
219
 * \param url_args Arguments dict, for the arguments passed to the URL
217
220
 * in the browser's address bar (will be forwarded along).
218
221
 */
219
 
function handle_response(path, response, url_args)
 
222
function handle_response(path, response, is_action, url_args)
220
223
{
221
224
    /* TODO: Set location bar to "path" */
222
225
    current_path = path;
246
249
    }
247
250
    catch (e)
248
251
    {
249
 
        handle_error("The server returned an invalid directory listing");
 
252
        if (is_action)
 
253
        {
 
254
            var err = document.createElement("div");
 
255
            var p = dom_make_text_elem("p", "Error: "
 
256
                    + "There was an unexpected server error processing "
 
257
                    + "the selected command.");
 
258
            err.appendChild(p);
 
259
            p = dom_make_text_elem("p", "If the problem persists, please "
 
260
                    + "contact the system administrator.")
 
261
            err.appendChild(p);
 
262
            p = document.createElement("p");
 
263
            var refresh = document.createElement("input");
 
264
            refresh.setAttribute("type", "button");
 
265
            refresh.setAttribute("value", "Back to file view");
 
266
            refresh.setAttribute("onclick", "refresh()");
 
267
            p.appendChild(refresh);
 
268
            err.appendChild(p);
 
269
            handle_error(err);
 
270
        }
 
271
        else
 
272
        {
 
273
            var err = document.createElement("div");
 
274
            var p = dom_make_text_elem("p", "Error: "
 
275
                    + "There was an unexpected server error retrieving "
 
276
                    + "the requested file or directory.");
 
277
            err.appendChild(p);
 
278
            p = dom_make_text_elem("p", "If the problem persists, please "
 
279
                    + "contact the system administrator.")
 
280
            err.appendChild(p);
 
281
            handle_error(err);
 
282
        }
250
283
        return;
251
284
    }
252
285
    /* Get "." out, it's special */
353
386
/*** HANDLERS for different types of responses (such as dir listing, file,
354
387
 * etc). */
355
388
 
 
389
/* handle_error.
 
390
 * message may either be a string, or a DOM node, which will be placed inside
 
391
 * a div.
 
392
 */
356
393
function handle_error(message)
357
394
{
358
395
    var files = document.getElementById("filesbody");
359
 
    var txt_elem = dom_make_text_elem("div", "Error: "
360
 
        + message.toString() + ".")
 
396
    var txt_elem;
 
397
    if (typeof(message) == "string")
 
398
    {
 
399
        txt_elem = dom_make_text_elem("div", "Error: "
 
400
                   + message.toString() + ".")
 
401
    }
 
402
    else
 
403
    {
 
404
        /* Assume message is a DOM node */
 
405
        txt_elem = document.createElement("div");
 
406
        txt_elem.appendChild(message);
 
407
    }
361
408
    txt_elem.setAttribute("class", "padding error");
362
409
    files.appendChild(txt_elem);
363
410
}