Moved check for plugin import/export to the start rather than the end
[moodle-linuxchix.git] / group / clientlib.js
blob5a5528e51de52319776c9ac795f005c433b12e31
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 combo 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 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);
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 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.
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 members = eval("("+o.responseText+")");
85                     // Clear the members combo box.
86                     if (selectEl) {
87                         while (selectEl.firstChild) {
88                             selectEl.removeChild(selectEl.firstChild);
89                         }
90                     }
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);
98                     }
99                 }
100                 }
101                 // Remove the loader gif image.
102                 removeLoaderImgs("membersloader", "memberslabel");
103         },
105         failure: function(o) {
106             removeLoaderImgs("membersloader", "memberslabel");
107         }
109     };
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
119  */
120 UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
121     // Add the loader gif image.
122     createLoaderImg("membersloader", "memberslabel", this.wwwRoot);
124     // Update the label.
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;
129     }
131     // Clear the members combo box.
132     selectEl = document.getElementById("members");
133     if (selectEl) {
134         while (selectEl.firstChild) {
135             selectEl.removeChild(selectEl.firstChild);
136         }
137     }
138     
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);
150     if (!parentEl) {
151         return false;
152     }
153     if (document.getElementById("loaderImg")) {
154         // A loader image already exists.
155         return false;
156     }
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);
165     return true;
169 var removeLoaderImgs = function (elClass, parentId) {
170     var parentEl = document.getElementById(parentId);
171     if (parentEl) {
172         var loader = document.getElementById("loaderImg");
173         parentEl.removeChild(loader);
174     }