file check_defaults.class.php was added on branch MOODLE_19_STABLE on 2008-05-15...
[moodle-linuxchix.git] / group / clientlib.js
blob6f74d1cf8023229c96e786d81f67d261c96a872a
1 /**
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
5  * @package groups
6  */
9 /**
10  * Class UpdatableGroupsCombo
11  */
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");
23                 if (membersComboEl) {
24                     // Clear the members list box.
25                     while (membersComboEl.firstChild) {
26                         membersComboEl.removeChild(membersComboEl.firstChild);
27                     }
28                 }
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);
40                     }
41                 }
42                 }
43                 // Remove the loader gif image.
44                 removeLoaderImgs("groupsloader", "groupslabel");
45         },
47         failure: function(o) {
48             removeLoaderImgs("membersloader", "memberslabel");
49             this.currentTransId = null;
50         }
52     };
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.
58     /*
59     groupsComboEl = document.getElementById("groups");
60     if (groupsComboEl) {
61         groupsComboEl.setAttribute("onchange", "membersCombo.refreshMembers(this.options[this.selectedIndex].value);");
62     }
63     */
65     // Hide the updategroups input since AJAX will take care of this.
66     YAHOO.util.Dom.setStyle("updategroups", "display", "none");
70 /**
71  * Class UpdatableMembersCombo
72  */
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.
86                     if (selectEl) {
87                         while (selectEl.firstChild) {
88                             selectEl.removeChild(selectEl.firstChild);
89                         }
90                     }
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);
102                         }
103                         selectEl.appendChild(optgroupEl);
104                     }
105                 }
106                 }
107                 // Remove the loader gif image.
108                 removeLoaderImgs("membersloader", "memberslabel");
109         },
111         failure: function(o) {
112             removeLoaderImgs("membersloader", "memberslabel");
113         }
115     };
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
125  */
126 UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
127     // Add the loader gif image.
128     createLoaderImg("membersloader", "memberslabel", this.wwwRoot);
130     // Update the label.
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;
135     }
137     // Clear the members list box.
138     selectEl = document.getElementById("members");
139     if (selectEl) {
140         while (selectEl.firstChild) {
141             selectEl.removeChild(selectEl.firstChild);
142         }
143     }
144     
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);
156     if (!parentEl) {
157         return false;
158     }
159     if (document.getElementById("loaderImg")) {
160         // A loader image already exists.
161         return false;
162     }
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);
171     return true;
175 var removeLoaderImgs = function (elClass, parentId) {
176     var parentEl = document.getElementById(parentId);
177     if (parentEl) {
178         var loader = document.getElementById("loaderImg");
179         parentEl.removeChild(loader);
180     }