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

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/browser/media/specialhome.js

  • Committer: Matt Giuca
  • Date: 2010-02-23 07:42:32 UTC
  • Revision ID: matt.giuca@gmail.com-20100223074232-atq05s66gxa5h7on
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
/* LAYOUT FUNCTIONS */
32
32
 
33
 
/** Present home directory 
 
33
/** Present special home directory. This is only called if in the top level.
 
34
 * Subjects must not be null.
34
35
 */
35
 
function home_listing(listing, subjects, path)
 
36
function special_home_listing(listing, subjects, path)
36
37
{
37
38
    /* Nav through the top-level of the JSON to the actual listing object. */
38
39
    var listing = listing.listing;
45
46
    var li;
46
47
    var div;
47
48
 
48
 
    /* Only show special headings if we get subject listings */
49
 
    if (subjects != null)
50
 
    {
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)
 
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.
 
68
        h3 = $('<h3><span></span> <span style="font-weight: normal">&ndash; <a class="subjectaction">Subject home</a></span>');
 
69
        h3.find('span:first-child').text(subject.subj_name);
 
70
        h3.find('a').attr('href', subject.url);
 
71
        $(specialhomediv).append(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++)
59
83
        {
60
 
            h2 = dom_make_text_elem("h2", "Subjects");
61
 
            specialhomediv.appendChild(h2);
 
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"));
62
91
        }
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, with link to offering home page.
70
 
            h3 = $('<h3><span></span> <span style="font-weight: normal">&ndash; <a class="subjectaction">Subject home</a></span>');
71
 
            h3.find('span:first-child').text(subject.subj_name);
72
 
            h3.find('a').attr('href', subject.url);
73
 
            $(specialhomediv).append(h3);
74
92
        
75
 
            /* Print the file listing */
76
 
            ul = document.createElement("ul");
77
 
            // Stuff
78
 
            ul.appendChild(make_subject_item(subjpath,
79
 
                path_join("users", username, subjpath), PERSONALDIR,
80
 
                "Your own files in this subject"));
81
 
 
82
 
            // Groups
83
 
            var groups = subject.groups;
84
 
            for (var j=0; j<subject.groups.length; j++)
85
 
            {
86
 
                var group = subject.groups[j];
87
 
                ul.appendChild(make_subject_item(subjpath,
88
 
                    path_join("groups", subject.subj_short_name + "_" +
89
 
                              subject.year + "_" + subject.semester + "_" +
90
 
                              group.name),
91
 
                    group.name,
92
 
                    "This group's files in this subject"));
93
 
            }
94
 
            
95
 
            specialhomediv.appendChild(ul);
96
 
 
97
 
            /* Remove it from listing */
98
 
            if (subject.subj_short_name in listing)
99
 
                delete listing[subject.subj_short_name];
100
 
        }
101
 
 
102
 
        /* FIXME: Old Subjects? */
103
 
 
104
 
        /* STUFF Section -- For the stuff directory */
105
 
        /* Create the header */
106
 
        h2 = dom_make_text_elem("h2", "Stuff");
107
 
        specialhomediv.appendChild(h2);
108
 
        /* Create the contents */
109
 
        ul = document.createElement("ul");
110
 
        ul.appendChild(make_subject_item("",
111
 
              path_join("users", username, "stuff"), "stuff",
112
 
              "Your own files not related to a subject"));
113
93
        specialhomediv.appendChild(ul);
114
 
        /* Remove stuff from the listing */
115
 
        if ("stuff" in listing)
116
 
            delete listing["stuff"];
117
94
 
118
 
        /* JUNK Section -- All the rest */
119
 
        /* Create the header row */
120
 
        if (obj_length(listing) > 0)
121
 
        {
122
 
            h2 = dom_make_text_elem("h2", "Junk");
123
 
            specialhomediv.appendChild(h2);
124
 
            handle_dir_listing(path, listing);
125
 
        }
 
95
        /* Remove it from listing */
 
96
        if (subject.subj_short_name in listing)
 
97
            delete listing[subject.subj_short_name];
126
98
    }
127
 
    else
 
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");
 
105
    specialhomediv.appendChild(h2);
 
106
    /* Create the contents */
 
107
    ul = document.createElement("ul");
 
108
    ul.appendChild(make_subject_item("",
 
109
          path_join("users", username, "stuff"), "stuff",
 
110
          "Your own files not related to a subject"));
 
111
    specialhomediv.appendChild(ul);
 
112
    /* Remove stuff from the listing */
 
113
    if ("stuff" in listing)
 
114
        delete listing["stuff"];
 
115
 
 
116
    /* JUNK Section -- All the rest */
 
117
    /* Create the header row */
 
118
    if (obj_length(listing) > 0)
128
119
    {
 
120
        h2 = dom_make_text_elem("h2", "Junk");
 
121
        specialhomediv.appendChild(h2);
129
122
        handle_dir_listing(path, listing);
130
123
    }
131
124
}