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

« back to all changes in this revision

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

Port ivle.webapp.admin.user's media to the new framework.

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 + " " + subject.semester_display + ")");
75
 
        }
76
 
        h3.find('a').attr('href', subject.url);
77
 
        $(specialhomediv).append(h3);
78
 
    
79
 
        /* Print the file listing */
 
106
        /* Create the contents */
80
107
        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++)
89
 
        {
90
 
            var group = subject.groups[j];
91
 
            ul.appendChild(make_subject_item(subjpath,
92
 
                path_join("groups", subject.subj_short_name + "_" +
93
 
                          subject.year + "_" + subject.semester_url + "_" +
94
 
                          group.name),
95
 
                group.name,
96
 
                "This group's files in this subject"));
97
 
        }
98
 
        
 
108
        ul.appendChild(make_subject_item("",
 
109
              path_join("users", username, "stuff"), "stuff",
 
110
              "Your own files not related to a subject"));
99
111
        specialhomediv.appendChild(ul);
 
112
        /* Remove stuff from the listing */
 
113
        if ("stuff" in listing)
 
114
            delete listing["stuff"];
100
115
 
101
 
        /* Remove it from listing */
102
 
        if (subject.subj_short_name in listing)
103
 
            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
        }
104
124
    }
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)
 
125
    else
125
126
    {
126
 
        h2 = dom_make_text_elem("h2", "Junk");
127
 
        specialhomediv.appendChild(h2);
128
127
        handle_dir_listing(path, listing);
129
128
    }
130
129
}
171
170
                li.appendChild(span);
172
171
 
173
172
                var button = document.createElement("input");
174
 
                $(button).click(function(event)
 
173
                button.addEventListener("click", function(event)
175
174
                {
176
175
                    action_rename(path_join(path, name));
177
 
                });
 
176
                },
 
177
                false);
178
178
                button.setAttribute("type", "button");
179
179
                button.setAttribute("value", "Rename");
180
180
                span.appendChild(button);
181
181
            }
182
182
        }
183
 
        else if (response.status == 404)
 
183
        else
184
184
        {
185
185
            // Missing: Try to check out or create the repository
186
186
            li.appendChild(dom_make_text_elem("span", name, description));
190
190
            li.appendChild(span);
191
191
 
192
192
            var button = document.createElement("input");
193
 
            $(button).click(function(event)
 
193
            button.addEventListener("click", function(event)
194
194
            {
195
195
                li.setAttribute("class", "listing-loading");
196
196
 
199
199
                if (create_if_needed(repopath))
200
200
                {
201
201
                    // Try a checkout
202
 
                    do_act("svncheckout", {"path": [repopath, localpath]});
 
202
                    do_action("svncheckout", current_path, {"path":
 
203
                        [repopath, localpath]});
203
204
                }
204
205
                else
205
206
                {
206
207
                    li.setAttribute("class", "listing-dir");
207
208
                }
208
 
            });
 
209
            },
 
210
            false);
209
211
            button.setAttribute("type", "button");
210
212
            button.setAttribute("value", "Checkout");
211
213
            span.appendChild(button);
212
214
        }
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
 
        }
226
215
    }
227
216
 
228
217
    /* Are we working in a subdirectory or parent? */
266
255
 */
267
256
function obj_length(obj)
268
257
{
269
 
    len = 0;
 
258
    length = 0;
270
259
    for (prop in obj)
271
 
        len++;
272
 
    return len;
 
260
        length++;
 
261
    return length;
273
262
}