Permalink
Browse files

MDL-37350 Detach listeners when hiding the 'Add roles' popup

If the submit event listener is not correctly closed, then the submit event
calls the relevant callback multiple times incorrectly.

When hiding the Add role dialogue, we need to detach any event listeners
which are applied to it.
  • Loading branch information...
1 parent 9130843 commit f9681cffa4c784b74abed4e352255d0d967058af @andrewnicols andrewnicols committed with andrewnicols Jan 4, 2013
Showing with 11 additions and 5 deletions.
  1. +11 −5 enrol/yui/rolemanager/rolemanager.js
@@ -56,7 +56,6 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
Y.extend(ROLE, Y.Base, {
users : [],
roleAssignmentPanel : null,
- panelsubmitevent : null,
rolesLoadedEvent : null,
escCloseEvent : null,
initializer : function(config) {
@@ -75,14 +74,16 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
this.rolesLoadedEvent = this.on('assignablerolesloaded', function(){
this.rolesLoadedEvent.detach();
var panel = this._getRoleAssignmentPanel();
- this.panelsubmitevent = panel.on('submit', this.addRoleCallback, this);
- panel.hide().display(user);
+ panel.hide();
+ panel.submitevent = panel.on('submit', this.addRoleCallback, this);
+ panel.display(user);
}, this);
this._loadAssignableRoles();
},
addRoleCallback : function(e, roleid, userid) {
- this.panelsubmitevent.detach();
var panel = this._getRoleAssignmentPanel();
+ panel.submitevent.detach();
+ panel.submitevent = null;
Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
method:'POST',
data:'id='+this.get(COURSEID)+'&action=assign&sesskey='+M.cfg.sesskey+'&roleid='+roleid+'&user='+userid,
@@ -350,6 +351,7 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
Y.extend(ROLEPANEL, Y.Base, {
user : null,
roles : [],
+ submitevent : null,
initializer : function() {
var i, m = this.get(MANIPULATOR);
var element = Y.Node.create('<div class="enrolpanel roleassign"><div class="container"><div class="header"><h2>'+M.str.role.assignroles+'</h2><div class="close"></div></div><div class="content"></div></div></div>');
@@ -398,6 +400,10 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
this.roles = [];
this.user = null;
this.get('elementNode').removeClass('visible');
+ if (this.submitevent) {
+ this.submitevent.detach();
+ this.submitevent = null;
+ }
this.displayed = false;
return this;
},
@@ -416,4 +422,4 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
}
}
-}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-enrol-notification']});
+}, '@VERSION@', {requires:['base','node','io-base','json-parse','test','moodle-enrol-notification']});

0 comments on commit f9681cf

Please sign in to comment.