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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-12-08 02:17:54 UTC
  • Revision ID: matt.giuca@gmail.com-20091208021754-xpjmt72v8ud93q9y
Added sample data infrastructure, with a little bit of sample data. The sample data is in examples/db/sample.sql. Documentation in doc/man/sample.rst details the infrastructure for importing and exporting sample data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Date: 21/7/2008
21
21
 */
22
22
 
 
23
serviceapp = 'userservice';
 
24
 
 
25
/* Creates a group */
 
26
function create_new_group(projectsetid)
 
27
{
 
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
    }
 
50
}
 
51
 
 
52
function manage_group(offeringid, groupid, namespace)
 
53
{
 
54
    var elem = document.getElementById(namespace);
 
55
    var button = document.getElementById(namespace+"_button");
 
56
    var manage_div = document.createElement("div")
 
57
    manage_div.id = namespace + "_contents";
 
58
    elem.insertBefore(manage_div, button);
 
59
    
 
60
    /* Refresh contents */
 
61
    list_projectgroup_contents(offeringid, groupid, manage_div.id);
 
62
 
 
63
    /* Remove the button element */
 
64
    elem.removeChild(button);
 
65
}
 
66
 
 
67
/* Lists the information about a particular project group identified by groupid 
 
68
 * in an offering identified by offeringid in the element with id elemnm. May 
 
69
 * be called multiple times safely to refresh the displayed information.
 
70
 */
 
71
function list_projectgroup_contents(offeringid, groupid, elemnm)
 
72
{
 
73
    var contents = document.getElementById(elemnm);
 
74
    dom_removechildren(contents);
 
75
    var callback = function(xhr)
 
76
    {
 
77
        var members = JSON.parse(xhr.responseText);
 
78
        var available = members.available;
 
79
        var groupmembers = members.groupmembers;
 
80
        
 
81
        /* Existing members */
 
82
        var ul = document.createElement("ul");
 
83
        for (var i=0; i<groupmembers.length; i++)
 
84
        {
 
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);
 
108
            ul.appendChild(li);
 
109
        }
 
110
 
 
111
        /* Add member box */
 
112
        var add_li = document.createElement("li");
 
113
        var select = document.createElement("select");
 
114
        for (var i=0; i<available.length; i++)
 
115
        {
 
116
            var option = dom_make_text_elem("option", available[i].login);
 
117
            option.value = available[i].login;
 
118
            select.appendChild(option);
 
119
        }
 
120
        var button = document.createElement("input");
 
121
        button.value = "Add";
 
122
        button.type = 'button';
 
123
        $(button).click(function()
 
124
        {
 
125
            this.disabled = true;
 
126
            args = {'login': select.value, 'groupid': groupid};
 
127
            ajax_call(null, serviceapp, 'assign_group', args, 'POST');
 
128
            list_projectgroup_contents(offeringid, groupid, elemnm);
 
129
        });
 
130
        add_li.appendChild(select);
 
131
        add_li.appendChild(button);
 
132
        ul.appendChild(add_li);
 
133
        contents.appendChild(ul);
 
134
    }
 
135
    var args = {'offeringid': offeringid, 'groupid': groupid};
 
136
    ajax_call(callback, serviceapp, 'get_group_membership', args, 'GET');
 
137
 
 
138
}