85
85
var callback1 = function(xhr)
87
87
var json_text = xhr.responseText;
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.")
88
server_key = JSON.parse(json_text).key;
89
server_started = true;
111
$("#console_output").append(
112
'<span class="console_message">IVLE console starting up...</span>\n');
113
console_maximize(true);
115
95
callback1, "console", "service",
116
96
{"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);
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()
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");
166
131
/** Show the main console panel, so it enlarges out to its full size.
168
function console_maximize(do_not_start)
133
function console_maximize()
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");
324
285
span.setAttribute("class", "inputMsg");
325
286
span.appendChild(document.createTextNode(inputline));
326
287
output.appendChild(span);
327
divScroll.activeScroll();
330
290
"ivle.op": "chat", "kind": which, "key": server_key,
380
339
// Print a reason to explain why we'd do such a horrible thing
381
340
// (console timeout, server error etc.)
383
"IVLE console restarted: " + res.restart, "console_message");
341
print_error("Console Restart: " + res.restart);
385
343
// set the prompt to >>>
386
344
set_prompt(">>>");
416
373
ajax_call(callback, "console", "service", args, "POST");
418
375
// Open up the console so we can see the output
376
// FIXME: do we need to maximize here?
419
377
console_maximize();
380
divScroll.activeScroll();
421
382
// Return early, so we don't re-enable the input box.
424
else if (res.hasOwnProperty('input'))
430
alert("An internal error occurred in the python console.");
387
// assert res.hasOwnProperty('input')
434
391
if (inputbox != null)
535
494
/** Prints an error line in the console **/
536
function print_error(error, cls)
495
function print_error(error)
541
497
var output = document.getElementById("console_output");
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);