~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: 2009-12-07 04:01:30 UTC
  • Revision ID: grantw@unimelb.edu.au-20091207040130-g86nvbxnm7xdaye7
Move the year decision responsibility to each pulldown module, not the pulldown framework.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
                callback();
65
65
        }
66
66
 
67
 
    //var current_path;
68
 
    if((typeof(current_path) != 'undefined') && current_file)
 
67
    var cwd = get_cwd();
 
68
    ajax_call(callback1, "console", "service", {"ivle.op": "start",
 
69
            "cwd": cwd}, "POST");
 
70
}
 
71
 
 
72
/** Try and get the current working directory of this app */
 
73
function get_cwd()
 
74
{
 
75
    /** Can get CWD from filesystem app */
 
76
    if((typeof(this_app) != 'undefined') && this_app == "files")
69
77
    {
70
 
        // We have a current_path - give a suggestion to the server
71
 
        var path;
72
78
        if (current_file.isdir)
73
79
        {
74
 
            // Browser
75
 
            path = path_join("/home", current_path);
 
80
            // Browser - already a directory
 
81
            return path_join("/home", current_path);
76
82
        }
77
83
        else
78
84
        {
79
85
            // Editor - need to chop off filename
80
86
            var tmp_path = current_path.split('/');
81
87
            tmp_path.pop();
82
 
            path = path_join("/home", tmp_path.join('/'));
 
88
            return path_join("/home", tmp_path.join('/'));
83
89
        }
84
 
        ajax_call(callback1, "console", "service", {"ivle.op": "start", "cwd": path}, "POST");
85
90
    }
86
91
    else
87
92
    {
88
 
        // No current_path - let the server decide
89
 
        ajax_call(callback1, "console", "service", {"ivle.op": "start"}, "POST");
 
93
        // Unable to determine CWD
 
94
        return '';
90
95
    }
91
96
}
92
97
 
279
284
        span.appendChild(document.createTextNode(inputline));
280
285
        output.appendChild(span);
281
286
    }
282
 
    var args = {"ivle.op": "chat", "kind": which, "key": server_key, "text":inputline};
 
287
    var cwd = get_cwd();
 
288
    var args = {"ivle.op": "chat", "kind": which, "key": server_key,
 
289
            "text":inputline, "cwd": cwd};
283
290
    var callback = function(xhr)
284
291
        {
285
292
            console_response(inputbox, inputline, xhr.responseText);
356
363
        {
357
364
            var kind = "chat";
358
365
        }
359
 
        var args = {"ivle.op": "chat", "kind": kind, "key": server_key, "text":''};
 
366
        var cwd = get_cwd();
 
367
        var args = {"ivle.op": "chat", "kind": kind, "key": server_key,
 
368
                "text":'', "cwd": cwd};
360
369
        ajax_call(callback, "console", "service", args, "POST");
361
370
 
362
371
        // Open up the console so we can see the output
440
449
    case 38:                /* Up arrow */
441
450
        hist.up(inp.value);
442
451
        inp.value = hist.curr();
 
452
        /* Inhibit further responses to this event, or WebKit moves the
 
453
         * cursor to the start. */
 
454
        return false;
443
455
        break;
444
456
    case 40:                /* Down arrow */
445
457
        hist.down(inp.value);
446
458
        inp.value = hist.curr();
 
459
        return false;
447
460
        break;
448
461
    }
449
462
}
463
476
    }
464
477
    else
465
478
    {
466
 
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat", "kind": "terminate", "key": server_key}, "POST");
 
479
        /* Terminate the old server and start a new one */
 
480
        var cwd = get_cwd();
 
481
        xhr = ajax_call(null, "console", "service", {"ivle.op": "chat",
 
482
                "kind": "terminate", "key": server_key, "cwd": cwd},
 
483
                "POST");
467
484
        console_response(null, null, xhr.responseText);
468
485
    }
469
486
}