23
23
serviceapp = 'userservice';
25
function create(offeringid)
27
/* TODO: Write this function */
30
/* Displays the selected group in the group adminsitration area
32
function manage_subject()
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);
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)
45
var offerings = JSON.parse(xhr.responseText);
46
for (var i=0; i<offerings.length; i++)
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);
57
ajax_call(callback, serviceapp, 'get_active_offerings', {'subjectid': subjectid}, 'GET');
60
/* Manages the display of a single offerings groups
61
* Takes a offeringid and element to attach the results to
63
function manage_subject_offering(offeringid, elem)
65
var callback = function(xhr)
67
var projectsets = JSON.parse(xhr.responseText);
68
var dl = document.createElement("dl");
70
/* Add details for each project set */
71
for (var i=0; i<projectsets.length; i++)
73
var projectset = projectsets[i];
74
var groups = projectset.groups;
76
var dt = dom_make_text_elem("dt", "Project Set "+(i+1)+" ");
78
var dd = document.createElement("dd");
79
var ul = document.createElement("ul");
81
/* Add each group in the project set */
82
for (var j=0; j<groups.length; j++)
84
var group = groups[j];
85
var namespace = "project_group_" + group.groupid;
86
var li = dom_make_text_elem("li", group['groupnm']+" ");
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);
97
var li = dom_make_text_elem("li", "");
98
var input = document.createElement("input");
100
input.type = 'button';
101
input.setAttribute("onclick", "create_new_group("+projectset['projectsetid']+")");
102
li.appendChild(input);
107
ajax_call(callback, serviceapp, 'get_project_groups', {'offeringid': offeringid}, 'GET');
110
25
/* Creates a group */
111
26
function create_new_group(projectsetid)
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)
122
alert("Error: Could not add group. Does it already exist?");
124
/* Reload the display */
28
groupnm = window.prompt('Please enter a name for the group','');
30
/* If the provided name is empty, or the prompt is cancelled, stop. */
34
'projectsetid': projectsetid,
38
response = ajax_call(null, serviceapp, 'create_group', args, 'POST');
39
if (response.status == 200)
43
else if (response.status == 400)
45
alert("Could not create group: " + response.getResponseHeader('X-IVLE-Error'));
49
alert("Error: Could not add group. Does it already exist?");
51
/* Reload the display */
52
window.location.href = window.location.href;
128
56
function manage_group(offeringid, groupid, namespace)
130
var elem = document.getElementById(namespace);
131
58
var button = document.getElementById(namespace+"_button");
132
59
var manage_div = document.createElement("div")
133
60
manage_div.id = namespace + "_contents";
134
elem.insertBefore(manage_div, button);
62
/* Get the td which is button's parent (the 'actions' column) */
63
button_td = button.parentNode;
64
button_td.appendChild(manage_div);
136
66
/* Refresh contents */
137
67
list_projectgroup_contents(offeringid, groupid, manage_div.id);
139
69
/* Remove the button element */
140
elem.removeChild(button);
70
button_td.removeChild(button);
143
73
/* Lists the information about a particular project group identified by groupid
158
88
var ul = document.createElement("ul");
159
89
for (var i=0; i<groupmembers.length; i++)
161
var li = dom_make_text_elem("li", groupmembers[i].fullname + " (" +
162
groupmembers[i].login + ")");
91
var member = groupmembers[i];
93
var li = dom_make_text_elem("li", member.fullname + " (" +
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! */
99
rmbutton.src = "/+media/ivle.webapp.core/images/interface/delete.png";
101
$(rmbutton).click(function(offeringid, login, groupid, elemnm)
104
if (!confirm("Are you sure want to revoke this user's membership?"))
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);
111
}(offeringid, member.login, groupid, elemnm));
113
li.appendChild(rmbutton);
163
114
ul.appendChild(li);