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

« back to all changes in this revision

Viewing changes to www/media/groups/groups.js

  • Committer: dcoles
  • Date: 2008-07-03 04:20:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:803
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should 
allow us to get in there and tidy up each module much easier. Also removed 
updatejails since this functionality seems to be duplicated with remakeuser.py 
and remakealluser.py scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* IVLE - Informatics Virtual Learning Environment
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
 
 * Module: Group management system (client)
19
 
 * Author: Matt Giuca
20
 
 * Date: 21/7/2008
21
 
 */
22
 
 
23
 
serviceapp = 'userservice';
24
 
 
25
 
function create(offeringid)
26
 
{
27
 
    /* TODO: Write this function */
28
 
}
29
 
 
30
 
/* Displays the selected group in the group adminsitration area
31
 
 */
32
 
function manage_subject()
33
 
{
34
 
    /* Get the subject id from the select box */
35
 
    var subject_select = document.getElementById("subject_select");
36
 
    var subject_div = document.getElementById("subject_div");
37
 
    var subjectid = parseInt(subject_select.value);
38
 
 
39
 
    /* List active offerings */
40
 
    dom_removechildren(subject_div);
41
 
    var p = dom_make_text_elem("h2", "Active Offerings");
42
 
    subject_div.appendChild(p);
43
 
    var callback = function(xhr) 
44
 
    {
45
 
        var offerings = JSON.parse(xhr.responseText);
46
 
        for (var i=0; i<offerings.length; i++)
47
 
        {
48
 
            var offering = offerings[i];
49
 
            var text = offering.subj_name + ", Semester " + offering.semester + " " + offering.year;
50
 
            var h3 = dom_make_text_elem("h3", text);
51
 
            subject_div.appendChild(h3);
52
 
            var div = document.createElement("div");
53
 
            subject_div.appendChild(div);
54
 
            manage_subject_offering(offering['offeringid'], div);
55
 
        }
56
 
    }
57
 
    ajax_call(callback, serviceapp, 'get_active_offerings', {'subjectid': subjectid}, 'GET');
58
 
}
59
 
 
60
 
/* Manages the display of a single offerings groups
61
 
 * Takes a offeringid and element to attach the results to
62
 
 */
63
 
function manage_subject_offering(offeringid, elem)
64
 
{
65
 
    var callback = function(xhr)
66
 
    {
67
 
        var projectsets = JSON.parse(xhr.responseText);
68
 
        var dl = document.createElement("dl");
69
 
        elem.appendChild(dl);
70
 
        /* Add details for each project set */
71
 
        for (var i=0; i<projectsets.length; i++)
72
 
        {
73
 
            var projectset = projectsets[i];
74
 
            var groups = projectset.groups;
75
 
            
76
 
            var dt = dom_make_text_elem("dt", "Project Set "+(i+1)+" ");
77
 
            dl.appendChild(dt);
78
 
            var dd = document.createElement("dd");
79
 
            var ul = document.createElement("ul");
80
 
            dd.appendChild(ul);
81
 
            /* Add each group in the project set */
82
 
            for (var j=0; j<groups.length; j++)
83
 
            {
84
 
                var group = groups[j];
85
 
                var namespace = "project_group_" + group.groupid;
86
 
                var li = dom_make_text_elem("li", group['groupnm']+" ");
87
 
                li.id = namespace;
88
 
                var button = document.createElement("a");
89
 
                button.id = namespace+"_button";
90
 
                button.setAttribute("class", "choice");
91
 
                button.textContent = '(manage)';
92
 
                button.setAttribute("onclick",
93
 
                    "manage_group("+offeringid+","+group.groupid+",'"+namespace+"')");
94
 
                li.appendChild(button);
95
 
                ul.appendChild(li);
96
 
            }
97
 
            var li = dom_make_text_elem("li", "");
98
 
            var input = document.createElement("input");
99
 
            input.value = "New";
100
 
            input.type = 'button';
101
 
            input.setAttribute("onclick", "create_new_group("+projectset['projectsetid']+")");
102
 
            li.appendChild(input);
103
 
            ul.appendChild(li);
104
 
            dl.appendChild(dd);
105
 
        }
106
 
    }
107
 
    ajax_call(callback, serviceapp, 'get_project_groups', {'offeringid': offeringid}, 'GET');
108
 
}
109
 
 
110
 
