925
by mattgiuca
Added "groups" app. No code within the app just yet. |
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 |
||
1001
by dcoles
Groups: Added the view half of the group admin panel. This lets people with the |
23 |
serviceapp = 'userservice'; |
24 |
||
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
25 |
/* Creates a group */
|
26 |
function create_new_group(projectsetid) |
|
27 |
{
|
|
1329
by David Coles
All window.prompts now have a default text (fixes appearing as "undefined" in |
28 |
groupnm = window.prompt('Please enter a name for the group',''); |
1335
by William Grant
Abort group creation if the prompt is cancelled or the name is empty. |
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 |
}
|
|
1606.1.4
by William Grant
Display a nice error when trying to add a group with an invalid name. |
43 |
else if (response.status == 400) |
44 |
{
|
|
1606.1.5
by William Grant
Call the field X-IVLE-Error instead (to avoid potential conflicts with icky fileservice), and populate it in the root XHTMLErrorView. |
45 |
alert("Could not create group: " + response.getResponseHeader('X-IVLE-Error')); |
1606.1.4
by William Grant
Display a nice error when trying to add a group with an invalid name. |
46 |
}
|
1335
by William Grant
Abort group creation if the prompt is cancelled or the name is empty. |
47 |
else
|
48 |
{
|
|
49 |
alert("Error: Could not add group. Does it already exist?"); |
|
50 |
}
|
|
51 |
/* Reload the display */
|
|
52 |
window.location.href = window.location.href; |
|
53 |
}
|
|
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
54 |
}
|
55 |
||
56 |
function manage_group(offeringid, groupid, namespace) |
|
57 |
{
|
|
58 |
var button = document.getElementById(namespace+"_button"); |
|
59 |
var manage_div = document.createElement("div") |
|
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
60 |
manage_div.id = namespace + "_contents"; |
1729
by Matt Giuca
groups.js: Fixed JavaScript for managing groups. Previously didn't expand the management panel because the ul changed into a table. Fixes Launchpad bug #527608. |
61 |
|
62 |
/* Get the td which is button's parent (the 'actions' column) */
|
|
63 |
button_td = button.parentNode; |
|
64 |
button_td.appendChild(manage_div); |
|
65 |
||
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
66 |
/* Refresh contents */
|
67 |
list_projectgroup_contents(offeringid, groupid, manage_div.id); |
|
68 |
||
69 |
/* Remove the button element */
|
|
1729
by Matt Giuca
groups.js: Fixed JavaScript for managing groups. Previously didn't expand the management panel because the ul changed into a table. Fixes Launchpad bug #527608. |
70 |
button_td.removeChild(button); |
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
71 |
}
|
72 |
||
73 |
/* Lists the information about a particular project group identified by groupid
|
|
74 |
* in an offering identified by offeringid in the element with id elemnm. May
|
|
75 |
* be called multiple times safely to refresh the displayed information.
|
|
76 |
*/
|
|
77 |
function list_projectgroup_contents(offeringid, groupid, elemnm) |
|
78 |
{
|
|
79 |
var contents = document.getElementById(elemnm); |
|
80 |
dom_removechildren(contents); |
|
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
81 |
var callback = function(xhr) |
82 |
{
|
|
83 |
var members = JSON.parse(xhr.responseText); |
|
84 |
var available = members.available; |
|
85 |
var groupmembers = members.groupmembers; |
|
86 |
||
1009
by wagrant
groups: Pretty up the admin interface somewhat. |
87 |
/* Existing members */
|
88 |
var ul = document.createElement("ul"); |
|
89 |
for (var i=0; i<groupmembers.length; i++) |
|
90 |
{
|
|
1181
by William Grant
Allow revocation of group memberships by tutors and lecturers. |
91 |
var member = groupmembers[i]; |
92 |
||
93 |
var li = dom_make_text_elem("li", member.fullname + " (" + |
|
1730
by Matt Giuca
ProjectSet view: Prettied up the group management interface, including fixing delete icons. |
94 |
member.login + ") "); |
1181
by William Grant
Allow revocation of group memberships by tutors and lecturers. |
95 |
var rmbutton = document.createElement("input"); |
96 |
rmbutton.value = "Remove"; |
|
97 |
rmbutton.type = "image"; |
|
98 |
/* XXX: There must be a better way to do this! */
|
|
1730
by Matt Giuca
ProjectSet view: Prettied up the group management interface, including fixing delete icons. |
99 |
rmbutton.src = "/+media/ivle.webapp.core/images/interface/delete.png"; |
1181
by William Grant
Allow revocation of group memberships by tutors and lecturers. |
100 |
|
101 |
$(rmbutton).click(function(offeringid, login, groupid, elemnm) |
|
102 |
{
|
|
103 |
return function() { |
|
104 |
if (!confirm("Are you sure want to revoke this user's membership?")) |
|
105 |
return; |
|
106 |
this.disabled = true; |
|
107 |
var args = {'login': login, 'groupid': groupid}; |
|
108 |
ajax_call(null, serviceapp, 'unassign_group', args, 'POST'); |
|
109 |
list_projectgroup_contents(offeringid, groupid, elemnm); |
|
110 |
};
|
|
111 |
}(offeringid, member.login, groupid, elemnm)); |
|
112 |
||
113 |
li.appendChild(rmbutton); |
|
1009
by wagrant
groups: Pretty up the admin interface somewhat. |
114 |
ul.appendChild(li); |
115 |
}
|
|
116 |
||
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
117 |
/* Add member box */
|
1009
by wagrant
groups: Pretty up the admin interface somewhat. |
118 |
var add_li = document.createElement("li"); |
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
119 |
var select = document.createElement("select"); |
120 |
for (var i=0; i<available.length; i++) |
|
121 |
{
|
|
122 |
var option = dom_make_text_elem("option", available[i].login); |
|
123 |
option.value = available[i].login; |
|
124 |
select.appendChild(option); |
|
125 |
}
|
|
126 |
var button = document.createElement("input"); |
|
1009
by wagrant
groups: Pretty up the admin interface somewhat. |
127 |
button.value = "Add"; |
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
128 |
button.type = 'button'; |
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
129 |
$(button).click(function() |
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
130 |
{
|
1145
by William Grant
Disable the 'Add' button inside groups as soon as it's pressed, to avoid |
131 |
this.disabled = true; |
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
132 |
args = {'login': select.value, 'groupid': groupid}; |
133 |
ajax_call(null, serviceapp, 'assign_group', args, 'POST'); |
|
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
134 |
list_projectgroup_contents(offeringid, groupid, elemnm); |
1166
by William Grant
Replace all non-external addEventListeners with equivalent jQuery calls. |
135 |
});
|
1009
by wagrant
groups: Pretty up the admin interface somewhat. |
136 |
add_li.appendChild(select); |
137 |
add_li.appendChild(button); |
|
138 |
ul.appendChild(add_li); |
|
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
139 |
contents.appendChild(ul); |
1004
by dcoles
Groups: Now you can add people to a group as well as creating groups from the |
140 |
}
|
141 |
var args = {'offeringid': offeringid, 'groupid': groupid}; |
|
142 |
ajax_call(callback, serviceapp, 'get_group_membership', args, 'GET'); |
|
1014
by dcoles
Groups: Small interface bug fix. Will now refresh the group information when |
143 |
|
1001
by dcoles
Groups: Added the view half of the group admin panel. This lets people with the |
144 |
}
|