85
85
var callback1 = function(xhr)
87
87
var json_text = xhr.responseText;
88
server_key = JSON.parse(json_text).key;
89
server_started = true;
90
server_key = JSON.parse(json_text).key;
91
server_started = true;
93
"ivle.op": "chat", "kind": "splash", "key": server_key
95
var callback2 = function(xhr)
97
console_response(null, null, xhr.responseText);
101
ajax_call(callback2, "console", "service", args, "POST");
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.")
111
$("#console_output").append(
112
'<span class="console_message">IVLE console starting up...</span>\n');
113
console_maximize(true);
95
115
callback1, "console", "service",
96
116
{"ivle.op": "start", "cwd": get_console_start_directory()},
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
124
function start_server_early()
126
var inputbox = document.getElementById("console_inputText");
127
inputbox.setAttribute("disabled", "disabled");
128
var callback = function(xhr)
130
inputbox.removeAttribute("disabled")
132
start_server(callback);
100
135
/** Initialises the console. All apps which import console are required to
101
136
* call this function.
102
137
* Optional "windowpane" (bool), if true, will cause the console to go into
124
159
function console_minimize()
126
161
if (!windowpane_mode) return;
127
console_body.setAttribute("class", "windowpane minimal");
162
console_body.setAttribute("class", "console_body windowpane minimal");
128
163
console_filler.setAttribute("class", "windowpane minimal");
131
166
/** Show the main console panel, so it enlarges out to its full size.
133
function console_maximize()
168
function console_maximize(do_not_start)
135
170
if (!windowpane_mode) return;
136
console_body.setAttribute("class", "windowpane maximal");
171
if (!do_not_start && !server_started) start_server_early();
172
console_body.setAttribute("class", "console_body windowpane maximal");
137
173
console_filler.setAttribute("class", "windowpane maximal");
285
324
span.setAttribute("class", "inputMsg");
286
325
span.appendChild(document.createTextNode(inputline));
287
326
output.appendChild(span);
327
divScroll.activeScroll();
290
330
"ivle.op": "chat", "kind": which, "key": server_key,
339
380
// Print a reason to explain why we'd do such a horrible thing
340
381
// (console timeout, server error etc.)
341
print_error("Console Restart: " + res.restart);
383
"IVLE console restarted: " + res.restart, "console_message");
343
385
// set the prompt to >>>
344
386
set_prompt(">>>");
373
416
ajax_call(callback, "console", "service", args, "POST");
375
418
// Open up the console so we can see the output
376
// FIXME: do we need to maximize here?
377
419
console_maximize();
380
divScroll.activeScroll();
382
421
// Return early, so we don't re-enable the input box.
424
else if (res.hasOwnProperty('input'))
387
// assert res.hasOwnProperty('input')
430
alert("An internal error occurred in the python console.");
391
434
if (inputbox != null)
494
535
/** Prints an error line in the console **/
495
function print_error(error)
536
function print_error(error, cls)
497
541
var output = document.getElementById("console_output");
499
543
// Create text block
500
544
var span = document.createElement("span");
501
span.setAttribute("class", "errorMsg");
545
span.setAttribute("class", cls);
502
546
span.appendChild(document.createTextNode(error + "\n"));
503
547
output.appendChild(span);