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

« back to all changes in this revision

Viewing changes to ivle/webapp/groups/media/groups.js

  • Committer: William Grant
  • Date: 2009-02-27 05:07:09 UTC
  • Revision ID: grantw@unimelb.edu.au-20090227050709-k16kvhyl50nzjbwm
Subject URLs now contain the short name (eg. info1) rather than the code
(eg. 600151).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
serviceapp = 'userservice';
24
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
 
25
110
/* Creates a group */
26
111
function create_new_group(projectsetid)
27
112
{
28
 
    groupnm = window.prompt('Please enter a name for the group','');
29
 
 
30
 
    /* If the provided name is empty, or the prompt is cancelled, stop. */
31
 
    if (groupnm)
32
 
    {
33
 
        args = {
34
 
            'projectsetid': projectsetid,
35
 
            'groupnm':groupnm,
36
 
            'nick': groupnm
37
 
        };
38
 
        response = ajax_call(null, serviceapp, 'create_group', args, 'POST');
39
 
        if (response.status == 200)
40
 
        {
41
 
            /* pass */
42
 
        }
43
 
        else
44
 
        {
45
 
            alert("Error: Could not add group. Does it already exist?");
46
 
        }
47
 
        /* Reload the display */
48
 
        window.location.href = window.location.href;
49
 
    }
 
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
    window.location.href = window.location.href;
50
126
}
51
127
 
52
128
function manage_group(offeringid, groupid, namespace)
82
158
        var ul = document.createElement("ul");
83
159
        for (var i=0; i<groupmembers.length; i++)
84
160
        {
85
 
            var member = groupmembers[i];
86
 
 
87
 
            var li = dom_make_text_elem("li", member.fullname + " (" +
88
 
                                              member.login + ")");
89
 
            var rmbutton = document.createElement("input");
90
 
            rmbutton.value = "Remove";
91
 
            rmbutton.type = "image";
92
 
            /* XXX: There must be a better way to do this! */
93
 
            rmbutton.src = "/+media/ivle.webapp.groups/cross.png";
94
 
 
95
 
            $(rmbutton).click(function(offeringid, login, groupid, elemnm)
96
 
            {
97
 
                return function() {
98
 
                    if (!confirm("Are you sure want to revoke this user's membership?"))
99
 
                        return;
100
 
                    this.disabled = true;
101
 
                    var args = {'login': login, 'groupid': groupid};
102
 
                    ajax_call(null, serviceapp, 'unassign_group', args, 'POST');
103
 
                    list_projectgroup_contents(offeringid, groupid, elemnm);
104
 
                };
105
 
            }(offeringid, member.login, groupid, elemnm));
106
 
 
107
 
            li.appendChild(rmbutton);
 
161
            var li = dom_make_text_elem("li", groupmembers[i].fullname + " (" +
 
162
                                              groupmembers[i].login + ")");
108
163
            ul.appendChild(li);
109
164
        }
110
165
 
120
175
        var button = document.createElement("input");
121
176
        button.value = "Add";
122
177
        button.type = 'button';
123
 
        $(button).click(function()
 
178
        button.addEventListener("click", function()
124
179
        {
125
 
            this.disabled = true;
126
180
            args = {'login': select.value, 'groupid': groupid};
127
181
            ajax_call(null, serviceapp, 'assign_group', args, 'POST');
128
182
            list_projectgroup_contents(offeringid, groupid, elemnm);
129
 
        });
 
183
        }, false);
130
184
        add_li.appendChild(select);
131
185
        add_li.appendChild(button);
132
186
        ul.appendChild(add_li);