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

« back to all changes in this revision

Viewing changes to www/media/console/console.js

  • Committer: dcoles
  • Date: 2008-02-29 02:11:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:624
forum: Removed the subsilver2 style and phpBB installer
Modified prosilver theme to be more IVLE integrated
Added db dumps for setup

setup.py: Added config.php generator code

doc/setup/install_proc.txt: New setup/install details

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
/* Starts the console server, if it isn't already.
38
38
 * This can be called any number of times - it only starts the one server.
 
39
 * Note that this is asynchronous. It will return after signalling to start
 
40
 * the server, but there is no guarantee that it has been started yet.
39
41
 * This is a separate step from console_init, as the server is only to be
40
42
 * started once the first command is entered.
41
43
 * Does not return a value. Writes to global variables
42
44
 * server_host, and server_port.
 
45
 *
 
46
 * \param callback Function which will be called after the server has been
 
47
 * started. No parameters are passed. May be null.
43
48
 */
44
 
function start_server()
 
49
function start_server(callback)
45
50
{
46
 
    if (server_started) return;
47
 
    var xhr = ajax_call("consoleservice", "start", {}, "POST");
48
 
    var json_text = xhr.responseText;
49
 
    server_key = JSON.parse(json_text);
50
 
    server_started = true;
 
51
    if (server_started)
 
52
    {
 
53
        callback();
 
54
        return;
 
55
    }
 
56
    var callback1 = function(xhr)
 
57
        {
 
58
            var json_text = xhr.responseText;
 
59
            server_key = JSON.parse(json_text);
 
60
            server_started = true;
 
61
            if (callback != null)
 
62
                callback();
 
63
        }
 
64
    ajax_call(callback1, "consoleservice", "start", {}, "POST");
51
65
}
52
66
 
53
67
/** Initialises the console. All apps which import console are required to
201
215
 * to its response by writing to the output box.
202
216
 * Also maximize the console window if not already.
203
217
 */
204
 
function console_enter_line(inputline, which)
 
218
function console_enter_line(inputbox, which)
205
219
{
206
 
    /* Start the server if it hasn't already been started */
207
 
    start_server();
 
220
    if (typeof(inputbox) == "string")
 
221
    {
 
222
        var inputline = inputbox;
 
223
        inputbox = null;
 
224
        var graytimer = null;
 
225
    }
 
226
    else
 
227
    {
 
228
        GLOBAL_inputbox = inputbox;     /* For timer */
 
229
        var inputline = inputbox.value;
 
230
        var graytimer = setTimeout("GLOBAL_inputbox.setAttribute(\"class\", "
 
231
            + "\"disabled\");", 100);
 
232
    }
 
233
    var output = document.getElementById("console_output");
 
234
    {
 
235
        var span = document.createElement("span");
 
236
        span.setAttribute("class", "inputMsg");
 
237
        span.appendChild(document.createTextNode(inputline + "\n"));
 
238
        output.appendChild(span);
 
239
    }
208
240
    var args = {"key": server_key, "text":inputline};
209
 
    var xmlhttp = ajax_call("consoleservice", which, args, "POST");
 
241
    var callback = function(xhr)
 
242
        {
 
243
            console_response(inputbox, graytimer, inputline, xhr.responseText);
 
244
        }
 
245
    /* Disable the text box */
 
246
    if (inputbox != null)
 
247
        inputbox.setAttribute("disabled", "disabled");
 
248
    ajax_call(callback, "consoleservice", which, args, "POST");
 
249
}
210
250
 
211
 
    var res = JSON.parse(xmlhttp.responseText);
 
251
function console_response(inputbox, graytimer, inputline, responseText)
 
