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 combo 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 combo 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 combo 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 members = eval("("+o.responseText+")");
85 // Clear the members combo box.
87 while (selectEl.firstChild) {
88 selectEl.removeChild(selectEl.firstChild);
91 // Populate the members combo box.
92 for (var i=0; i<members.length; i++) {
93 var optionEl = document.createElement("option");
94 optionEl.setAttribute("value", members[i].id);
95 optionEl.title = members[i].name;
96 optionEl.innerHTML = members[i].name;
97 selectEl.appendChild(optionEl);
101 // Remove the loader gif image.
102 removeLoaderImgs("membersloader", "memberslabel");
105 failure: function(o) {
106 removeLoaderImgs("membersloader", "memberslabel");
111 // Hide the updatemembers input since AJAX will take care of this.
112 YAHOO.util.Dom.setStyle("updatemembers", "display", "none");
116 * When a group is selected, we need to update the members.
117 * The Add/Remove Users button also needs to be disabled/enabled
118 * depending on whether or not a group is selected
120 UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
121 // Add the loader gif image.
122 createLoaderImg("membersloader", "memberslabel", this.wwwRoot);
125 var selectEl = document.getElementById("groups");
126 var spanEl = document.getElementById("thegroup");
127 if (selectEl && selectEl.selectedIndex >= 0) {
128 spanEl.innerHTML = selectEl.options[selectEl.selectedIndex].title;
131 // Clear the members combo box.
132 selectEl = document.getElementById("members");
134 while (selectEl.firstChild) {
135 selectEl.removeChild(selectEl.firstChild);
139 document.getElementById("showaddmembersform").disabled = false;
140 document.getElementById("showeditgroupsettingsform").disabled = false;
141 document.getElementById("deletegroup").disabled = false;
142 var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&group="+groupId+"&act_ajax_getmembersingroup";
143 YAHOO.util.Connect.asyncRequest("GET", sUrl, this.connectCallback, null);
148 var createLoaderImg = function (elClass, parentId, wwwRoot) {
149 var parentEl = document.getElementById(parentId);
153 if (document.getElementById("loaderImg")) {
154 // A loader image already exists.
157 var loadingImg = document.createElement("img");
159 loadingImg.setAttribute("src", wwwRoot+"/pix/i/ajaxloader.gif");
160 loadingImg.setAttribute("class", elClass);
161 loadingImg.setAttribute("alt", "Loading");
162 loadingImg.setAttribute("id", "loaderImg");
163 parentEl.appendChild(loadingImg);
169 var removeLoaderImgs = function (elClass, parentId) {
170 var parentEl = document.getElementById(parentId);
172 var loader = document.getElementById("loaderImg");
173 parentEl.removeChild(loader);