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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-07-23 07:38:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:944
Special Home Directory: Work to create a special home directory that shows the 
subjects you are enrolled in, the repositories that you have for those subjects 
and aranges the files in a sensible fashion. (See bugtracker [ 2010232 ] Home 
directory: special user interface)

This should also support showing group repositories at a later date.

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="personal"
 
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 h1;
 
40
    var h2;
 
41
    var ul;
 
42
    var li;
 
43
 
 
44
    /* SUBJECTS Section
 
45
    /* Create the header row */
 
46
    h1 = dom_make_text_elem("h1", "Subjects");
 
47
    filetablediv.appendChild(h1);
 
48
    /* Create the contents */
 
49
    for (var i=0; i<subjects.length; i++)
 
50
    {
 
51
        var subject = subjects[i];
 
52
        var path = subject.subj_short_name;
 
53
        // Header
 
54
        h2 = dom_make_text_elem("h2", subject.subj_name);
 
55
        filetablediv.appendChild(h2);
 
56
        
 
57
        /* Print the file listing */
 
58
        ul = document.createElement("ul");
 
59
        // Stuff
 
60
        ul.appendChild(make_subject_item(path, "personal", "Your personal files here"));
 
61
        // Groups
 
62
        /* TODO: List groups */
 
63
            
 
64
        filetablediv.appendChild(ul);
 
65
 
 
66
        /* Remove it from listing */
 
67
        if (subject.subj_short_name in listing)
 
68
            delete listing[subject.subj_short_name];
 
69
    }
 
70
   
 
71
    /* FIXME: Old Subjects? */
 
72
 
 
73
    /* STUFF Section -- For the stuff directory */
 
74
    /* Create the header */
 
75
    h1 = dom_make_text_elem("h1", "Stuff");
 
76
    filetablediv.appendChild(h1);
 
77
    /* Create the contents */
 
78
    ul = document.createElement("ul");
 
79
    ul.appendChild(make_subject_item("", "stuff", "stuff"));
 
80
    filetablediv.appendChild(ul);
 
81
    /* Remove stuff from the listing */
 
82
    if ("stuff" in listing)
 
83
        delete listing["stuff"];
 
84
 
 
85
    /* JUNK Section -- All the rest */
 
86
    /* Create the header row */
 
87
    h1 = dom_make_text_elem("h1", "Junk");
 
88
    filetablediv.appendChild(h1);
 
89
}
 
90
 
 
91
/* Does an series of AJAX requests to find out the properties of this folder 
 
92
 * and then updates the folder view
 
93
 */
 
94
function make_subject_item(path, name, description)
 
95
{
 
96
    // Create the temporary item
 
97
    var li = document.createElement("li");
 
98
    var span;
 
99
    li.setAttribute("class", "listing-loading");
 
100
    li.appendChild(dom_make_text_elem("span", name));
 
101
    span = dom_make_text_elem("loading...");
 
102
    span.setAttribute("class","status");
 
103
    li.appendChild(span);
 
104
 
 
105
    // Set the callback function to update when we get the real details
 
106
    var callback = function(response)
 
107
    {
 
108
        var sublisting = decode_response(response);
 
109
        dom_removechildren(li);
 
110
        li.setAttribute("class", "listing-dir");
 
111
 
 
112
        // If we could find the file status...
 
113
        if (sublisting != null)
 
114
        {
 
115
            var thisdir = sublisting.listing['.'];
 
116
            var versioned = ("svnstatus" in thisdir) && (thisdir.svnstatus != "unversioned");
 
117
            if (versioned)
 
118
            {
 
119
                // Default: Just offer a link to the directory
 
120
                li.appendChild(dom_make_link_elem("span", name, description,
 
121
                    app_path(this_app, username, path, name)));
 
122
            }
 
123
            else
 
124
            {
 
125
                // Blocked: Offer to rename the directory
 
126
                li.appendChild(dom_make_text_elem("span", name));
 
127
                span = dom_make_text_elem("span", "blocked");
 
128
                span.setAttribute("class", "status");
 
129
                li.appendChild(span);
 
130
 
 
131
                var button = document.createElement("input");
 
132
                button.addEventListener("click", function(event)
 
133
                {
 
134
                    action_rename(path_join(path, name));
 
135
 
 
136
                    // FIXME: Also do checkout here?
 
137
                },
 
138
                false);
 
139
                button.setAttribute("type", "button");
 
140
                button.setAttribute("value", "Rename");
 
141
                span.appendChild(button);
 
142
            }
 
143
        }
 
144
        else
 
145
        {
 
146
            // Missing: Try to check out or create the repository
 
147
            li.appendChild(dom_make_text_elem("span", name));
 
148
            span = dom_make_text_elem("span", "missing");
 
149
            span.setAttribute("class", "status");
 
150
            li.appendChild(span);
 
151
 
 
152
            var button = document.createElement("input");
 
153
            button.addEventListener("click", function(event)
 
154
            {   
 
155
                // Get repository stat
 
156
                response = ajax_call(null, service_app, current_path,
 
157
                    {
 
158
                        "action": "svnrepostat",
 
159
                        "path": path_join(username, path, name)
 
160
                    }, "POST");
 
161
 
 
162
                if (response.status == 200)
 
163
                {
 
164
                    // Try a checkout
 
165
                    do_action("svncheckout", current_path, {"path":
 
166
                        [
 
167
                            path_join(username, path, name), // url
 
168
                            path_join(path, name) // localpath
 
169
                        ]});
 
170
                }
 
171
                else if (response.status == 404)
 
172
                {
 
173
                    // Try a mkdir
 
174
                    do_action("svnrepomkdir", current_path,
 
175
                        {
 
176
                            "path": path_join(username, path, name),
 
177
                            "logmsg": "Automated creation of '" + name + "' work directory"
 
178
                        });
 
179
                }
 
180
                else
 
181
                {
 
182
                    alert("Error: Could not Create repository");
 
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