~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-07-27 12:09:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1826.
  • Revision ID: grantw@unimelb.edu.au-20100727120913-v0kfnwxzbiwrjnue
(simple)json always returns a unicode when decoding, while cjson returned a str where possible. This makes cPickle unhappy, so convert back to a str.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
            {
90
90
                server_key = JSON.parse(json_text).key;
91
91
                server_started = true;
92
 
                if (callback != null)
93
 
                    callback();
 
92
                var args = {
 
93
                    "ivle.op": "chat", "kind": "splash", "key": server_key
 
94
                };
 
95
                var callback2 = function(xhr)
 
96
                {
 
97
                    console_response(null, null, xhr.responseText);
 
98
                    if (callback != null)
 
99
                        callback();
 
100
                };
 
101
                ajax_call(callback2, "console", "service", args, "POST");
94
102
            }
95
103
            catch (e)
96
104
            {
100
108
            }
101
109
        }
102
110
 
 
111
    $("#console_output").append(
 
112
        '<span class="console_message">IVLE console starting up...</span>\n');
 
113
    console_maximize(true);
103
114
    ajax_call(
104
115
        callback1, "console", "service",
105
116
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
106
117
        "POST");
107
118
}
108
119
 
 
120
/** Start up the console backend before the user has entered text.
 
121
 * This will disable the text input, start a backend, and enable the input
 
122
 * again.
 
123
 */
 
124
function start_server_early()
 
125
{
 
126
    var inputbox = document.getElementById("console_inputText");
 
127
    inputbox.setAttribute("disabled", "disabled");
 
128
    var callback = function(xhr)
 
129
    {
 
130
        inputbox.removeAttribute("disabled")
 
131
    }
 
132
    start_server(callback);
 
133
}
 
134
 
109
135
/** Initialises the console. All apps which import console are required to
110
136
 * call this function.
111
137
 * Optional "windowpane" (bool), if true, will cause the console to go into
139
165
 
140
166
/** Show the main console panel, so it enlarges out to its full size.
141
167
 */
142
 
function console_maximize()
 
168
function console_maximize(do_not_start)
143
169
{
144
170
    if (!windowpane_mode) return;
 
171
    if (!do_not_start && !server_started) start_server_early();
145
172
    console_body.setAttribute("class", "console_body windowpane maximal");
146
173
    console_filler.setAttribute("class", "windowpane maximal");
147
174
}
268
295
{
269
296
    interrupted = false;
270
297
 
 
298
    // Open up the console so we can see the output
 
299
    console_maximize();
 
300
 
271
301
    if (typeof(inputbox) == "string")
272
302
    {
273
303
        var inputline = inputbox + "\n";
294
324
        span.setAttribute("class", "inputMsg");
295
325
        span.appendChild(document.createTextNode(inputline));
296
326
        output.appendChild(span);
 
327
        divScroll.activeScroll();
297
328
    }
298
329
    var args = {
299
330
        "ivle.op": "chat", "kind": which, "key": server_key,
325
356
        {
326
357
            output.appendChild(document.createTextNode(res.okay + "\n"));
327
358
            output.appendChild(span);
 
359
            divScroll.activeScroll();
328
360
        }
329
361
        // set the prompt to >>>
330
362
        set_prompt(">>>");
347
379
 
348
380
        // Print a reason to explain why we'd do such a horrible thing
349
381
        // (console timeout, server error etc.)
350
 
        print_error("Console Restart: " + res.restart);
 
382
        print_error(
 
383
            "IVLE console restarted: " + res.restart, "console_message");
351
384
        
352
385
        // set the prompt to >>>
353
386
        set_prompt(">>>");
362
395
        if (res.output.length > 0)
363
396
        {
364
397
            output.appendChild(document.createTextNode(res.output));
 
398
            divScroll.activeScroll();
365
399
        }
366
400
        var callback = function(xhr)
367
401
            {
382
416
        ajax_call(callback, "console", "service", args, "POST");
383
417
 
384
418
        // Open up the console so we can see the output
385
 
        // FIXME: do we need to maximize here?
386
419
        console_maximize();
387
420
 
388
 
        /* Auto-scrolling */
389
 
        divScroll.activeScroll();
390
 
 
391
421
        // Return early, so we don't re-enable the input box.
392
422
        return;
393
423
    }
408
438
        interrupted = false;
409
439
    }
410
440
 
411
 
    /* Open up the console so we can see the output */
412
 
    console_maximize();
413
441
    /* Auto-scrolling */
414
442
    divScroll.activeScroll();
415
443
 
505
533
}
506
534
 
507
535
/** Prints an error line in the console **/
508
 
function print_error(error)
509
 
 
536
function print_error(error, cls)
 
537
{
 
538
    if (!cls)
 
539
        cls = "errorMsg";
 
540
 
510
541
    var output = document.getElementById("console_output");
511
542
  
512
543
    // Create text block
513
544
    var span = document.createElement("span");
514
 
    span.setAttribute("class", "errorMsg");
 
545
    span.setAttribute("class", cls);
515
546
    span.appendChild(document.createTextNode(error + "\n"));
516
547
    output.appendChild(span);
517
548