~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: 2009-04-29 04:58:42 UTC
  • Revision ID: grantw@unimelb.edu.au-20090429045842-upijb1ybcbz1zg6u
Kill --nosvnrevno from setup.install - we don't use Subversion now.

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
 
 
66
39
/* Starts the console server, if it isn't already.
67
40
 * This can be called any number of times - it only starts the one server.
68
41
 * Note that this is asynchronous. It will return after signalling to start
85
58
    var callback1 = function(xhr)
86
59
        {
87
60
            var json_text = xhr.responseText;
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
 
            }
 
61
            server_key = JSON.parse(json_text).key;
 
62
            server_started = true;
 
63
            if (callback != null)
 
64
                callback();
101
65
        }
102
66
 
103
 
    ajax_call(
104
 
        callback1, "console", "service",
105
 
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
106
 
        "POST");
 
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
    }
107
91
}
108
92
 
109
93
/** Initialises the console. All apps which import console are required to
295
279
        span.appendChild(document.createTextNode(inputline));
296
280
        output.appendChild(span);
297
281
    }
298
 
    var args = {
299
 
        "ivle.op": "chat", "kind": which, "key": server_key,
300
 
        "text": inputline, "cwd": get_console_start_directory()
301
 
        };
 
282
    var args = {"ivle.op": "chat", "kind": which, "key": server_key, "text":inputline};
302
283
    var callback = function(xhr)
303
284
        {
304
285
            console_response(inputbox, inputline, xhr.responseText);
375
356
        {
376
357
            var kind = "chat";
377
358
        }
378
 
        var args = {
379
 
            "ivle.op": "chat", "kind": kind, "key": server_key,
380
 
            "text": '', "cwd": get_console_start_directory()
381
 
            };
 
359
        var args = {"ivle.op": "chat", "kind": kind, "key": server_key, "text":''};
382
360
        ajax_call(callback, "console", "service", args, "POST");
383
361
 
384
362
        // Open up the console so we can see the output
456
434
            hist.submit(inp.value);
457
435
            inp.value = hist.curr();
458
436
        }
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");
465
437
        /* Start the server if it hasn't already been started */
466
438
        start_server(callback);
467
439
        break;
468
440
    case 38:                /* Up arrow */
469
441
        hist.up(inp.value);
470
442
        inp.value = hist.curr();
471
 
        /* Inhibit further responses to this event, or WebKit moves the
472
 
         * cursor to the start. */
473
 
        return false;
474
443
        break;
475
444
    case 40:                /* Down arrow */
476
445
        hist.down(inp.value);
477
446
        inp.value = hist.curr();
478
 
        return false;
479
447
        break;
480
448
    }
481
449
}
495
463
    }
496
464
    else
497
465
    {
498
 
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key, "cwd": get_console_start_directory()}, "POST");
 
466
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key}, "POST");
499
467
        console_response(null, null, xhr.responseText);
500
468
    }
501
469
}