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

« back to all changes in this revision

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

  • Committer: me at id
  • Date: 2009-01-15 05:53:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1161
bin/ivle-showenrolment: Switch to ivle.database.User.enrolments from
    ivle.db.get_enrolment, removing the dependency on ivle.db.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
interrupted = false;
38
38
 
39
 
 
40
 
function get_console_start_directory()
41
 
{
42
 
    if((typeof(current_path) != 'undefined') && current_file)
43
 
    {
44
 
        // We have a current_path - give a suggestion to the server
45
 
        var path;
46
 
        if (current_file.isdir)
47
 
        {
48
 
            // Browser
49
 
            return path_join("/home", current_path);
50
 
        }
51
 
        else
52
 
        {
53
 
            // Editor - need to chop off filename
54
 
            var tmp_path = current_path.split('/');
55
 
            tmp_path.pop();
56
 
            return path_join("/home", tmp_path.join('/'));
57
 
        }
58
 
    }
59
 
    else
60
 
    {
61
 
        // No current_path - let the server decide
62
 
        return '';
63
 
    }
64
 
}
65
 
 
66
39
/* Starts the console server, if it isn't already.
67
40
 * This can be called any number of times - it only starts the one server.
68
41
 * Note that this is asynchronous. It will return after signalling to start
85
58
    var callback1 = function(xhr)
86
59
        {
87
60
            var json_text = xhr.responseText;
88
 
            try
89
 
            {
90
 
                server_key = JSON.parse(json_text).key;
91
 
                server_started = true;
92
 
                if (callback != null)
93
 
                    callback();
94
 
            }
95
 
            catch (e)
96
 
            {
97
 
                alert("An error occured when starting the IVLE console. " +
98
 
                    "Please refresh the page and try again.\n" +
99
 
                    "Details have been logged for further examination.")
100
 
            }
 
61
            server_key = JSON.parse(json_text).key;
 
62
            server_started = true;
 
63
            if (callback != null)
 
64
                callback();
101
65
        }
102
66
 
103
 
    ajax_call(
104
 
        callback1, "console", "service",
105
 
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
106
 
        "POST");
 
67
    //var current_path;
 
68
    if((typeof(current_path) != 'undefined') && current_file)
 
69
    {
 
70
        // We have a current_path - give a suggestion to the server
 
71
        var path;
 
72
        if (current_file.isdir)
 
73
        {
 
74
            // Browser
 
75
            path = path_join("/home", current_path);
 
76
        }
 
77
        else
 
78
        {
 
79
            // Editor - need to chop off filename
 
80
            var tmp_path = current_path.split('/');
 
81
            tmp_path.pop();
 
82
            path = path_join("/home", tmp_path.join('/'));
 
83
        }
 
84
        ajax_call(callback1, "consoleservice", "start", {"startdir": path}, "POST");
 
85
    }
 
86
    else
 
87
    {
 
88
        // No current_path - let the server decide
 
89
        ajax_call(callback1, "consoleservice", "start", {}, "POST");
 
90
    }
107
91
}
108
92
 
109
93
/** Initialises the console. All apps which import console are required to
133
117
function console_minimize()
134
118
{
135
119
    if (!windowpane_mode) return;
136
 
    console_body.setAttribute("class", "console_body windowpane minimal");
 
120
    console_body.setAttribute("class", "windowpane minimal");
137
121
    console_filler.setAttribute("class", "windowpane minimal");
138
122
}
139
123
 
142
126
function console_maximize()
143
127
{
144
128
    if (!windowpane_mode) return;
145
 
    console_body.setAttribute("class", "console_body windowpane maximal");
 
129
    console_body.setAttribute("class", "windowpane maximal");
146
130
    console_filler.setAttribute("class", "windowpane maximal");
147
131
}
148
132
 
270
254
 
271
255
    if (typeof(inputbox) == "string")
272
256
    {
273
 
        var inputline = inputbox + "\n";
 
257
        var inputline = inputbox;
274
258
        inputbox = null;
 
259
        var graytimer = null;
275
260
    }
276
261
    else
277
262
    {
278
 
        /* Disable the text box */
279
 
        inputbox.setAttribute("disabled", "disabled");
280
 
 
 
263
        GLOBAL_inputbox = inputbox;     /* For timer */
