Merge branch 'master_MDL-51401' of https://github.com/janeklb/moodle

This commit is contained in:
David Monllao 2016-10-11 17:58:05 +08:00
commit 85d7a13ab0
5 changed files with 38 additions and 11 deletions

View file

@ -88,7 +88,7 @@ switch ($action) {
break; break;
case 'getassignable': case 'getassignable':
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL); $otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
$outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true); $outcome->response = $manager->get_assignable_roles_for_json($otheruserroles);
break; break;
case 'searchotherusers': case 'searchotherusers':
$search = optional_param('search', '', PARAM_RAW); $search = optional_param('search', '', PARAM_RAW);

View file

@ -621,6 +621,22 @@ class course_enrolment_manager {
} }
} }
/**
* Gets all of the assignable roles for this course, wrapped in an array to ensure
* role sort order is not lost during json deserialisation.
*
* @param boolean $otherusers whether to include the assignable roles for other users
* @return array
*/
public function get_assignable_roles_for_json($otherusers = false) {
$rolesarray = array();
$assignable = $this->get_assignable_roles($otherusers);
foreach ($assignable as $id => $role) {
$rolesarray[] = array('id' => $id, 'name' => $role);
}
return $rolesarray;
}
/** /**
* Gets all of the groups for this course. * Gets all of the groups for this course.
* *

View file

@ -198,8 +198,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
var index = 0, count = 0; var index = 0, count = 0;
for (var i in roles) { for (var i in roles) {
count++; count++;
var option = create('<option value="'+i+'">'+roles[i]+'</option>'); var option = create('<option value="' + roles[i].id + '">' + roles[i].name + '</option>');
if (i == v) { if (roles[i].id == v) {
index = count; index = count;
} }
s.append(option); s.append(option);

View file

@ -314,10 +314,10 @@ YUI.add('moodle-enrol-otherusersmanager', function(Y) {
) )
.append(Y.Node.create('<div class="'+CSS.OPTIONS+'"><span class="label">'+M.util.get_string('assignrole', 'role')+': </span></div>')) .append(Y.Node.create('<div class="'+CSS.OPTIONS+'"><span class="label">'+M.util.get_string('assignrole', 'role')+': </span></div>'))
); );
var id = 0, roles = this._manager.get(ASSIGNABLEROLES); var roles = this._manager.get(ASSIGNABLEROLES);
for (id in roles) { for (var i in roles) {
var role = Y.Node.create('<a href="#" class="'+CSS.ROLEOPTION+'">'+roles[id]+'</a>'); var role = Y.Node.create('<a href="#" class="' + CSS.ROLEOPTION + '">' + roles[i].name + '</a>');
role.on('click', this.assignRoleToUser, this, id, role); role.on('click', this.assignRoleToUser, this, roles[i].id, role);
this._node.one('.'+CSS.OPTIONS).append(role); this._node.one('.'+CSS.OPTIONS).append(role);
} }
return this._node; return this._node;

View file

@ -94,7 +94,7 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
if (o.error) { if (o.error) {
new M.core.ajaxException(o); new M.core.ajaxException(o);
} else { } else {
this.users[userid].addRoleToDisplay(args.roleid, this.get(ASSIGNABLEROLES)[args.roleid]); this.users[userid].addRoleToDisplay(args.roleid, this._getAssignableRole(args.roleid));
} }
} catch (e) { } catch (e) {
new M.core.exception(e); new M.core.exception(e);
@ -152,6 +152,15 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
} }
}); });
}, },
_getAssignableRole: function(roleid) {
var roles = this.get(ASSIGNABLEROLES);
for (var i in roles) {
if (roles[i].id == roleid) {
return roles[i].name;
}
}
return null;
},
_loadAssignableRoles : function() { _loadAssignableRoles : function() {
var c = this.get(COURSEID), params = { var c = this.get(COURSEID), params = {
id : this.get(COURSEID), id : this.get(COURSEID),
@ -277,7 +286,7 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
var current = this.get(CURRENTROLES); var current = this.get(CURRENTROLES);
var allroles = true, i = 0; var allroles = true, i = 0;
for (i in roles) { for (i in roles) {
if (!current[i]) { if (!current[roles[i].id]) {
allroles = false; allroles = false;
break; break;
} }
@ -353,8 +362,10 @@ YUI.add('moodle-enrol-rolemanager', function(Y) {
var content = element.one('.content'); var content = element.one('.content');
var roles = m.get(ASSIGNABLEROLES); var roles = m.get(ASSIGNABLEROLES);
for (i in roles) { for (i in roles) {
var button = Y.Node.create('<input type="button" value="'+roles[i]+'" id="add_assignable_role_'+i+'" />'); var buttonid = 'add_assignable_role_' + roles[i].id;
button.on('click', this.submit, this, i); var buttonhtml = '<input type="button" value="' + roles[i].name + '" id="' + buttonid + '" />';
var button = Y.Node.create(buttonhtml);
button.on('click', this.submit, this, roles[i].id);
content.append(button); content.append(button);
} }
Y.one(document.body).append(element); Y.one(document.body).append(element);