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

« back to all changes in this revision

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

  • Committer: me at id
  • Date: 2009-01-15 01:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1147
ivle.makeuser: Don't create a local.auth. It wasn't used anywhere, and seems
    to have only been there for historical reasons.
setup.configure: Remove svn_auth_local from the config.py boilerplate; it was
    used solely by ivle.makeuser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
/* LAYOUT FUNCTIONS */
32
32
 
33
 
/** Present special home directory. This is only called if in the top level.
34
 
 * Subjects must not be null.
 
33
/** Present home directory 
35
34
 */
36
 
function special_home_listing(listing, subjects, path)
 
35
function home_listing(listing, subjects, path)
37
36
{
38
37
    /* Nav through the top-level of the JSON to the actual listing object. */
39
38
    var listing = listing.listing;
46
45
    var li;
47
46
    var div;
48
47
 
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)
 
48
    /* Only show special headings if we get subject listings */
 
49
    if (subjects != null)
57
50
    {
58
 
        h2 = dom_make_text_elem("h2", "Subjects");
 
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
 
76
            ul.appendChild(make_subject_item(subjpath,
 
77
                path_join("users", username, subjpath), PERSONALDIR,
 
78
                "Your own files in this subject"));
 
79
 
 
80
            // Groups
 
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
            }
 
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");
59
105
        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.
68
 
        h3 = $('<h3><span class="subjname"></span><span style="font-weight: normal"><span class="semester"></span> &ndash; <a class="subjectaction">Subject home</a></span></h3>');
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
 
        {
74
 
            h3.find('.semester').text(" (" + subject.year + ", semester "
75
 
                                      + subject.semester + ")");
76
 
        }
77
 
        h3.find('a').attr('href', subject.url);
78
 
        $(specialhomediv).append(h3);
79
 
    
80
 
        /* Print the file listing */
 
106
        /* Create the contents */
81
107
        ul = document.createElement("ul");
82
 
        // Stuff
83
 
        ul.appendChild(make_subject_item(subjpath,
84
 
            path_join("users", username, subjpath), PERSONALDIR,
85
 
            "Your own files in this subject"));
86
 
 
87
 
        // Groups
88
 
        var groups = subject.groups;
89
 
        for (var j=0; j<subject.groups.length; j++)
90
 
        {
91
 
            var group = subject.groups[j];
92
 
            ul.appendChild(make_subject_item(subjpath,
93
 
                path_join("groups", subject.subj_short_name + "_" +
94
 
                          subject.year + "_" + subject.semester + "_" +
95
 
                          group.name),
96
 
                group.name,
97
 
                "This group's files in this subject"));
98
 
        }
99
 
        
 
108
        ul.appendChild(make_subject_item("",
 
109
              path_join("users", username, "stuff"), "stuff",
 
110
              "Your own files not related to a subject"));
100
111
        specialhomediv.appendChild(ul);
 
112
        /* Remove stuff from the listing */
 
113
        if ("stuff" in listing)
 
114
            delete listing["stuff"];
101
115
 
102
 
        /* Remove it from listing */
103
 
        if (subject.subj_short_name in listing)
104
 
            delete listing[subject.subj_short_name];
 
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
        }
105
124
    }
106
 
 
107
 
    /* FIXME: Old Subjects? */
108
 
 
109
 
    /* STUFF Section -- For the stuff directory */
110
 
    /* Create the header */
111
 
    h2 = dom_make_text_elem("h2", "Stuff");
112
 
    specialhomediv.appendChild(h2);
113
 
    /* Create the contents */
114
 
    ul = document.createElement("ul");
115
 
    ul.appendChild(make_subject_item("",
116
 
          path_join("users", username, "stuff"), "stuff",
117
 
          "Your own files not related to a subject"));
118
 
    specialhomediv.appendChild(ul);
119
 
    /* Remove stuff from the listing */
120
 
    if ("stuff" in listing)
121
 
        delete listing["stuff"];
122
 
 
123
 
    /* JUNK Section -- All the rest */
124
 
    /* Create the header row */
125
 
    if (obj_length(listing) > 0)
 
125
    else
126
126
    {
127
 
        h2 = dom_make_text_elem("h2", "Junk");
128
 
        specialhomediv.appendChild(h2);
129
127
        handle_dir_listing(path, listing);
130
128
    }
131
129
}
172
170
                li.appendChild(span);
173
171
 
174
172
                var button = document.createElement("input");
175
 
                $(button).click(function(event)
 
173
                button.addEventListener("click", function(event)
176
174
                {
177
175
                    action_rename(path_join(path, name));
178
 
                });
 
176
                },
 
177
                false);
179
178
                button.setAttribute("type", "button");
180
179
                button.setAttribute("value", "Rename");
181
180
                span.appendChild(button);
182
181
            }
183
182
        }
184
 
        else if (response.status == 404)
 
183
        else
185
184
        {
186
185
            // Missing: Try to check out or create the repository
187
186
            li.appendChild(dom_make_text_elem("span", name, description));
191
190
            li.appendChild(span);
192
191
 
193
192
            var button = document.createElement("input");
194
 
            $(button).click(function(event)
 
193
            button.addEventListener("click", function(event)
195
194
            {
196
195
                li.setAttribute("class", "listing-loading");
197
196
 
200
199
                if (create_if_needed(repopath))
201
200
                {
202
201
                    // Try a checkout
203
 
                    do_act("svncheckout", {"path": [repopath, localpath]});
 
202
                    do_action("svncheckout", current_path, {"path":
 
203
                        [repopath, localpath]});
204
204
                }
205
205
                else
206
206
                {
207
207
                    li.setAttribute("class", "listing-dir");
208
208
                }
209
 
            });
 
209
            },
 
210
            false);
210
211
            button.setAttribute("type", "button");
211
212
            button.setAttribute("value", "Checkout");
212
213
            span.appendChild(button);
213
214
        }
214
 
        else
215
 
        {
216
 
            // Error: The directory listing could not be retrieved
217
 
            // Make a link in case the user wants to investigate
218
 
            li.appendChild(dom_make_link_elem("span", name, description,
219
 
                app_path(this_app, username, path, name)));
220
 
            span = dom_make_text_elem("span",
221
 
                  " (error \u2013 contact system administrator)",
222
 
                  "There was an error retrieving information about this "
223
 
                  + "directory.");
224
 
            span.setAttribute("class", "status");
225
 
            li.appendChild(span);
226
 
        }
227
215
    }
228
216
 
229
217
    /* Are we working in a subdirectory or parent? */
267
255
 */
268
256
function obj_length(obj)
269
257
{
270
 
    len = 0;
 
258
    length = 0;
271
259
    for (prop in obj)
272
 
        len++;
273
 
    return len;
 
260
        length++;
 
261
    return length;
274
262
}