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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-12-08 05:22:45 UTC
  • Revision ID: matt.giuca@gmail.com-20091208052245-04kgsqg1cva40iav
Added a script ivle-loadsampledata.
doc/man/sample: Instructions on using this script to load the sample data into
a fresh installation of IVLE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
    var callback1 = function(xhr)
86
86
        {
87
87
            var json_text = xhr.responseText;
88
 
            try
89
 
            {
90
 
                server_key = JSON.parse(json_text).key;
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");
102
 
            }
103
 
            catch (e)
104
 
            {
105
 
                alert("An error occured when starting the IVLE console. " +
106
 
                    "Please refresh the page and try again.\n" +
107
 
                    "Details have been logged for further examination.")
108
 
            }
 
88
            server_key = JSON.parse(json_text).key;
 
89
            server_started = true;
 
90
            if (callback != null)
 
91
                callback();
109
92
        }
110
93
 
111
 
    $("#console_output").append(
112
 
        '<span class="console_message">IVLE console starting up...</span>\n');
113
 
    console_maximize(true);
114
94
    ajax_call(
115
95
        callback1, "console", "service",
116
96
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
117
97
        "POST");
118
98
}
119
99
 
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
100
/** Initialises the console. All apps which import console are required to
136
101
 * call this function.
137
102
 * Optional "windowpane" (bool), if true, will cause the console to go into
159
124
function console_minimize()
160
125
{
161
126
    if (!windowpane_mode) return;
162
 
    console_body.setAttribute("class", "console_body windowpane minimal");
 
127
    console_body.setAttribute("class", "windowpane minimal");
163
128
    console_filler.setAttribute("class", "windowpane minimal");
164
129
}
165
130
 
166
131
/** Show the main console panel, so it enlarges out to its full size.
167
132
 */
168
 
function console_maximize(do_not_start)
 
133
function console_maximize()
169
134
{
170
135
    if (!windowpane_mode) return;
171
 
    if (!do_not_start && !server_started) start_server_early();
172
 
    console_body.setAttribute("class", "console_body windowpane maximal");
 
136
    console_body.setAttribute("class", "windowpane maximal");
173
137
    console_filler.setAttribute("class", "windowpane maximal");
174
138
}
175
139
 
295
259
{
296
260
    interrupted = false;
297
261
 
298
 
    // Open up the console so we can see the output
299
 
    console_maximize();
300
 
 
301
262
    if (typeof(inputbox) == "string")
302
263
    {
303
264
        var inputline = inputbox + "\n";
324
285
        span.setAttribute("class", "inputMsg");
325
286
        span.appendChild(document.createTextNode(inputline));
326
287
        output.appendChild(span);
327
 
        divScroll.activeScroll();
328
288
    }
329
289
    var args = {
330
290
        "ivle.op": "chat", "kind": which, "key": server_key,
356
316
        {
357
317
            output.appendChild(document.createTextNode(res.okay + "\n"));
358
318
            output.appendChild(span);
359
 
            divScroll.activeScroll();
360
319
        }
361
320
        // set the prompt to >>>
362
321
        set_prompt(">>>");
379
338
 
380
339
        // Print a reason to explain why we'd do such a horrible thing
381
340
        // (console timeout, server error etc.)
382
 
        print_error(
383
 
            "IVLE console restarted: " + res.restart, "console_message");
 
341
        print_error("Console Restart: " + res.restart);
384
342
        
385
343
        // set the prompt to >>>
386
344
        set_prompt(">>>");
395
353
        if (res.output.length > 0)
396
354
        {
397
355
            output.appendChild(document.createTextNode(res.output));
398
 
            divScroll.activeScroll();
399
356
        }
400
357
        var callback = function(xhr)
401
358
            {
416
373
        ajax_call(callback, "console", "service", args, "POST");
417
374
 
418
375
        // Open up the console so we can see the output
 
376
        // FIXME: do we need to maximize here?
419
377
        console_maximize();
420
378
 
 
379
        /* Auto-scrolling */
 
380
        divScroll.activeScroll();
 
381
 
421
382
        // Return early, so we don't re-enable the input box.
422
383
        return;
423
384
    }
424
 
    else if (res.hasOwnProperty('input'))
425
 
    {
426
 
        set_prompt("+++");
427
 
    }
428
385
    else
429
386
    {
430
 
        alert("An internal error occurred in the python console.");
431
 
        return;
 
387
        // assert res.hasOwnProperty('input')
 
388
        set_prompt("...");
432
389
    }
433
390
 
434
391
    if (inputbox != null)
438
395
        interrupted = false;
439
396
    }
440
397
 
 
398
    /* Open up the console so we can see the output */
 
399
    console_maximize();
441
400
    /* Auto-scrolling */
442
401
    divScroll.activeScroll();
443
402
 
533
492
}
534
493
 
535
494
/** Prints an error line in the console **/
536
 
function print_error(error, cls)
537
 
{
538
 
    if (!cls)
539
 
        cls = "errorMsg";
540
 
 
 
495
function print_error(error)
 
496
541
497
    var output = document.getElementById("console_output");
542
498
  
543
499
    // Create text block
544
500
    var span = document.createElement("span");
545
 
    span.setAttribute("class", cls);
 
501
    span.setAttribute("class", "errorMsg");
546
502
    span.appendChild(document.createTextNode(error + "\n"));
547
503
    output.appendChild(span);
548
504