Merge branch 'MDL-74815-400' of https://github.com/junpataleta/moodle into MOODLE_400...
[moodle.git] / group / module.js
blob83ce416e0382bd3537a9184adaa20c08e2e67359
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 M.core_group = {
6     hoveroverlay : null
7 };
9 M.core_group.init_index = function(Y, wwwroot, courseid) {
10     M.core_group.groupsCombo = new UpdatableGroupsCombo(wwwroot, courseid);
11     M.core_group.membersCombo = new UpdatableMembersCombo(wwwroot, courseid);
14 M.core_group.groupslist = function(Y, preventgroupremoval) {
15     var actions = {
16         init : function() {
17             // We need to add check_deletable both on change for the groups, and then call it the first time the page loads
18             Y.one('#groups').on('change', this.check_deletable, this);
19             this.check_deletable();
20         },
21         check_deletable : function() {
22             // Ensure that if the 'preventremoval' attribute is set, the delete button is greyed out
23             var candelete = true;
24             var optionselected = false;
25             Y.one('#groups').get('options').each(function(option) {
26                 if (option.get('selected')) {
27                     optionselected = true;
28                     if (option.getAttribute('value') in preventgroupremoval) {
29                         candelete = false;
30                     }
31                 }
32             }, this);
33             var deletebutton = Y.one('#deletegroup');
34             if (candelete && optionselected) {
35                 deletebutton.removeAttribute('disabled');
36             } else {
37                 deletebutton.setAttribute('disabled', 'disabled');
38             }
39         }
40     }
41     actions.init();