2
* Copyright (C) 2007-2008 The University of Melbourne
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* Module: SpecialHome (File Browser, client)
24
/* This module implements the functionality to lay out a special home directory
25
* view on top of the normal listing
28
/* The name of the personal file directory */
31
/* LAYOUT FUNCTIONS */
33
/** Present home directory
35
function home_listing(listing, subjects)
37
listing = listing.listing;
38
var filetablediv = document.getElementById("filetablediv");
45
/* Create the header row */
46
if (subjects.length > 0)
48
h1 = dom_make_text_elem("h1", "Subjects");
49
filetablediv.appendChild(h1);
52
/* Create the contents */
53
for (var i=0; i<subjects.length; i++)
55
var subject = subjects[i];
56
var path = subject.subj_short_name;
58
h2 = dom_make_text_elem("h2", subject.subj_name);
59
filetablediv.appendChild(h2);
61
/* Print the file listing */
62
ul = document.createElement("ul");
64
ul.appendChild(make_subject_item(path, PERSONALDIR,
65
"Your own files in this subject"));
67
/* TODO: List groups */
69
filetablediv.appendChild(ul);
71
/* Remove it from listing */
72
if (subject.subj_short_name in listing)
73
delete listing[subject.subj_short_name];
76
/* FIXME: Old Subjects? */
78
/* STUFF Section -- For the stuff directory */
79
/* Create the header */
80
h1 = dom_make_text_elem("h1", "Stuff");
81
filetablediv.appendChild(h1);
82
/* Create the contents */
83
ul = document.createElement("ul");
84
ul.appendChild(make_subject_item("", "stuff",
85
"Your own files not related to a subject"));
86
filetablediv.appendChild(ul);
87
/* Remove stuff from the listing */
88
if ("stuff" in listing)
89
delete listing["stuff"];
91
/* JUNK Section -- All the rest */
92
/* Create the header row */
93
h1 = dom_make_text_elem("h1", "Junk");
94
filetablediv.appendChild(h1);
97
/* Does an series of AJAX requests to find out the properties of this folder
98
* and then updates the folder view
100
function make_subject_item(path, name, description)
102
// Create the temporary item
103
var li = document.createElement("li");
105
li.setAttribute("class", "listing-loading");
106
li.appendChild(dom_make_text_elem("span", name, description));
107
span = dom_make_text_elem("loading...");
108
span.setAttribute("class","status");
109
li.appendChild(span);
111
// Set the callback function to update when we get the real details
112
var callback = function(response)
114
var sublisting = decode_response(response);
115
dom_removechildren(li);
116
li.setAttribute("class", "listing-dir");
118
// If we could find the file status...
119
if (sublisting != null)
121
var thisdir = sublisting.listing['.'];
122
var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned");
125
// Default: Just offer a link to the directory
126
li.appendChild(dom_make_link_elem("span", name, description,
127
app_path(this_app, username, path, name)));
131
// Blocked: Offer to rename the directory
132
li.appendChild(dom_make_text_elem("span", name, description));
133
span = dom_make_text_elem("span", " (blocked) ",
134
"Another file or directory is in the way of this directory.");
135
span.setAttribute("class", "status");
136
li.appendChild(span);
138
var button = document.createElement("input");
139
button.addEventListener("click", function(event)
141
action_rename(path_join(path, name));
144
button.setAttribute("type", "button");
145
button.setAttribute("value", "Rename");
146
span.appendChild(button);
151
// Missing: Try to check out or create the repository
152
li.appendChild(dom_make_text_elem("span", name, description));
153
span = dom_make_text_elem("span", " (missing) ",
154
"This directory does not yet exist.");
155
span.setAttribute("class", "status");
156
li.appendChild(span);
158
var button = document.createElement("input");
159
button.addEventListener("click", function(event)
161
li.setAttribute("class", "listing-loading");
163
var localpath = path_join(path, name);
164
// The repository doesn't know about PERSONALDIR.
165
if (name == PERSONALDIR) name = '';
166
var repopath = path_join('users', username, path, name);
168
if (create_if_needed(repopath))
171
do_action("svncheckout", current_path, {"path":
172
[repopath, localpath]});
176
li.setAttribute("class", "listing-dir");
180
button.setAttribute("type", "button");
181
button.setAttribute("value", "Checkout");
182
span.appendChild(button);
186
/* Are we working in a subdirectory or parent? */
187
ajax_call(callback, service_app, path_join(username, path, name), {}, "GET");
191
function create_if_needed(path)
193
response = ajax_call(null, service_app, current_path,
195
"action": "svnrepostat",
200
if (response.status == 200)
204
else if (response.status == 404)
207
r2 = ajax_call(null, service_app, current_path,
209
"action": "svnrepomkdir",
211
"logmsg": "Automated creation of '" + path + "' work directory"
214
if (r2.status == 200)
219
alert("Error: Could not create Subversion directory");