/* Creates a group */
111
 
function create_new_group(projectsetid)
112
 
{
113
 
    groupnm = window.prompt('Please enter a name for the group');
114
 
    args = {'projectsetid': projectsetid, 'groupnm':groupnm, 'nick': groupnm};
115
 
    response = ajax_call(null, serviceapp, 'create_group', args, 'POST');
116
 
    if (response.status == 200)
117
 
    {
118
 
        /* pass */
119
 
    }
120
 
    else
121
 
    {
122
 
        alert("Error: Could not add group. Does it already exist?");
123
 
    }
124
 
    /* Reload the display */
125
 
    manage_subject();
126
 
}
127
 
 
128
 
function manage_group(offeringid, groupid, namespace)
129
 
{
130
 
    var elem = document.getElementById(namespace);
131
 
    var button = document.getElementById(namespace+"_button");
132
 
    var manage_div = document.createElement("div")
133
 
    manage_div.id = namespace + "_contents";
134
 
    elem.insertBefore(manage_div, button);
135
 
    
136
 
    /* Refresh contents */
137
 
    list_projectgroup_contents(offeringid, groupid, manage_div.id);
138
 
 
139
 
    /* Remove the button element */
140
 
    elem.removeChild(button);
141
 
}
142
 
 
143
 
/* Lists the information about a particular project group identified by groupid 
144
 
 * in an offering identified by offeringid in the element with id elemnm. May 
145
 
 * be called multiple times safely to refresh the displayed information.
146
 
 */
147
 
function list_projectgroup_contents(offeringid, groupid, elemnm)
148
 
{
149
 
    var contents = document.getElementById(elemnm);
150
 
    dom_removechildren(contents);
151
 
    var callback = function(xhr)
152
 
    {
153
 
        var members = JSON.parse(xhr.responseText);
154
 
        var available = members.available;
155
 
        var groupmembers = members.groupmembers;
156
 
        
157
 
        /* Existing members */
158
 
        var ul = document.createElement("ul");
159
 
        for (var i=0; i<groupmembers.length; i++)
160
 
        {
161
 
            var li = dom_make_text_elem("li", groupmembers[i].fullname + " (" +
162
 
                                              groupmembers[i].login + ")");
163
 
            ul.appendChild(li);
164
 
        }
165
 
 
166
 
        /* Add member box */
167
 
        var add_li = document.createElement("li");
168
 
        var select = document.createElement("select");
169
 
        for (var i=0; i<available.length; i++)
170
 
        {
171
 
            var option = dom_make_text_elem("option", available[i].login);
172
 
            option.value = available[i].login;
173
 
            select.appendChild(option);
174
 
        }
175
 
        var button = document.createElement("input");
176
 
        button.value = "Add";
177
 
        button.type = 'button';
178
 
        button.addEventListener("click", function()
179
 
        {
180
 
            args = {'login': select.value, 'groupid': groupid};
181
 
            ajax_call(null, serviceapp, 'assign_group', args, 'POST');
182
 
            list_projectgroup_contents(offeringid, groupid, elemnm);
183
 
        }, false);
184
 
        add_li.appendChild(select);
185
 
        add_li.appendChild(button);
186
 
        ul.appendChild(add_li);
187
 
        contents.appendChild(ul);
188
 
    }
189
 
    var args = {'offeringid': offeringid, 'groupid': groupid};
190
 
    ajax_call(callback, serviceapp, 'get_group_membership', args, 'GET');
191
 
 
192
 
}