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

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/browser/media/editor.js

  • Committer: David Coles
  • Date: 2010-07-28 05:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: coles.david@gmail.com-20100728052719-h6d10lgpo1pfty6a
Change handle_content_response so that we only fetch file contents inside-
fetch_text and not for all media types.

Also remove present_editorhead since it's only useful action is an unreachable
codepath and requires threading some otherwise unneeded varaibles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    window.onbeforeunload = confirm_beforeunload;
66
66
}
67
67
 
68
 
/** Presents the "editor heading" inserting it into a given element at
69
 
 *  the front. Note that the save widget is handled by the Python.
70
 
 */
71
 
function present_editorhead(elem, path, handler_type)
72
 
{
73
 
    var div = document.getElementById("actions2");
74
 
 
75
 
    /* Print a warning message if this is not actually a text file.
76
 
     */
77
 
    if (handler_type != "text")
78
 
    {
79
 
        var warn = dom_make_text_elem("p",
80
 
            "Warning: You are editing a binary " +
81
 
            "file, which explains any strange characters you may see. If " +
82
 
            "you save this file, you could corrupt it.");
83
 
        div.appendChild(warn);
84
 
    }
85
 
}
86
 
 
87
68
function highlighting_changed(select)
88
69
{
89
70
    editbox.edit(editbox.getCode(), select.value);
107
88
 
108
89
/** Presents the text editor.
109
90
 */
110
 
function handle_text(path, text, handler_type)
 
91
function handle_text(path, content_type, url_args)
 
92
{
 
93
    /* Need to make a 2nd ajax call, this time get the actual file
 
94
     * contents */
 
95
    callback = function(response)
 
96
        {
 
97
            /* Read the response and set up the page accordingly */
 
98
            handle_text_response(path, content_type, response.responseText);
 
99
        }
 
100
    /* Call the server and request the listing. */
 
101
    if (url_args)
 
102
        args = shallow_clone_object(url_args);
 
103
    else
 
104
        args = {};
 
105
    /* This time, get the contents of the file, not its metadata */
 
106
    args['return'] = "contents";
 
107
    ajax_call(callback, service_app, path, args, "GET");
 
108
}
 
109
 
 
110
function handle_text_response(path, content_type, response_text)
111
111
{
112
112
    /* Create a textarea with the text in it
113
113
     * (The makings of a primitive editor).
114
114
     */
115
115
    var files = document.getElementById("filesbody");
116
 
    /* Put our UI at the top */
117
 
    present_editorhead(files, path, handler_type);
118
116
 
119
117
    var div = document.createElement("div");
120
118
    div.style.height = '100%';
121
119
    files.appendChild(div);
122
120
    var txt_elem = document.createElement("textarea");
123
 
    txt_elem.value = text.toString();
 
121
    txt_elem.value = response_text.toString();
124
122
    div.appendChild(txt_elem);
125
123
    txt_elem.setAttribute("id", "editbox");
126
 
    language = language_from_mime(current_file.type);
 
124
    language = language_from_mime(content_type);
127
125
 
128
126
    // Assume plaintext if no type can be determined.
129
127
    language = language ? language : "text";