~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-11 08:36:15 UTC
  • Revision ID: grantw@unimelb.edu.au-20100211083615-5imzir7px5dblvwk
divify the login form, fixing up the submit/error indentation while there.

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
 
                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");
 
92
                if (callback != null)
 
93
                    callback();
102
94
            }
103
95
            catch (e)
104
96
            {
108
100
            }
109
101
        }
110
102
 
111
 
    $("#console_output").append(
112
 
        '<span class="console_message">IVLE console starting up...</span>\n');
113
 
    console_maximize(true);
114
103
    ajax_call(
115
104
        callback1, "console", "service",
116
105
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
117
106
        "POST");
118
107
}
119
108
 
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
 
 
135
109
/** Initialises the console. All apps which import console are required to
136
110
 * call this function.
137
111
 * Optional "windowpane" (bool), if true, will cause the console to go into
159
133
function console_minimize()
160
134
{
161
135
    if (!windowpane_mode) return;
162
 
    console_body.setAttribute("class", "console_body windowpane minimal");
 
136
    console_body.setAttribute("class", "windowpane minimal");
163
137
    console_filler.setAttribute("class", "windowpane minimal");
164
138
}
165
139
 
166
140
/** Show the main console panel, so it enlarges out to its full size.
167
141
 */
168
 
function console_maximize(do_not_start)
 
142
function console_maximize()
169
143
{
170
144
    if (!windowpane_mode) return;
171
 
    if (!do_not_start && !server_started) start_server_early();
172
 
    console_body.setAttribute("class", "console_body windowpane maximal");
 
145
    console_body.setAttribute("class", "windowpane maximal");
173
146
    console_filler.setAttribute("class", "windowpane maximal");
174
147
}
175
148
 
295
268
{
296
269
    interrupted = false;
297
270
 
298
 
    // Open up the console so we can see the output
299
 
    console_maximize();
300
 
 
301
271
    if (typeof(inputbox) == "string")
302
272
    {
303
273
        var inputline = inputbox + "\n";
324
294
        span.setAttribute("class", "inputMsg");
325
295
        span.appendChild(document.createTextNode(inputline));
326
296
        output.appendChild(span);
327
 
        divScroll.activeScroll();
328
297
    }
329
298
    var args = {
330
299
        "ivle.op": "chat", "kind": which, "key": server_key,
356
325
        {
357
326
            output.appendChild(document.createTextNode(res.okay + "\n"));
358
327
            output.appendChild(span);
359
 
            divScroll.activeScroll();
360
328
        }
361
329
        // set the prompt to >>>
362
330
        set_prompt(">>>");
379
347
 
380
348
        // Print a reason to explain why we'd do such a horrible thing
381
349
        // (console timeout, server error etc.)
382
 
        print_error(
383
 
            "IVLE console restarted: " + res.restart, "console_message");
 
350
        print_error("Console Restart: " + res.restart);
384
351
        
385
352
        // set the prompt to >>>
386
353
        set_prompt(">>>");
395
362
        if (res.output.length > 0)
396
363
        {
397
364
            output.appendChild(document.createTextNode(res.output));
398
 
            divScroll.activeScroll();
399
365
        }
400
366
        var callback = function(xhr)
401
367
            {
416
382
        ajax_call(callback, "console", "service", args, "POST");
417
383
 
418
384
        // Open up the console so we can see the output
 
385
        // FIXME: do we need to maximize here?
419
386
        console_maximize();
420
387
 
 
388
        /* Auto-scrolling */
 
389
        divScroll.activeScroll();
 
390
 
421
391
        // Return early, so we don't re-enable the input box.
422
392
        return;
423
393
    }
424
 
    else if (res.hasOwnProperty('input'))
425
 
    {
426
 
        set_prompt("+++");
427
 
    }
428
394
    else
429
395
    {
430
 
        alert("An internal error occurred in the python console.");
431
 
        return;
 
396
        // assert res.hasOwnProperty('input')
 
397
        set_prompt("...");
432
398
    }
433
399
 
434
400
    if (inputbox != null)
438
404
        interrupted = false;
439
405
    }
440
406
 
 
407
    /* Open up the console so we can see the output */
 
408
    console_maximize();
441
409
    /* Auto-scrolling */
442
410
    divScroll.activeScroll();
443
411
 
533
501
}
534
502
 
535
503
/** Prints an error line in the console **/
536
 
function print_error(error, cls)
537
 
{
538
 
    if (!cls)
539
 
        cls = "errorMsg";
540
 
 
 
504
function print_error(error)
 
505
541
506
    var output = document.getElementById("console_output");
542
507
  
543
508
    // Create text block
544
509
    var span = document.createElement("span");
545
 
    span.setAttribute("class", cls);
 
510
    span.setAttribute("class", "errorMsg");
546
511
    span.appendChild(document.createTextNode(error + "\n"));
547
512
    output.appendChild(span);
548
513