944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
1 |
/* IVLE
|
2 |
* Copyright (C) 2007-2008 The University of Melbourne
|
|
3 |
*
|
|
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.
|
|
8 |
*
|
|
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.
|
|
13 |
*
|
|
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
|
|
17 |
*/
|
|
18 |
||
19 |
/* Module: SpecialHome (File Browser, client)
|
|
20 |
* Author: David Coles
|
|
21 |
* Date: 23/7/2008
|
|
22 |
*/
|
|
23 |
||
24 |
/* This module implements the functionality to lay out a special home directory
|
|
25 |
* view on top of the normal listing
|
|
26 |
*/
|
|
27 |
||
28 |
/* The name of the personal file directory */
|
|
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
29 |
PERSONALDIR="mywork" |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
30 |
|
31 |
/* LAYOUT FUNCTIONS */
|
|
32 |
||
33 |
/** Present home directory
|
|
34 |
*/
|
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
35 |
function home_listing(listing, subjects, path) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
36 |
{
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
37 |
/* Nav through the top-level of the JSON to the actual listing object. */
|
38 |
var listing = listing.listing; |
|
39 |
||
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
40 |
var filetablediv = document.getElementById("filetablediv"); |
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
41 |
var specialhomediv; |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
42 |
var h2; |
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
43 |
var h3; |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
44 |
var ul; |
45 |
var li; |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
46 |
var div; |
47 |
||
48 |
/* Only show special headings if we get subject listings */
|
|
49 |
if (subjects != null) |
|
949
by wagrant
specialhome: Only show the subjects header if we are enrolled in some |
50 |
{
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
51 |
/* Wrap all this "special" stuff in a div, for styling purposes */
|
52 |
specialhomediv = document.createElement("div"); |
|
53 |
specialhomediv.setAttribute("id", "specialhome"); |
|
54 |
filetablediv.appendChild(specialhomediv); |
|
55 |
||
56 |
/* SUBJECTS Section
|
|
57 |
/* Create the header row */
|
|
58 |
if (subjects.length > 0) |
|
59 |
{
|
|
60 |
h2 = dom_make_text_elem("h2", "Subjects"); |
|
61 |
specialhomediv.appendChild(h2); |
|
62 |
}
|
|
63 |
||
64 |
/* Create the contents */
|
|
65 |
for (var i=0; i<subjects.length; i++) |
|
66 |
{
|
|
67 |
var subject = subjects[i]; |
|
68 |
var subjpath = subject.subj_short_name; |
|
69 |
// Header
|
|
70 |
h3 = dom_make_text_elem("h3", subject.subj_name); |
|
71 |
specialhomediv.appendChild(h3); |
|
72 |
||
73 |
/* Print the file listing */
|
|
74 |
ul = document.createElement("ul"); |
|
75 |
// Stuff
|
|
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
76 |
ul.appendChild(make_subject_item(subjpath, |
77 |
path_join("users", username, subjpath), PERSONALDIR, |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
78 |
"Your own files in this subject")); |
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
79 |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
80 |
// Groups
|
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
81 |
var groups = subject.groups; |
82 |
for (var j=0; j<subject.groups.length; j++) |
|
83 |
{
|
|
84 |
var group = subject.groups[j]; |
|
85 |
ul.appendChild(make_subject_item(subjpath, |
|
86 |
path_join("groups", subject.subj_short_name + "_" + |
|
87 |
subject.year + "_" + subject.semester + "_" + |
|
88 |
group.name), |
|
89 |
group.name, |
|
90 |
"This group's files in this subject")); |
|
91 |
}
|
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
92 |
|
93 |
specialhomediv.appendChild(ul); |
|
94 |
||
95 |
/* Remove it from listing */
|
|
96 |
if (subject.subj_short_name in listing) |
|
97 |
delete listing[subject.subj_short_name]; |
|
98 |
}
|
|
99 |
||
100 |
/* FIXME: Old Subjects? */
|
|
101 |
||
102 |
/* STUFF Section -- For the stuff directory */
|
|
103 |
/* Create the header */
|
|
104 |
h2 = dom_make_text_elem("h2", "Stuff"); |
|
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
105 |
specialhomediv.appendChild(h2); |
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
106 |
/* Create the contents */
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
107 |
ul = document.createElement("ul"); |
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
108 |
ul.appendChild(make_subject_item("", |
109 |
path_join("users", username, "stuff"), "stuff", |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
110 |
"Your own files not related to a subject")); |
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
111 |
specialhomediv.appendChild(ul); |
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
112 |
/* Remove stuff from the listing */
|
113 |
if ("stuff" in listing) |
|
114 |
delete listing["stuff"]; |
|
115 |
||
116 |
/* JUNK Section -- All the rest */
|
|
117 |
/* Create the header row */
|
|
118 |
if (obj_length(listing) > 0) |
|
119 |
{
|
|
120 |
h2 = dom_make_text_elem("h2", "Junk"); |
|
121 |
specialhomediv.appendChild(h2); |
|
122 |
handle_dir_listing(path, listing); |
|
123 |
}
|
|
124 |
}
|
|
125 |
else
|
|
126 |
{
|
|
127 |
handle_dir_listing(path, listing); |
|
128 |
}
|
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
129 |
}
|
130 |
||
131 |
/* Does an series of AJAX requests to find out the properties of this folder
|
|
132 |
* and then updates the folder view
|
|
133 |
*/
|
|
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
134 |
function make_subject_item(path, repopath, name, description) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
135 |
{
|
136 |
// Create the temporary item
|
|
137 |
var li = document.createElement("li"); |
|
138 |
var span; |
|
139 |
li.setAttribute("class", "listing-loading"); |
|
951
by wagrant
specialhome: Make nonexistent directories a little nicer, with titles |
140 |
li.appendChild(dom_make_text_elem("span", name, description)); |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
141 |
span = dom_make_text_elem("loading..."); |
142 |
span.setAttribute("class","status"); |
|
143 |
li.appendChild(span); |
|
144 |
||
145 |
// Set the callback function to update when we get the real details
|
|
146 |
var callback = function(response) |
|
147 |
{
|
|
148 |
var sublisting = decode_response(response); |
|
149 |
dom_removechildren(li); |
|
150 |
li.setAttribute("class", "listing-dir"); |
|
151 |
||
152 |
// If we could find the file status...
|
|
153 |
if (sublisting != null) |
|
154 |
{
|
|
155 |
var thisdir = sublisting.listing['.']; |
|
156 |
var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned"); |
|
157 |
if (versioned) |
|
158 |
{
|
|
159 |
// Default: Just offer a link to the directory
|
|
160 |
li.appendChild(dom_make_link_elem("span", name, description, |
|
161 |
app_path(this_app, username, path, name))); |
|
162 |
}
|
|
163 |
else
|
|
164 |
{
|
|
165 |
// Blocked: Offer to rename the directory
|
|
952
by wagrant
specialhome: Also be nice if a directory is blocked. |
166 |
li.appendChild(dom_make_text_elem("span", name, description)); |
167 |
span = dom_make_text_elem("span", " (blocked) ", |
|
168 |
"Another file or directory is in the way of this directory."); |
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
169 |
span.setAttribute("class", "status"); |
170 |
li.appendChild(span); |
|
171 |
||
172 |
var button = document.createElement("input"); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
173 |
$(button).click(function(event) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
174 |
{
|
175 |
action_rename(path_join(path, name)); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
176 |
});
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
177 |
button.setAttribute("type", "button"); |
178 |
button.setAttribute("value", "Rename"); |
|
179 |
span.appendChild(button); |
|
180 |
}
|
|
181 |
}
|
|
182 |
else
|
|
183 |
{
|
|
184 |
// Missing: Try to check out or create the repository
|
|
951
by wagrant
specialhome: Make nonexistent directories a little nicer, with titles |
185 |
li.appendChild(dom_make_text_elem("span", name, description)); |
186 |
span = dom_make_text_elem("span", " (missing) ", |
|
187 |
"This directory does not yet exist."); |
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
188 |
span.setAttribute("class", "status"); |
189 |
li.appendChild(span); |
|
190 |
||
191 |
var button = document.createElement("input"); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
192 |
$(button).click(function(event) |
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
193 |
{
|
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
194 |
li.setAttribute("class", "listing-loading"); |
195 |
||
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
196 |
var localpath = path_join(path, name); |
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
197 |
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
198 |
if (create_if_needed(repopath)) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
199 |
{
|
200 |
// Try a checkout
|
|
1326.1.2
by David Coles
Small refactor of browser's JavaScript to allow do_action to be called from |
201 |
do_act("svncheckout", {"path": [repopath, localpath]}); |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
202 |
}
|
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
203 |
else
|
204 |
{
|
|
205 |
li.setAttribute("class", "listing-dir"); |
|
206 |
}
|
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
207 |
});
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
208 |
button.setAttribute("type", "button"); |
209 |
button.setAttribute("value", "Checkout"); |
|
210 |
span.appendChild(button); |
|
211 |
}
|
|
212 |
}
|
|
213 |
||
214 |
/* Are we working in a subdirectory or parent? */
|
|
215 |
ajax_call(callback, service_app, path_join(username, path, name), {}, "GET"); |
|
216 |
return li; |
|
217 |
}
|
|
218 |
||
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
219 |
function create_if_needed(path) |
220 |
{
|
|
221 |
response = ajax_call(null, service_app, current_path, |
|
222 |
{
|
|
223 |
"action": "svnrepostat", |
|
224 |
"path": path |
|
225 |
}, "POST"); |
|
226 |
||
227 |
||
228 |
if (response.status == 200) |
|
229 |
{
|
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
230 |
return true; |
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
231 |
}
|
232 |
else if (response.status == 404) |
|
233 |
{
|
|
234 |
// Try a mkdir
|
|
235 |
r2 = ajax_call(null, service_app, current_path, |
|
236 |
{
|
|
237 |
"action": "svnrepomkdir", |
|
238 |
"path": path, |
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
239 |
"logmsg": "Automated creation of '" + path + "' work directory" |
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
240 |
}, "POST"); |
241 |
||
242 |
if (r2.status == 200) |
|
243 |
{
|
|
244 |
return true; |
|
245 |
}
|
|
246 |
}
|
|
247 |
alert("Error: Could not create Subversion directory"); |
|
248 |
return false; |
|
249 |
}
|
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
250 |
|
251 |
/** Finds the length (number of user defined properties) of an object
|
|
252 |
*/
|
|
253 |
function obj_length(obj) |
|
254 |
{
|
|
1168
by William Grant
Rename length to len in specialhome.js to please IE8. |
255 |
len = 0; |
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
256 |
for (prop in obj) |
1168
by William Grant
Rename length to len in specialhome.js to please IE8. |
257 |
len++; |
258 |
return len; |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
259 |
}
|