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 |
||
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
33 |
/** Present special home directory. This is only called if in the top level.
|
34 |
* Subjects must not be null.
|
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
35 |
*/
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
36 |
function special_home_listing(listing, subjects, path) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
37 |
{
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
38 |
/* Nav through the top-level of the JSON to the actual listing object. */
|
39 |
var listing = listing.listing; |
|
40 |
||
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
41 |
var filetablediv = document.getElementById("filetablediv"); |
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
42 |
var specialhomediv; |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
43 |
var h2; |
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
44 |
var h3; |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
45 |
var ul; |
46 |
var li; |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
47 |
var div; |
48 |
||
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
49 |
/* Wrap all this "special" stuff in a div, for styling purposes */
|
50 |
specialhomediv = document.createElement("div"); |
|
51 |
specialhomediv.setAttribute("id", "specialhome"); |
|
52 |
filetablediv.appendChild(specialhomediv); |
|
53 |
||
54 |
/* SUBJECTS Section
|
|
55 |
/* Create the header row */
|
|
56 |
if (subjects.length > 0) |
|
57 |
{
|
|
58 |
h2 = dom_make_text_elem("h2", "Subjects"); |
|
59 |
specialhomediv.appendChild(h2); |
|
60 |
}
|
|
61 |
||
62 |
/* Create the contents */
|
|
63 |
for (var i=0; i<subjects.length; i++) |
|
64 |
{
|
|
65 |
var subject = subjects[i]; |
|
66 |
var subjpath = subject.subj_short_name; |
|
67 |
// Header, with link to offering home page.
|
|
1791.1.2
by David Coles
File Browser: Make sure we close subject name's <h3>. |
68 |
h3 = $('<h3><span class="subjname"></span><span style="font-weight: normal"><span class="semester"></span> – <a class="subjectaction">Subject home</a></span></h3>'); |
1686
by Matt Giuca
Specialhome now shows the semester name for any non-current offerings. userservice/get_enrolments now returns the 'state' property of an offering (past, current, future, etc). This fixes Launchpad bug #526838. |
69 |
h3.find('.subjname').text(subject.subj_name); |
70 |
/* Non-current offerings need to show the semester, to avoid confusion
|
|
71 |
* about which offering we are talking about */
|
|
72 |
if (subject.state != "current") |
|
73 |
{
|
|
1822.1.1
by William Grant
Replace semester.semester with semester.{code,url_name,display_name}. |
74 |
h3.find('.semester').text(" (" + subject.year + " " + subject.semester_display + ")"); |
1686
by Matt Giuca
Specialhome now shows the semester name for any non-current offerings. userservice/get_enrolments now returns the 'state' property of an offering (past, current, future, etc). This fixes Launchpad bug #526838. |
75 |
}
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
76 |
h3.find('a').attr('href', subject.url); |
77 |
$(specialhomediv).append(h3); |
|
78 |
||
79 |
/* Print the file listing */
|
|
80 |
ul = document.createElement("ul"); |
|
81 |
// Stuff
|
|
82 |
ul.appendChild(make_subject_item(subjpath, |
|
83 |
path_join("users", username, subjpath), PERSONALDIR, |
|
84 |
"Your own files in this subject")); |
|
85 |
||
86 |
// Groups
|
|
87 |
var groups = subject.groups; |
|
88 |
for (var j=0; j<subject.groups.length; j++) |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
89 |
{
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
90 |
var group = subject.groups[j]; |
91 |
ul.appendChild(make_subject_item(subjpath, |
|
92 |
path_join("groups", subject.subj_short_name + "_" + |
|
1822.1.1
by William Grant
Replace semester.semester with semester.{code,url_name,display_name}. |
93 |
subject.year + "_" + subject.semester_url + "_" + |
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
94 |
group.name), |
95 |
group.name, |
|
96 |
"This group's files in this subject")); |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
97 |
}
|
98 |
||
955
by mattgiuca
browser: Restyled "special home" page. Now much more in-line with the existing |
99 |
specialhomediv.appendChild(ul); |
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
100 |
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
101 |
/* Remove it from listing */
|
102 |
if (subject.subj_short_name in listing) |
|
103 |
delete listing[subject.subj_short_name]; |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
104 |
}
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
105 |
|
106 |
/* FIXME: Old Subjects? */
|
|
107 |
||
108 |
/* STUFF Section -- For the stuff directory */
|
|
109 |
/* Create the header */
|
|
110 |
h2 = dom_make_text_elem("h2", "Stuff"); |
|
111 |
specialhomediv.appendChild(h2); |
|
112 |
/* Create the contents */
|
|
113 |
ul = document.createElement("ul"); |
|
114 |
ul.appendChild(make_subject_item("", |
|
115 |
path_join("users", username, "stuff"), "stuff", |
|
116 |
"Your own files not related to a subject")); |
|
117 |
specialhomediv.appendChild(ul); |
|
118 |
/* Remove stuff from the listing */
|
|
119 |
if ("stuff" in listing) |
|
120 |
delete listing["stuff"]; |
|
121 |
||
122 |
/* JUNK Section -- All the rest */
|
|
123 |
/* Create the header row */
|
|
124 |
if (obj_length(listing) > 0) |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
125 |
{
|
1670
by Matt Giuca
specialhome.js: Refactor so home_listing (now special_home_listing) is ONLY called if the special home is used, rather than all the time. browser.js: Now calls special_home_listing conditionally. |
126 |
h2 = dom_make_text_elem("h2", "Junk"); |
127 |
specialhomediv.appendChild(h2); |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
128 |
handle_dir_listing(path, listing); |
129 |
}
|
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
130 |
}
|
131 |
||
132 |
/* Does an series of AJAX requests to find out the properties of this folder
|
|
133 |
* and then updates the folder view
|
|
134 |
*/
|
|
997
by wagrant
specialhome: Support group workspaces! Yay! Involved a bit of poking to |
135 |
function make_subject_item(path, repopath, name, description) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
136 |
{
|
137 |
// Create the temporary item
|
|
138 |
var li = document.createElement("li"); |
|
139 |
var span; |
|
140 |
li.setAttribute("class", "listing-loading"); |
|
951
by wagrant
specialhome: Make nonexistent directories a little nicer, with titles |
141 |
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 |
142 |
span = dom_make_text_elem("loading..."); |
143 |
span.setAttribute("class","status"); |
|
144 |
li.appendChild(span); |
|
145 |
||
146 |
// Set the callback function to update when we get the real details
|
|
147 |
var callback = function(response) |
|
148 |
{
|
|
149 |
var sublisting = decode_response(response); |
|
150 |
dom_removechildren(li); |
|
151 |
li.setAttribute("class", "listing-dir"); |
|
152 |
||
153 |
// If we could find the file status...
|
|
154 |
if (sublisting != null) |
|
155 |
{
|
|
156 |
var thisdir = sublisting.listing['.']; |
|
157 |
var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned"); |
|
158 |
if (versioned) |
|
159 |
{
|
|
160 |
// Default: Just offer a link to the directory
|
|
161 |
li.appendChild(dom_make_link_elem("span", name, description, |
|
162 |
app_path(this_app, username, path, name))); |
|
163 |
}
|
|
164 |
else
|
|
165 |
{
|
|
166 |
// Blocked: Offer to rename the directory
|
|
952
by wagrant
specialhome: Also be nice if a directory is blocked. |
167 |
li.appendChild(dom_make_text_elem("span", name, description)); |
168 |
span = dom_make_text_elem("span", " (blocked) ", |
|
169 |
"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 |
170 |
span.setAttribute("class", "status"); |
171 |
li.appendChild(span); |
|
172 |
||
173 |
var button = document.createElement("input"); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
174 |
$(button).click(function(event) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
175 |
{
|
176 |
action_rename(path_join(path, name)); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
177 |
});
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
178 |
button.setAttribute("type", "button"); |
179 |
button.setAttribute("value", "Rename"); |
|
180 |
span.appendChild(button); |
|
181 |
}
|
|
182 |
}
|
|
1626
by Matt Giuca
specialhome.js: Previously assumed 'missing' if a directory listing couldn't be retrieved. Now checks for 404 status. Any other status, prints 'error -- contact system administrator', because clicking Checkout won't help you. |
183 |
else if (response.status == 404) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
184 |
{
|
185 |
// Missing: Try to check out or create the repository
|
|
951
by wagrant
specialhome: Make nonexistent directories a little nicer, with titles |
186 |
li.appendChild(dom_make_text_elem("span", name, description)); |
187 |
span = dom_make_text_elem("span", " (missing) ", |
|
188 |
"This directory does not yet exist."); |
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
189 |
span.setAttribute("class", "status"); |
190 |
li.appendChild(span); |
|
191 |
||
192 |
var button = document.createElement("input"); |
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
193 |
$(button).click(function(event) |
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
194 |
{
|
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
195 |
li.setAttribute("class", "listing-loading"); |
196 |
||
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
197 |
var localpath = path_join(path, name); |
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
198 |
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
199 |
if (create_if_needed(repopath)) |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
200 |
{
|
201 |
// Try a checkout
|
|
1326.1.2
by David Coles
Small refactor of browser's JavaScript to allow do_action to be called from |
202 |
do_act("svncheckout", {"path": [repopath, localpath]}); |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
203 |
}
|
947
by wagrant
specialhome: Display the classic AJAX loading animation while |
204 |
else
|
205 |
{
|
|
206 |
li.setAttribute("class", "listing-dir"); |
|
207 |
}
|
|
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
208 |
});
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
209 |
button.setAttribute("type", "button"); |
210 |
button.setAttribute("value", "Checkout"); |
|
211 |
span.appendChild(button); |
|
212 |
}
|
|
1626
by Matt Giuca
specialhome.js: Previously assumed 'missing' if a directory listing couldn't be retrieved. Now checks for 404 status. Any other status, prints 'error -- contact system administrator', because clicking Checkout won't help you. |
213 |
else
|
214 |
{
|
|
215 |
// Error: The directory listing could not be retrieved
|
|
216 |
// Make a link in case the user wants to investigate
|
|
217 |
li.appendChild(dom_make_link_elem("span", name, description, |
|
218 |
app_path(this_app, username, path, name))); |
|
219 |
span = dom_make_text_elem("span", |
|
220 |
" (error \u2013 contact system administrator)", |
|
221 |
"There was an error retrieving information about this "
|
|
222 |
+ "directory."); |
|
223 |
span.setAttribute("class", "status"); |
|
224 |
li.appendChild(span); |
|
225 |
}
|
|
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
226 |
}
|
227 |
||
228 |
/* Are we working in a subdirectory or parent? */
|
|
229 |
ajax_call(callback, service_app, path_join(username, path, name), {}, "GET"); |
|
230 |
return li; |
|
231 |
}
|
|
232 |
||
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
233 |
function create_if_needed(path) |
234 |
{
|
|
235 |
response = ajax_call(null, service_app, current_path, |
|
236 |
{
|
|
237 |
"action": "svnrepostat", |
|
238 |
"path": path |
|
239 |
}, "POST"); |
|
240 |
||
241 |
||
242 |
if (response.status == 200) |
|
243 |
{
|
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
244 |
return true; |
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
245 |
}
|
246 |
else if (response.status == 404) |
|
247 |
{
|
|
248 |
// Try a mkdir
|
|
249 |
r2 = ajax_call(null, service_app, current_path, |
|
250 |
{
|
|
251 |
"action": "svnrepomkdir", |
|
252 |
"path": path, |
|
946
by wagrant
specialhome: Work with per-subject 'mywork' directories, although it |
253 |
"logmsg": "Automated creation of '" + path + "' work directory" |
945
by wagrant
specialhome: Rebrand personal to mywork (by majority), refactor a bit, |
254 |
}, "POST"); |
255 |
||
256 |
if (r2.status == 200) |
|
257 |
{
|
|
258 |
return true; |
|
259 |
}
|
|
260 |
}
|
|
261 |
alert("Error: Could not create Subversion directory"); |
|
262 |
return false; |
|
263 |
}
|
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
264 |
|
265 |
/** Finds the length (number of user defined properties) of an object
|
|
266 |
*/
|
|
267 |
function obj_length(obj) |
|
268 |
{
|
|
1168
by William Grant
Rename length to len in specialhome.js to please IE8. |
269 |
len = 0; |
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
270 |
for (prop in obj) |
1168
by William Grant
Rename length to len in specialhome.js to please IE8. |
271 |
len++; |
272 |
return len; |
|
980
by dcoles
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the |
273 |
}
|