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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-02-23 08:55:42 UTC
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: grantw@unimelb.edu.au-20100223085542-r8xw14bxxoraza51
Permit underscores in all names.

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
 
39
66
/* Starts the console server, if it isn't already.
40
67
 * This can be called any number of times - it only starts the one server.
41
68
 * Note that this is asynchronous. It will return after signalling to start
58
85
    var callback1 = function(xhr)
59
86
        {
60
87
            var json_text = xhr.responseText;
61
 
            server_key = JSON.parse(json_text).key;
62
 
            server_started = true;
63
 
            if (callback != null)
64
 
                callback();
 
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
            }
65
101
        }
66
102
 
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, "console", "service", {"ivle.op": "start", "cwd": path}, "POST");
85
 
    }
86
 
    else
87
 
    {
88
 
        // No current_path - let the server decide
89
 
        ajax_call(callback1, "console", "service", {"ivle.op": "start"}, "POST");
90
 
    }
 
103
    ajax_call(
 
104
        callback1, "console", "service",
 
105
        {"ivle.op": "start", "cwd": get_console_start_directory()}, 
 
106
        "POST");
91
107
}
92
108
 
93
109
/** Initialises the console. All apps which import console are required to
117
133
function console_minimize()
118
134
{
119
135
    if (!windowpane_mode) return;
120
 
    console_body.setAttribute("class", "windowpane minimal");
 
136
    console_body.setAttribute("class", "console_body windowpane minimal");
121
137
    console_filler.setAttribute("class", "windowpane minimal");
122
138
}
123
139
 
126
142
function console_maximize()
127
143
{
128
144
    if (!windowpane_mode) return;
129
 
    console_body.setAttribute("class", "windowpane maximal");
 
145
    console_body.setAttribute("class", "console_body windowpane maximal");
130
146
    console_filler.setAttribute("class", "windowpane maximal");
131
147
}
132
148
 
254
270
 
255
271
    if (typeof(inputbox) == "string")
256
272
    {
257
 
        var inputline = inputbox;
 
273
        var inputline = inputbox + "\n";
258
274
        inputbox = null;
259
275
    }
260
276
    else
270
286
        var span = document.createElement("span");
271
287
        span.setAttribute("class", "inputPrompt");
272
288
        span.appendChild(document.createTextNode(
273
 
              document.getElementById("console_prompt").firstChild.textContent)
 
289
              document.getElementById("console_prompt").firstChild.nodeValue)
274
290
                        );
275
291
        output.appendChild(span);
276
292
        // Print input line itself in a span
279
295
        span.appendChild(document.createTextNode(inputline));
280
296
        output.appendChild(span);
281
297
    }
282
 
    var args = {"ivle.op": "chat", "kind": which, "key": server_key, "text":inputline};
 
298
    var args = {
 
299
        "ivle.op": "chat", "kind": which, "key": server_key,
 
300
        "text": inputline, "cwd": get_console_start_directory()
 
301
        };
283
302
    var callback = function(xhr)
284
303
        {
285
304
            console_response(inputbox, inputline, xhr.responseText);
356
375
        {
357
376
            var kind = "chat";
358
377
        }
359
 
        var args = {"ivle.op": "chat", "kind": kind, "key": server_key, "text":''};
 
378
        var args = {
 
379
            "ivle.op": "chat", "kind": kind, "key": server_key,
 
380
            "text": '', "cwd": get_console_start_directory()
 
381
            };
360
382
        ajax_call(callback, "console", "service", args, "POST");
361
383
 
362
384
        // Open up the console so we can see the output
369
391
        // Return early, so we don't re-enable the input box.
370
392
        return;
371
393
    }
 
394
    else if (res.hasOwnProperty('input'))
 
395
    {
 
396
        set_prompt("+++");
 
397
    }
372
398
    else
373
399
    {
374
 
        // assert res.hasOwnProperty('input')
375
 
        set_prompt("...");
 
400
        alert("An internal error occurred in the python console.");
 
401
        return;
376
402
    }
377
403
 
378
404
    if (inputbox != null)
434
460
            hist.submit(inp.value);
435
461
            inp.value = hist.curr();
436
462
        }
 
463
 
 
464
        /* Disable the text box. This will be redone by
 
465
         * console_enter_line, but we do it here too in case start_server
 
466
         * takes a while.
 
467
         */
 
468
        inp.setAttribute("disabled", "disabled");
437
469
        /* Start the server if it hasn't already been started */
438
470
        start_server(callback);
439
471
        break;
440
472
    case 38:                /* Up arrow */
441
473
        hist.up(inp.value);
442
474
        inp.value = hist.curr();
 
475
        /* Inhibit further responses to this event, or WebKit moves the
 
476
         * cursor to the start. */
 
477
        return false;
443
478
        break;
444
479
    case 40:                /* Down arrow */
445
480
        hist.down(inp.value);
446
481
        inp.value = hist.curr();
 
482
        return false;
447
483
        break;
448
484
    }
449
485
}
463
499
    }
464
500
    else
465
501
    {
466
 
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key}, "POST");
467
 
        console_response(null, null, null, xhr.responseText);
 
502
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key, "cwd": get_console_start_directory()}, "POST");
 
503
        console_response(null, null, xhr.responseText);
468
504
    }
469
505
}
470
506