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

« back to all changes in this revision

Viewing changes to www/media/browser/listing.js

  • Committer: mattgiuca
  • Date: 2008-01-14 00:28:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:215
listing.js:
    Added handling code for all non-subversion actions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * Handles directory listings on the client side.
23
23
 */
24
24
 
 
25
/* TODO: encodeURI on all generated paths for links */
 
26
 
25
27
/* DOM nodeType constants */
26
28
ELEMENT_NODE = 1;
27
29
 
32
34
file_listing = null;
33
35
thisdir = null;
34
36
 
 
37
/** ACTIONS **/
 
38
 
 
39
function action_rename(fromfilename)
 
40
{
 
41
    tofilename = prompt("Rename file \"" + fromfilename + "\" to?");
 
42
    if (tofilename == null) return;
 
43
    do_action("move", current_path, {"from":fromfilename, "to":tofilename});
 
44
    return false;
 
45
}
 
46
 
 
47
function action_remove(files)
 
48
{
 
49
    do_action("remove", current_path, {"path":files});
 
50
    return false;
 
51
}
 
52
 
 
53
function action_copy(files)
 
54
{
 
55
    do_action("copy", current_path, {"path":files});
 
56
    return false;
 
57
}
 
58
 
 
59
function action_cut(files)
 
60
{
 
61
    do_action("cut", current_path, {"path":files});
 
62
    return false;
 
63
}
 
64
 
 
65
function action_paste()
 
66
{
 
67
    do_action("paste", current_path, {"path":"."});
 
68
    return false;
 
69
}
 
70
 
 
71
/** END ACTIONS **/
 
72
 
35
73
/** Updates the side-panel. Expects selected_files reflects the current
36
74
 * selected files.
37
75
 */
54
92
        }
55
93
        else if (selected_files.length == 1)
56
94
        {
57
 
            filename = selected_files;
 
95
            filename = selected_files[0];
58
96
            file = file_listing[filename];
59
97
        }
60
98
        var filetype;
123
161
        if ("type" in file)
124
162
            handler_type = get_handler_type(file.type);
125
163
        /* Action: Use the "files" / "edit" app */
126
 
        if (file.isdir)
127
 
            p = dom_make_link_elem("p", "Browse",
128
 
                "Browse this directory in the file browser");
129
 
        else if (handler_type == "text")
130
 
            p = dom_make_link_elem("p", "Edit", "Edit this file");
131
 
        else
132
 
            p = dom_make_link_elem("p", "Browse",
133
 
                "View this file in the file browser");
134
 
        sidepanel.appendChild(p);
 
164
        var path;
 
165
        if (selected_files.length == 1)
 
166
        {
 
167
            /* Don't have "Browse" if this is the current dir */
 
168
            if (file.isdir)
 
169
                p = dom_make_link_elem("p", "Browse",
 
170
                    "Navigate to this directory in the file browser",
 
171
                    make_path(path_join(this_app, current_path, filename)));
 
172
            else if (handler_type == "text")
 
173
                p = dom_make_link_elem("p", "Edit", "Edit this file",
 
174
                    make_path(path_join(edit_app, current_path, filename)));
 
175
            else
 
176
                p = dom_make_link_elem("p", "Browse",
 
177
                    "View this file in the file browser",
 
178
                    make_path(path_join(this_app, current_path, filename)));
 
179
            sidepanel.appendChild(p);
 
180
        }
135
181
 
136
182
        /* Action: Use the "serve" app */
137
183
        /* TODO: Figure out if this file is executable,
140
186
        if (file.isdir || handler_type == "binary") {}
141
187
        else
142
188
            p = dom_make_link_elem("p", "View",
143
 
                "View this file");
 
189
                "View this file",
 
190
                make_path(path_join(serve_app, current_path, filename)));
144
191
        if (p)
145
192
            sidepanel.appendChild(p);
146
193
 
147
194
        /* Action: Use the "download" app */
148
195
        p = null;
 
196
        path = make_path(path_join(download_app, current_path, filename));
149
197
        if (file.isdir)
150
198
            p = dom_make_link_elem("p", "Download as zip",
151
 
                "Download this directory as a ZIP file");
 
199
                "Download this directory as a ZIP file", path);
152
200
        else
153
201
            p = dom_make_link_elem("p", "Download",
154
 
                "Download this file to your computer");
 
202
                "Download this file to your computer", path);
155
203
        if (p)
156
204
            sidepanel.appendChild(p);
157
205
 
158
206
        p = dom_make_link_elem("p", "Rename",
159
 
            "Change the name of this file");
 
207
            "Change the name of this file", null,
 
208
            "return action_rename(" + repr(filename) + ")");
160
209
        sidepanel.appendChild(p);
161
210
    }
162
211
    else
163
212
    {
 
213
        path = make_path(path_join(download_app, current_path) + "?");
 
214
        for (var i=0; i<selected_files.length; i++)
 
215
            path += "path=" + encodeURIComponent(selected_files[i]) + "&";
 
216
        path = path.substr(0, path.length-1);
164
217
        /* Multiple files selected */
165
218
        p = dom_make_link_elem("p", "Download as zip",
166
 
            "Download the selected files as a ZIP file");
 
219
            "Download the selected files as a ZIP file", path);
167
220
        sidepanel.appendChild(p);
168
221
    }
169
222
 
170
223
    /* Common actions */
 
224
    p = dom_make_link_elem("p", "Delete",
 
225
        "Delete the selected files", null,
 
226
        "return action_remove(selected_files)");
 
227
    sidepanel.appendChild(p);
171
228
    p = dom_make_link_elem("p", "Cut",
172
 
        "Prepare to move the selected files to another directory");
 
229
        "Prepare to move the selected files to another directory", null,
 
230
        "return action_cut(selected_files)");
173
231
    sidepanel.appendChild(p);
174
232
    p = dom_make_link_elem("p", "Copy",
175
 
        "Prepare to copy the selected files to another directory");
 
233
        "Prepare to copy the selected files to another directory", null,
 
234
        "return action_copy(selected_files)");
176
235
    sidepanel.appendChild(p);
177
236
    p = dom_make_link_elem("p", "Paste",
178
 
        "Paste the copied or cut files to the current directory");
 
237
        "Paste the copied or cut files to the current directory", null,
 
238
        "return action_paste()");
179
239
    sidepanel.appendChild(p);
180
240
 
181
241
    if (under_subversion)
408
468
            /* Column 3: Filename */
409
469
            td = dom_make_link_elem("td", filename,
410
470
                "Navigate to " + path_join(path, filename),
411
 
                make_path(path_join(this_app, path, filename)),
412
 
                "navigate(" + repr(path_join(path, filename)) + ")");
 
471
                make_path(path_join(this_app, path, filename))/*,
 
472
                "navigate(" + repr(path_join(path, filename)) + ")"*/);
413
473
            td.setAttribute("onclick", selection_string);
414
474
            row.appendChild(td);
415
475
        }