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

« back to all changes in this revision

Viewing changes to ivle/webapp/console/media/console.js

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
interrupted = false;
38
38
 
 
39
 
 
40
function get_console_start_directory()
 
41
{
 
42
    if((typeof(current_path) != 'undefined') && current_file)
 
43
    {
 
44
        // We have a current_path - give a suggestion to the server
 
45
        var path;
 
46
        if (current_file.isdir)
 
47
        {
 
48
            // Browser
 
49
            return path_join("/home", current_path);
 
50
        }
 
51
        else
 
52
        {
 
53
            // Editor - need to chop off filename
 
54
            var tmp_path = current_path.split('/');
 
55
            tmp_path.pop();
 
56
            return path_join("/home", tmp_path.join('/'));
 
57
        }
 
58
    }
 
59
    else
 
60
    {
 
61
        // No current_path - let the server decide
 
62
        return '';
 
63
    }
 
64
}
 
65
 
39
66
/* Starts the console server, if it isn't already.
40
67
 * This can be called any number of times - it only starts the one server.
41
68
 * Note that this is asynchronous. It will return after signalling to start
58
85
    var callback1 = function(xhr)
59
86
        {
60
87
            var json_text = xhr.responseText;
61
 
            server_key = JSON.parse(json_text).key;
62
 
            server_started = true;
63
 
            if (callback != null)
64
 
                callback();
 
88
            try
 
89
            {
 
90
                server_key = JSON.parse(json_text).key;
 
91
                server_started = true;
 
92
                if (callback != null)
 
93
                    callback();
 
94
            }
 
95
            catch (e)
 
96
            {
 
97
                alert("An error occured when starting the IVLE console. " +
 
98
                    "Please refresh the page and try again.\n" +
 
99
                    "Details have been logged for further examination.")
 
100
            }
65
101
        }
66
102
 
67
 
    //var current_path;
68
 
    if((typeof(current_path) != 'undefined') && current_file)
69
 
    {
70
 
        // We have a current_path - give a suggestion to the server
71
 
        var path;
72
 
        if (current_file.isdir)
73
 
        {
74
 
            // Browser
75
 
            path = path_join("/home", current_path);
76
 
        }
77
 
        else
78
 
        {
79
 
            // Editor - need to chop off filename
80
 
            var tmp_path = current_path.split('/');
81
 
            tmp_path.pop();
82
 
            path = path_join("/home", tmp_path.join('/'));
83
 
        }
84
 
        ajax_call(callback1, "console", "service", {"ivle.op": "start", "cwd": path}, "POST");
85
 
    }
86
 
    else
87
 
    {
88
 
        // No current_path - let the server decide
89
 
        ajax_call(callback1, "console", "service", {"ivle.op": "start"}, "POST");
90
 
    }
 
103
    ajax_call(
 
104
        callback1, "console", "service",
 
105
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
 
106
        "POST");
91
107
}
92
108
 
93
109
/** Initialises the console. All apps which import console are required to
279
295
        span.appendChild(document.createTextNode(inputline));
280
296
        output.appendChild(span);
281
297
    }
282
 
    var args = {"ivle.op": "chat", "kind": which, "key": server_key, "text":inputline};
 
298
    var args = {
 
299
        "ivle.op": "chat", "kind": which, "key": server_key,
 
300
        "text": inputline, "cwd": get_console_start_directory()
 
301
        };
283
302
    var callback = function(xhr)
284
303
        {
285
304
            console_response(inputbox, inputline, xhr.responseText);
356
375
        {
357
376
            var kind = "chat";
358
377
        }
359
 
        var args = {"ivle.op": "chat", "kind": kind, "key": server_key, "text":''};
 
378
        var args = {
 
379
            "ivle.op": "chat", "kind": kind, "key": server_key,
 
380
            "text": '', "cwd": get_console_start_directory()
 
381
            };
360
382
        ajax_call(callback, "console", "service", args, "POST");
361
383
 
362
384
        // Open up the console so we can see the output
434
456
            hist.submit(inp.value);
435
457
            inp.value = hist.curr();
436
458
        }
 
459
 
 
460
        /* Disable the text box. This will be redone by
 
461
         * console_enter_line, but we do it here too in case start_server
 
462
         * takes a while.
 
463
         */
 
464
        inp.setAttribute("disabled", "disabled");
437
465
        /* Start the server if it hasn't already been started */
438
466
        start_server(callback);
439
467
        break;
440
468
    case 38:                /* Up arrow */
441
469
        hist.up(inp.value);
442
470
        inp.value = hist.curr();
 
471
        /* Inhibit further responses to this event, or WebKit moves the
 
472
         * cursor to the start. */
 
473
        return false;
443
474
        break;
444
475
    case 40:                /* Down arrow */
445
476
        hist.down(inp.value);
446
477
        inp.value = hist.curr();
 
478
        return false;
447
479
        break;
448
480
    }
449
481
}
463
495
    }
464
496
    else
465
497
    {
466
 
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key}, "POST");
 
498
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key, "cwd": get_console_start_directory()}, "POST");
467
499
        console_response(null, null, xhr.responseText);
468
500
    }
469
501
}