[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /** 17 * Client-side JavaScript for group management interface. 18 * @copyright vy-shane AT moodle.com 19 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 20 * @package core_group 21 */ 22 23 24 /** 25 * Class UpdatableGroupsCombo 26 */ 27 function UpdatableGroupsCombo(wwwRoot, courseId) { 28 this.wwwRoot = wwwRoot; 29 this.courseId = courseId; 30 31 this.connectCallback = { 32 33 success: function(o) { 34 if (o.responseText !== undefined) { 35 var groupsComboEl = document.getElementById("groups"); 36 var membersComboEl = document.getElementById("members"); 37 if (membersComboEl) { 38 // Clear the members list box. 39 while (membersComboEl.firstChild) { 40 membersComboEl.removeChild(membersComboEl.firstChild); 41 } 42 } 43 44 if (groupsComboEl && o.responseText) { 45 var groups = eval("("+o.responseText+")"); 46 47 // Populate the groups list box. 48 for (var i=0; i<groups.length; i++) { 49 var optionEl = document.createElement("option"); 50 optionEl.setAttribute("value", groups[i].id); 51 optionEl.title = groups[i].name; 52 optionEl.innerHTML = groups[i].name; 53 groupsComboEl.appendChild(optionEl); 54 } 55 } 56 } 57 // Remove the loader gif image. 58 removeLoaderImgs("groupsloader", "groupslabel"); 59 }, 60 61 failure: function(o) { 62 removeLoaderImgs("membersloader", "memberslabel"); 63 this.currentTransId = null; 64 } 65 66 }; 67 } 68 69 70 /** 71 * Class UpdatableMembersCombo 72 */ 73 function UpdatableMembersCombo(wwwRoot, courseId) { 74 this.wwwRoot = wwwRoot; 75 this.courseId = courseId; 76 77 this.connectCallback = { 78 success: function(t, o) { 79 80 if (o.responseText !== undefined) { 81 var selectEl = document.getElementById("members"); 82 if (selectEl && o.responseText) { 83 var roles = eval("("+o.responseText+")"); 84 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); 95 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 }, 110 111 failure: function() { 112 removeLoaderImgs("membersloader", "memberslabel"); 113 } 114 115 }; 116 117 // Hide the updatemembers input since AJAX will take care of this. 118 var updatemembers = Y.one('#updatemembers'); 119 if (updatemembers) { 120 updatemembers.hide(); 121 } 122 } 123 124 /** 125 * When a group is selected, we need to update the members. 126 * The Add/Remove Users button also needs to be disabled/enabled 127 * depending on whether or not a group is selected 128 */ 129 UpdatableMembersCombo.prototype.refreshMembers = function () { 130 131 // Get group selector and check selection type 132 var selectEl = document.getElementById("groups"); 133 var selectionCount=0,groupId=0; 134 if( selectEl ) { 135 for (var i = 0; i < selectEl.options.length; i++) { 136 if(selectEl.options[i].selected) { 137 selectionCount++; 138 if(!groupId) { 139 groupId=selectEl.options[i].value; 140 } 141 } 142 } 143 } 144 var singleSelection=selectionCount == 1; 145 146 // Add the loader gif image (we only load for single selections) 147 if(singleSelection) { 148 createLoaderImg("membersloader", "memberslabel", this.wwwRoot); 149 } 150 151 // Update the label. 152 var spanEl = document.getElementById("thegroup"); 153 if (singleSelection) { 154 spanEl.innerHTML = selectEl.options[selectEl.selectedIndex].title; 155 } else { 156 spanEl.innerHTML = ' '; 157 } 158 159 // Clear the members list box. 160 selectEl = document.getElementById("members"); 161 if (selectEl) { 162 while (selectEl.firstChild) { 163 selectEl.removeChild(selectEl.firstChild); 164 } 165 } 166 167 document.getElementById("showaddmembersform").disabled = !singleSelection; 168 document.getElementById("showeditgroupsettingsform").disabled = !singleSelection; 169 document.getElementById("deletegroup").disabled = selectionCount == 0; 170 171 if(singleSelection) { 172 var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&group="+groupId+"&act_ajax_getmembersingroup"; 173 var self = this; 174 YUI().use('io', function (Y) { 175 Y.io(sUrl, { 176 method: 'GET', 177 context: this, 178 on: self.connectCallback 179 }); 180 }); 181 } 182 }; 183 184 185 186 var createLoaderImg = function (elClass, parentId, wwwRoot) { 187 var parentEl = document.getElementById(parentId); 188 if (!parentEl) { 189 return false; 190 } 191 if (document.getElementById("loaderImg")) { 192 // A loader image already exists. 193 return false; 194 } 195 var loadingImg = document.createElement("img"); 196 197 loadingImg.setAttribute("src", M.util.image_url('/i/ajaxloader', 'moodle')); 198 loadingImg.setAttribute("class", elClass); 199 loadingImg.setAttribute("alt", "Loading"); 200 loadingImg.setAttribute("id", "loaderImg"); 201 parentEl.appendChild(loadingImg); 202 203 return true; 204 }; 205 206 207 var removeLoaderImgs = function (elClass, parentId) { 208 var parentEl = document.getElementById(parentId); 209 if (parentEl) { 210 var loader = document.getElementById("loaderImg"); 211 if (loader) { 212 parentEl.removeChild(loader); 213 } 214 } 215 }; 216 217 /** 218 * Updates the current groups information shown about a user when a user is selected. 219 * 220 * @global {Array} userSummaries 221 * userSummaries is added to the page via /user/selector/lib.php - group_non_members_selector::print_user_summaries() 222 * as a global that can be used by this function. 223 */ 224 function updateUserSummary() { 225 var selectEl = document.getElementById('addselect'), 226 summaryDiv = document.getElementById('group-usersummary'), 227 length = selectEl.length, 228 selectCnt = 0, 229 selectIdx = -1, 230 i; 231 232 for (i = 0; i < length; i++) { 233 if (selectEl.options[i].selected) { 234 selectCnt++; 235 selectIdx = i; 236 } 237 } 238 239 if (selectCnt == 1 && userSummaries[selectIdx]) { 240 summaryDiv.innerHTML = userSummaries[selectIdx]; 241 } else { 242 summaryDiv.innerHTML = ''; 243 } 244 245 return true; 246 } 247 248 function init_add_remove_members_page(Y) { 249 var add = Y.one('#add'); 250 var addselect = M.core_user.get_user_selector('addselect'); 251 add.set('disabled', addselect.is_selection_empty()); 252 addselect.on('user_selector:selectionchanged', function(isempty) { 253 add.set('disabled', isempty); 254 }); 255 256 var remove = Y.one('#remove'); 257 var removeselect = M.core_user.get_user_selector('removeselect'); 258 remove.set('disabled', removeselect.is_selection_empty()); 259 removeselect.on('user_selector:selectionchanged', function(isempty) { 260 remove.set('disabled', isempty); 261 }); 262 263 addselect = document.getElementById('addselect'); 264 addselect.onchange = updateUserSummary; 265 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |