~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-07-31 04:26:02 UTC
  • mfrom: (1281.1.9 aufsless)
  • Revision ID: me@williamgrant.id.au-20090731042602-51tp90sv3icl7iqv
Jails no longer use aufs, but bind mounts. Both parts of the jails must be rebuilt.

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
    args = {'projectsetid': projectsetid, 'groupnm':groupnm, 'nick': groupnm};
 
30
    response = ajax_call(null, serviceapp, 'create_group', args, 'POST');
 
31
    if (response.status == 200)
 
32
    {
 
33
        /* pass */
 
34
    }
 
35
    else
 
36
    {
 
37
        alert("Error: Could not add group. Does it already exist?");
 
38
    }
 
39
    /* Reload the display */
 
40
    window.location.href = window.location.href;
 
41
}
 
42
 
 
43
function manage_group(offeringid, groupid, namespace)
 
44
{
 
45
    var elem = document.getElementById(namespace);
 
46
    var button = document.getElementById(namespace+"_button");
 
47
    var manage_div = document.createElement("div")
 
48
    manage_div.id = namespace + "_contents";
 
49
    elem.insertBefore(manage_div, button);
 
50
    
 
51
    /* Refresh contents */
 
52
    list_projectgroup_contents(offeringid, groupid, manage_div.id);
 
53
 
 
54
    /* Remove the button element */
 
55
    elem.removeChild(button);
 
56
}
 
57
 
 
58
/* Lists the information about a particular project group identified by groupid 
 
59
 * in an offering identified by offeringid in the element with id elemnm. May 
 
60
 * be called multiple times safely to refresh the displayed information.
 
61
 */
 
62
function list_projectgroup_contents(offeringid, groupid, elemnm)
 
63
{
 
64
    var contents = document.getElementById(elemnm);
 
65
    dom_removechildren(contents);
 
66
    var callback = function(xhr)
 
67
    {
 
68
        var members = JSON.parse(xhr.responseText);
 
69
        var available = members.available;
 
70
        var groupmembers = members.groupmembers;
 
71
        
 
72
        /* Existing members */
 
73
        var ul = document.createElement("ul");
 
74
        for (var i=0; i<groupmembers.length; i++)
 
75
        {
 
76
            var member = groupmembers[i];
 
77
 
 
78
            var li = dom_make_text_elem("li", member.fullname + " (" +
 
79
                                              member.login + ")");
 
80
            var rmbutton = document.createElement("input");
 
81
            rmbutton.value = "Remove";
 
82
            rmbutton.type = "image";
 
83
            /* XXX: There must be a better way to do this! */
 
84
            rmbutton.src = "/+media/ivle.webapp.groups/cross.png";
 
85
 
 
86
            $(rmbutton).click(function(offeringid, login, groupid, elemnm)
 
87
            {
 
88
                return function() {
 
89
                    if (!confirm("Are you sure want to revoke this user's membership?"))
 
90
                        return;
 
91
                    this.disabled = true;
 
92
                    var args = {'login': login, 'groupid': groupid};
 
93
                    ajax_call(null, serviceapp, 'unassign_group', args, 'POST');
 
94
                    list_projectgroup_contents(offeringid, groupid, elemnm);
 
95
                };
 
96
            }(offeringid, member.login, groupid, elemnm));
 
97
 
 
98
            li.appendChild(rmbutton);
 
99
            ul.appendChild(li);
 
100
        }
 
101
 
 
102
        /* Add member box */
 
103
        var add_li = document.createElement("li");
 
104
        var select = document.createElement("select");
 
105
        for (var i=0; i<available.length; i++)
 
106
        {
 
107
            var option = dom_make_text_elem("option", available[i].login);
 
108
            option.value = available[i].login;
 
109
            select.appendChild(option);
 
110
        }
 
111
        var button = document.createElement("input");
 
112
        button.value = "Add";
 
113
        button.type = 'button';
 
114
        $(button).click(function()
 
115
        {
 
116
            this.disabled = true;
 
117
            args = {'login': select.value, 'groupid': groupid};
 
118
            ajax_call(null, serviceapp, 'assign_group', args, 'POST');
 
119
            list_projectgroup_contents(offeringid, groupid, elemnm);
 
120
        });
 
121
        add_li.appendChild(select);
 
122
        add_li.appendChild(button);
 
123
        ul.appendChild(add_li);
 
124
        contents.appendChild(ul);
 
125
    }
 
126
    var args = {'offeringid': offeringid, 'groupid': groupid};
 
127
    ajax_call(callback, serviceapp, 'get_group_membership', args, 'GET');
 
128
 
 
129
}