~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-08-05 02:06:49 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:980
Files: "Junk" is now only shown when other (non-subject/stuff) files are in the 
top level directory. Also refactored the code a bit to support this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
/** Present home directory 
34
34
 */
35
 
function home_listing(listing, subjects)
 
35
function home_listing(listing, subjects, path)
36
36
{
37
 
    listing = listing.listing;
 
37
    /* Nav through the top-level of the JSON to the actual listing object. */
 
38
    var listing = listing.listing;
 
39
    
38
40
    var filetablediv = document.getElementById("filetablediv");
39
41
    var specialhomediv;
40
42
    var h2;
41
43
    var h3;
42
44
    var ul;
43
45
    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)
 
46
    var div;
 
47
 
 
48
    /* Only show special headings if we get subject listings */
 
49
    if (subjects != null)
53
50
    {
54
 
        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, PERSONALDIR,
 
77
                "Your own files in this subject"));
 
78
            // Groups
 
79
            /* TODO: List groups */
 
80
            
 
81
            specialhomediv.appendChild(ul);
 
82
 
 
83
            /* Remove it from listing */
 
84
            if (subject.subj_short_name in listing)
 
85
                delete listing[subject.subj_short_name];
 
86
        }
 
87
 
 
88
        /* FIXME: Old Subjects? */
 
89
 
 
90
        /* STUFF Section -- For the stuff directory */
 
91
        /* Create the header */
 
92
        h2 = dom_make_text_elem("h2", "Stuff");
55
93
        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 */
 
94
        /* Create the contents */
68
95
        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
 
            
 
96
        ul.appendChild(make_subject_item("", "stuff",
 
97
              "Your own files not related to a subject"));
75
98
        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);
 
99
        /* Remove stuff from the listing */
 
100
        if ("stuff" in listing)
 
101
            delete listing["stuff"];
 
102
 
 
103
        /* JUNK Section -- All the rest */
 
104
        /* Create the header row */
 
105
        if (obj_length(listing) > 0)
 
106
        {
 
107
            h2 = dom_make_text_elem("h2", "Junk");
 
108
            specialhomediv.appendChild(h2);
 
109
            handle_dir_listing(path, listing);
 
110
        }
 
111
    }
 
112
    else
 
113
    {
 
114
        handle_dir_listing(path, listing);
 
115
    }
101
116
}
102
117
 
103
118
/* Does an series of AJAX requests to find out the properties of this folder 
225
240
    alert("Error: Could not create Subversion directory");
226
241
    return false;
227
242
}
 
243
 
 
244
/** Finds the length (number of user defined properties) of an object
 
245
 */
 
246
function obj_length(obj)
 
247
{
 
248
    length = 0;
 
249
    for (prop in obj)
 
250
        length++;
 
251
    return length;
 
252
}