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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
29
 
PERSONALDIR="mywork"
30
 
 
31
 
/* LAYOUT FUNCTIONS */
32
 
 
33
 
/** Present home directory 
34
 
 */
35
 
function home_listing(listing, subjects)
36
 
{
37
 
    listing = listing.listing;
38
 
    var filetablediv = document.getElementById("filetablediv");
39
 
    var specialhomediv;
40
 
    var h2;
41
 
    var h3;
42
 
    var ul;
43
 
    var li;
44
 
 
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);
49
 
 
50
 
    /* SUBJECTS Section
51
 
    /* Create the header row */
52
 
    if (subjects.length > 0)
53
 
    {
54
 
        h2 = dom_make_text_elem("h2", "Subjects");
55
 
        specialhomediv.appendChild(h2);
56
 
    }
57
 
 
58
 
    /* Create the contents */
59
 
    for (var i=0; i<subjects.length; i++)
60
 
    {
61
 
        var subject = subjects[i];
62
 
        var path = subject.subj_short_name;
63
 
        // Header
64
 
        h3 = dom_make_text_elem("h3", subject.subj_name);
65
 
        specialhomediv.appendChild(h3);
66
 
        
67
 
        /* Print the file listing */
68
 
        ul = document.createElement("ul");
69
 
        // Stuff
70
 
        ul.appendChild(make_subject_item(path, PERSONALDIR,
71
 
              "Your own files in this subject"));
72
 
        // Groups
73
 
        /* TODO: List groups */
74
 
            
75
 
        specialhomediv.appendChild(ul);
76
 
 
77
 
        /* Remove it from listing */
78
 
        if (subject.subj_short_name in listing)
79
 
            delete listing[subject.subj_short_name];
80
 
    }
81
 
   
82
 
    /* FIXME: Old Subjects? */
83
 
 
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"];
96
 
 
97
 
    /* JUNK Section -- All the rest */
98
 
    /* Create the header row */
99
 
    h2 = dom_make_text_elem("h2", "Junk");
100
 
    specialhomediv.appendChild(h2);
101
 
}
102
 
 
103
 
/* Does an series of AJAX requests to find out the properties of this folder 
104
 
 * and then updates the folder view
105
 
 */
106
 
function make_subject_item(path, name, description)
107
 
{
108
 
    // Create the temporary item
109
 
    var li = document.createElement("li");
110
 
    var span;
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);
116
 
 
117
 
    // Set the callback function to update when we get the real details
118
 
    var callback = function(response)
119
 
    {
120
 
        var sublisting = decode_response(response);
121
 
        dom_removechildren(li);
122
 
        li.setAttribute("class", "listing-dir");
123
 
 
124
 
        // If we could find the file status...
125
 
        if (sublisting != null)
126
 
        {
127
 
            var thisdir = sublisting.listing['.'];
128
 
            var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned");
129
 
            if (versioned)
130
 
            {
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)));
134
 
            }
135
 
            else
136
 
            {
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);
143
 
 
144
 
                var button = document.createElement("input");
145
 
                button.addEventListener("click", function(event)
146
 
                {
147
 
                    action_rename(path_join(path, name));
148
 
                },
149
 
                false);
150
 
                button.setAttribute("type", "button");
151
 
                button.setAttribute("value", "Rename");
152
 
                span.appendChild(button);
153
 
            }
154
 
        }
155
 
        else
156
 
        {
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);
163
 
 
164
 
            var button = document.createElement("input");
165
 
            button.addEventListener("click", function(event)
166
 
            {
167
 
                li.setAttribute("class", "listing-loading");
168
 
 
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);
173
 
 
174
 
                if (create_if_needed(repopath))
175
 
                {
176
 
                    // Try a checkout
177
 
                    do_action("svncheckout", current_path, {"path":
178
 
                        [repopath, localpath]});
179
 
                }
180
 
                else
181
 
                {
182
 
                    li.setAttribute("class", "listing-dir");
183
 
                }
184
 
            },
185
 
            false);
186
 
            button.setAttribute("type", "button");
187
 
            button.setAttribute("value", "Checkout");
188
 
            span.appendChild(button);
189
 
        }
190
 
    }
191
 
 
192
 
    /* Are we working in a subdirectory or parent? */
193
 
    ajax_call(callback, service_app, path_join(username, path, name), {}, "GET");
194
 
    return li;
195
 
}
196
 
 
197
 
function create_if_needed(path)
198
 
{
199
 
    response = ajax_call(null, service_app, current_path,
200
 
            {
201
 
                "action": "svnrepostat",
202
 
                "path": path
203
 
            }, "POST");
204
 
 
205
 
 
206
 
    if (response.status == 200)
207
 
    {
208
 
        return true;
209
 
    }
210
 
    else if (response.status == 404)
211
 
    {
212
 
        // Try a mkdir
213
 
        r2 = ajax_call(null, service_app, current_path,
214
 
                {
215
 
                    "action": "svnrepomkdir",
216
 
                    "path": path,
217
 
                    "logmsg": "Automated creation of '" + path + "' work directory"
218
 
                }, "POST");
219
 
 
220
 
        if (r2.status == 200)
221
 
        {
222
 
            return true;
223
 
        }
224
 
    }
225
 
    alert("Error: Could not create Subversion directory");
226
 
    return false;
227
 
}