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

« back to all changes in this revision

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

  • Committer: David Coles
  • Date: 2009-12-02 19:16:46 UTC
  • mfrom: (1332.1.4 console-fix)
  • Revision ID: coles.david@gmail.com-20091202191646-e55k83yd7sera1fk
When a console is restarted due to either being reset from the UI or killed 
due to inactivity/resource limits then will restart at the correct working 
directory.

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
467
476
    }
468
477
    else
469
478
    {
470
 
        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");
471
484
        console_response(null, null, xhr.responseText);
472
485
    }
473
486
}