2 * Client-side JavaScript for group management interface.
3 * @author vy-shane AT moodle.com
4 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * Class UpdatableGroupsCombo
12 function UpdatableGroupsCombo(wwwRoot, courseId) {
13 this.wwwRoot = wwwRoot;
14 this.courseId = courseId;
16 this.connectCallback = {
18 success: function(o) {
19 if (o.responseText !== undefined) {
20 var groupsComboEl = document.getElementById("groups");
21 var membersComboEl = document.getElementById("members");
24 // Clear the members list box.
25 while (membersComboEl.firstChild) {
26 membersComboEl.removeChild(membersComboEl.firstChild);
30 if (groupsComboEl && o.responseText) {
31 var groups = eval("("+o.responseText+")");
33 // Populate the groups list box.
34 for (var i=0; i<groups.length; i++) {
35 var optionEl = document.createElement("option");
36 optionEl.setAttribute("value", groups[i].id);
37 optionEl.title = groups[i].name;
38 optionEl.innerHTML = groups[i].name;
39 groupsComboEl.appendChild(optionEl);
43 // Remove the loader gif image.
44 removeLoaderImgs("groupsloader", "groupslabel");
47 failure: function(o) {
48 removeLoaderImgs("membersloader", "memberslabel");
49 this.currentTransId = null;
54 // Add onchange event to groups list box.
55 // Okay, this is not working in IE. The onchange is never fired...
56 // I'm hard coding the onchange in ../index.php. Not ideal, but it works
57 // then. vyshane AT moodle DOT com.
59 groupsComboEl = document.getElementById("groups");
61 groupsComboEl.setAttribute("onchange", "membersCombo.refreshMembers(this.options[this.selectedIndex].value);");
65 // Hide the updategroups input since AJAX will take care of this.
66 YAHOO.util.Dom.setStyle("updategroups", "display", "none");
71 * Class UpdatableMembersCombo
73 function UpdatableMembersCombo(wwwRoot, courseId) {
74 this.wwwRoot = wwwRoot;
75 this.courseId = courseId;
77 this.connectCallback = {
78 success: function(o) {
80 if (o.responseText !== undefined) {
81 var selectEl = document.getElementById("members");
82 if (selectEl && o.responseText) {
83 var roles = eval("("+o.responseText+")");
85 // Clear the members list box.
87 while (selectEl.firstChild) {
88 selectEl.removeChild(selectEl.firstChild);
91 // Populate the members list box.
92 for (var i=0; i<roles.length; i++) {
93 var optgroupEl = document.createElement("optgroup");
94 optgroupEl.setAttribute("label",roles[i].name);
96 for(var j=0; j<roles[i].users.length; j++) {
97 var optionEl = document.createElement("option");
98 optionEl.setAttribute("value", roles[i].users[j].id);
99 optionEl.title = roles[i].users[j].name;
100 optionEl.innerHTML = roles[i].users[j].name;
101 optgroupEl.appendChild(optionEl);
103 selectEl.appendChild(optgroupEl);
107 // Remove the loader gif image.
108 removeLoaderImgs("membersloader", "memberslabel");
111 failure: function(o) {
112 removeLoaderImgs("membersloader", "memberslabel");
117 // Hide the updatemembers input since AJAX will take care of this.
118 YAHOO.util.Dom.setStyle("updatemembers", "display", "none");
122 * When a group is selected, we need to update the members.
123 * The Add/Remove Users button also needs to be disabled/enabled
124 * depending on whether or not a group is selected
126 UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
127 // Add the loader gif image.
128 createLoaderImg("membersloader", "memberslabel", this.wwwRoot);
131 var selectEl = document.getElementById("groups");
132 var spanEl = document.getElementById("thegroup");
133 if (selectEl && selectEl.selectedIndex >= 0) {
134 spanEl.innerHTML = selectEl.options[selectEl.selectedIndex].title;
137 // Clear the members list box.
138 selectEl = document.getElementById("members");
140 while (selectEl.firstChild) {
141 selectEl.removeChild(selectEl.firstChild);
145 document.getElementById("showaddmembersform").disabled = false;
146 document.getElementById("showeditgroupsettingsform").disabled = false;
147 document.getElementById("deletegroup").disabled = false;
148 var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&group="+groupId+"&act_ajax_getmembersingroup";
149 YAHOO.util.Connect.asyncRequest("GET", sUrl, this.connectCallback, null);
154 var createLoaderImg = function (elClass, parentId, wwwRoot) {
155 var parentEl = document.getElementById(parentId);
159 if (document.getElementById("loaderImg")) {
160 // A loader image already exists.
163 var loadingImg = document.createElement("img");
165 loadingImg.setAttribute("src", wwwRoot+"/pix/i/ajaxloader.gif");
166 loadingImg.setAttribute("class", elClass);
167 loadingImg.setAttribute("alt", "Loading");
168 loadingImg.setAttribute("id", "loaderImg");
169 parentEl.appendChild(loadingImg);
175 var removeLoaderImgs = function (elClass, parentId) {
176 var parentEl = document.getElementById(parentId);
178 var loader = document.getElementById("loaderImg");
179 parentEl.removeChild(loader);