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
/* Wrap all this "special" stuff in a div, for styling purposes */
46
specialhomediv = document.createElement("div");
47
specialhomediv.setAttribute("id", "specialhome");
48
filetablediv.appendChild(specialhomediv);
51
/* Create the header row */
52
if (subjects.length > 0)
54
h2 = dom_make_text_elem("h2", "Subjects");
55
specialhomediv.appendChild(h2);
58
/* Create the contents */
59
for (var i=0; i<subjects.length; i++)
61
var subject = subjects[i];
62
var path = subject.subj_short_name;
64
h3 = dom_make_text_elem("h3", subject.subj_name);
65
specialhomediv.appendChild(h3);
67
/* Print the file listing */
68
ul = document.createElement("ul");
70
ul.appendChild(make_subject_item(path, PERSONALDIR,
71
"Your own files in this subject"));
73
/* TODO: List groups */
75
specialhomediv.appendChild(ul);
77
/* Remove it from listing */
78
if (subject.subj_short_name in listing)
79
delete listing[subject.subj_short_name];
82
/* FIXME: Old Subjects? */
84
/* STUFF Section -- For the stuff directory */
85
/* Create the header */
86
h2 = dom_make_text_elem("h2", "Stuff");
87
specialhomediv.appendChild(h2);
88
/* Create the contents */
89
ul = document.createElement("ul");
90
ul.appendChild(make_subject_item("", "stuff",
91
"Your own files not related to a subject"));
92
specialhomediv.appendChild(ul);
93
/* Remove stuff from the listing */
94
if ("stuff" in listing)
95
delete listing["stuff"];
97
/* JUNK Section -- All the rest */
98
/* Create the header row */
99
h2 = dom_make_text_elem("h2", "Junk");
100
specialhomediv.appendChild(h2);
103
/* Does an series of AJAX requests to find out the properties of this folder
104
* and then updates the folder view
106
function make_subject_item(path, name, description)
108
// Create the temporary item
109
var li = document.createElement("li");
111
li.setAttribute("class", "listing-loading");
112
li.appendChild(dom_make_text_elem("span", name, description));
113
span = dom_make_text_elem("loading...");
114
span.setAttribute("class","status");
115
li.appendChild(span);
117
// Set the callback function to update when we get the real details
118
var callback = function(response)
120
var sublisting = decode_response(response);
121
dom_removechildren(li);
122
li.setAttribute("class", "listing-dir");
124
// If we could find the file status...
125
if (sublisting != null)
127
var thisdir = sublisting.listing['.'];
128
var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned");
131
// Default: Just offer a link to the directory
132
li.appendChild(dom_make_link_elem("span", name, description,
133
app_path(this_app, username, path, name)));
137
// Blocked: Offer to rename the directory
138
li.appendChild(dom_make_text_elem("span", name, description));
139
span = dom_make_text_elem("span", " (blocked) ",
140
"Another file or directory is in the way of this directory.");
141
span.setAttribute("class", "status");
142
li.appendChild(span);
144
var button = document.createElement("input");
145
button.addEventListener("click", function(event)
147
action_rename(path_join(path, name));
150
button.setAttribute("type", "button");
151
button.setAttribute("value", "Rename");
152
span.appendChild(button);
157
// Missing: Try to check out or create the repository
158
li.appendChild(dom_make_text_elem("span", name, description));
159
span = dom_make_text_elem("span", " (missing) ",
160
"This directory does not yet exist.");
161
span.setAttribute("class", "status");
162
li.appendChild(span);
164
var button = document.createElement("input");
165
button.addEventListener("click", function(event)
167
li.setAttribute("class", "listing-loading");
169
var localpath = path_join(path, name);
170
// The repository doesn't know about PERSONALDIR.
171
if (name == PERSONALDIR) name = '';
172
var repopath = path_join('users', username, path, name);
174
if (create_if_needed(repopath))
177
do_action("svncheckout", current_path, {"path":
178
[repopath, localpath]});
182
li.setAttribute("class", "listing-dir");
186
button.setAttribute("type", "button");
187
button.setAttribute("value", "Checkout");
188
span.appendChild(button);
192
/* Are we working in a subdirectory or parent? */
193
ajax_call(callback, service_app, path_join(username, path, name), {}, "GET");
197
function create_if_needed(path)
199
response = ajax_call(null, service_app, current_path,
201
"action": "svnrepostat",
206
if (response.status == 200)
210
else if (response.status == 404)
213
r2 = ajax_call(null, service_app, current_path,
215
"action": "svnrepomkdir",
217
"logmsg": "Automated creation of '" + path + "' work directory"
220
if (r2.status == 200)
225
alert("Error: Could not create Subversion directory");