281
264
        var inputline = inputbox.value + "\n";
 
265
        var graytimer = setTimeout("GLOBAL_inputbox.setAttribute(\"class\", "
 
266
            + "\"disabled\");", 100);
282
267
    }
283
268
    var output = document.getElementById("console_output");
284
269
    {
286
271
        var span = document.createElement("span");
287
272
        span.setAttribute("class", "inputPrompt");
288
273
        span.appendChild(document.createTextNode(
289
 
              document.getElementById("console_prompt").firstChild.nodeValue)
 
274
              document.getElementById("console_prompt").firstChild.textContent)
290
275
                        );
291
276
        output.appendChild(span);
292
277
        // Print input line itself in a span
295
280
        span.appendChild(document.createTextNode(inputline));
296
281
        output.appendChild(span);
297
282
    }
298
 
    var args = {
299
 
        "ivle.op": "chat", "kind": which, "key": server_key,
300
 
        "text": inputline, "cwd": get_console_start_directory()
301
 
        };
 
283
    var args = {"key": server_key, "text":inputline};
302
284
    var callback = function(xhr)
303
285
        {
304
 
            console_response(inputbox, inputline, xhr.responseText);
 
286
            console_response(inputbox, graytimer, inputline, xhr.responseText);
305
287
        }
306
 
    ajax_call(callback, "console", "service", args, "POST");
 
288
    /* Disable the text box */
 
289
    if (inputbox != null)
 
290
        inputbox.setAttribute("disabled", "disabled");
 
291
    ajax_call(callback, "consoleservice", which, args, "POST");
307
292
}
308
293
 
309
 
function console_response(inputbox, inputline, responseText)
 
294
function console_response(inputbox, graytimer, inputline, responseText)
310
295
{
311
296
    try
312
297
    {
365
350
        }
366
351
        var callback = function(xhr)
367
352
            {
368
 
                console_response(inputbox, null, xhr.responseText);
 
353
                console_response(inputbox, graytimer,
 
354
                                 null, xhr.responseText);
369
355
            }
370
356
        if (interrupted)
371
357
        {
375
361
        {
376
362
            var kind = "chat";
377
363
        }
378
 
        var args = {
379
 
            "ivle.op": "chat", "kind": kind, "key": server_key,
380
 
            "text": '', "cwd": get_console_start_directory()
381
 
            };
382
 
        ajax_call(callback, "console", "service", args, "POST");
 
364
        var args = {"key": server_key, "text":''};
 
365
        ajax_call(callback, "consoleservice", kind, args, "POST");
383
366
 
384
367
        // Open up the console so we can see the output
385
368
        // FIXME: do we need to maximize here?
400
383
    if (inputbox != null)
401
384
    {
402
385
        /* Re-enable the text box */
 
386
        clearTimeout(graytimer);
403
387
        inputbox.removeAttribute("disabled");
 
388
        inputbox.removeAttribute("class");
404
389
        interrupted = false;
405
390
    }
406
391
 
456
441
            hist.submit(inp.value);
457
442
            inp.value = hist.curr();
458
443
        }
459
 
 
460
 
        /* Disable the text box. This will be redone by
461
 
         * console_enter_line, but we do it here too in case start_server
462
 
         * takes a while.
463
 
         */
464
 
        inp.setAttribute("disabled", "disabled");
465
444
        /* Start the server if it hasn't already been started */
466
445
        start_server(callback);
467
446
        break;
468
447
    case 38:                /* Up arrow */
469
448
        hist.up(inp.value);
470
449
        inp.value = hist.curr();
471
 
        /* Inhibit further responses to this event, or WebKit moves the
472
 
         * cursor to the start. */
473
 
        return false;
474
450
        break;
475
451
    case 40:                /* Down arrow */
476
452
        hist.down(inp.value);
477
453
        inp.value = hist.curr();
478
 
        return false;
479
454
        break;
480
455
    }
481
456
}
495
470
    }
496
471
    else
497
472
    {
498
 
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key, "cwd": get_console_start_directory()}, "POST");
499
 
        console_response(null, null, xhr.responseText);
 
473
        xhr = ajax_call(null, "consoleservice", "restart", {"key": server_key}, "POST");
 
474
        console_response(null, null, null, xhr.responseText);
500
475
    }
501
476
}
502
477