252
{
 
253
    var res = JSON.parse(responseText);
212
254
    var output = document.getElementById("console_output");
213
 
    {
214
 
        var pre = document.createElement("pre");
215
 
        pre.setAttribute("class", "inputMsg");
216
 
        pre.appendChild(document.createTextNode(inputline + "\n"));
217
 
        output.appendChild(pre);
218
 
    }
219
255
    if (res.hasOwnProperty('okay'))
220
256
    {
221
257
        // Success!
222
 
        // print out the output (res.okay[0])
223
 
        var pre = document.createElement("pre");
224
 
        pre.setAttribute("class", "outputMsg");
225
 
        pre.appendChild(document.createTextNode(res.okay[0]));
226
 
        output.appendChild(pre);
227
 
        // print out the return value (res.okay[1])
228
 
        if (res.okay[1])
 
258
        if (res.okay)
229
259
        {
230
 
            var pre = document.createElement("pre");
231
 
            pre.setAttribute("class", "outputMsg");
232
 
            pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
233
 
            output.appendChild(pre);
 
260
            output.appendChild(document.createTextNode(res.okay + "\n"));
 
261
            output.appendChild(span);
234
262
        }
235
263
        // set the prompt to >>>
236
264
        var prompt = document.getElementById("console_prompt");
239
267
    else if (res.hasOwnProperty('exc'))
240
268
    {
241
269
        // Failure!
242
 
        // print out any output that came before the error
243
 
        if (res.exc[0].length > 0)
244
 
        {
245
 
            var pre = document.createElement("pre");
246
 
            pre.setAttribute("class", "outputMsg");
247
 
            pre.appendChild(document.createTextNode(res.exc[0]));
248
 
            output.appendChild(pre);
249
 
        }
250
 
 
251
270
        // print out the error message (res.exc)
252
 
        var pre = document.createElement("pre");
253
 
        pre.setAttribute("class", "errorMsg");
254
 
        pre.appendChild(document.createTextNode(res.exc[1]));
255
 
        output.appendChild(pre);
 
271
        var span = document.createElement("span");
 
272
        span.setAttribute("class", "errorMsg");
 
273
        span.appendChild(document.createTextNode(res.exc + "\n"));
 
274
        output.appendChild(span);
256
275
    }
257
276
    else if (res.hasOwnProperty('more'))
258
277
    {
260
279
        var prompt = document.getElementById("console_prompt");
261
280
        prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
262
281
    }
 
282
    else if (res.hasOwnProperty('output'))
 
283
    {
 
284
        if (res.output.length > 0)
 
285
        {
 
286
            output.appendChild(document.createTextNode(res.output));
 
287
        }
 
288
        var callback = function(xhr)
 
289
            {
 
290
                console_response(inputbox, graytimer,
 
291
                                 null, xhr.responseText);
 
292
            }
 
293
        var args = {"key": server_key, "text":''};
 
294
        ajax_call(callback, "consoleservice", "chat", args, "POST");
 
295
 
 
296
        /* Open up the console so we can see the output */
 
297
        console_maximize();
 
298
        /* Auto-scrolling */
 
299
        divScroll.activeScroll();
 
300
 
 
301
        // Return early, so we don't re-enable the input box.
 
302
        return;
 
303
    }
263
304
    else {
264
305
        // assert res.hasOwnProperty('input')
265
306
        var prompt = document.getElementById("console_prompt");
266
307
        prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
267
308
    }
 
309
 
 
310
    if (inputbox != null)
 
311
    {
 
312
        /* Re-enable the text box */
 
313
        clearTimeout(graytimer);
 
314
        inputbox.removeAttribute("disabled");
 
315
        inputbox.removeAttribute("class");
 
316
    }
 
317
 
268
318
    /* Open up the console so we can see the output */
269
319
    console_maximize();
 
320
    /* Auto-scrolling */
 
321
    divScroll.activeScroll();
270
322
}
271
323
 
272
324
function catch_input(key)
304
356
         */
305
357
        break;
306
358
    case 13:                /* Enter key */
307
 
        /* Send the line of text to the server */
308
 
        console_enter_line(inp.value, "chat");
309
 
        hist.submit(inp.value);
310
 
        inp.value = hist.curr();
 
359
        var callback = function()
 
360
        {
 
361
            /* Send the line of text to the server */
 
362
            console_enter_line(inp, "chat");
 
363
            hist.submit(inp.value);
 
364
            inp.value = hist.curr();
 
365
        }
 
366
        /* Start the server if it hasn't already been started */
 
367
        start_server(callback);
311
368
        break;
312
369
    case 38:                /* Up arrow */
313
370
        hist.up(inp.value);
319
376
        break;
320
377
    }
321
378
}
 
379
 
 
380
/**** Following Code modified from ******************************************/
 
381
/**** http://radio.javaranch.com/pascarello/2006/08/17/1155837038219.html ***/
 
382
/****************************************************************************/
 
383
var chatscroll = new Object();
 
384
 
 
385
chatscroll.Pane = function(scrollContainerId)
 
386
{
 
387
    this.scrollContainerId = scrollContainerId;
 
388
}
 
389
 
 
390
chatscroll.Pane.prototype.activeScroll = function()
 
391
{
 
392
    var scrollDiv = document.getElementById(this.scrollContainerId);
 
393
    var currentHeight = 0;
 
394
        
 
395
    if (scrollDiv.scrollHeight > 0)
 
396
        currentHeight = scrollDiv.scrollHeight;
 
397
    else 
 
398
        if (objDiv.offsetHeight > 0)
 
399
            currentHeight = scrollDiv.offsetHeight;
 
400
 
 
401
    scrollDiv.scrollTop = currentHeight;
 
402
 
 
403
    scrollDiv = null;
 
404
}
 
405
 
 
406
var divScroll = new chatscroll.Pane('console_output');