Merge pull request #530 from charithag/release-2.0.x

Add select2 controller to select roles to share a group
revert-70aa11f8
Rasika Perera 8 years ago committed by GitHub
commit 9afffc6571

@ -119,10 +119,9 @@
<div id="user-names"> <div id="user-names">
<h4> <h4>
Select user role(s) Select user role(s)
<br><br>
<div style="max-height: 200px; overflow: auto" id="rolesListing">
</div>
</h4> </h4>
<div class="wr-input-control" id="rolesListing">
</div>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -402,3 +401,19 @@
{{js "js/listing.js"}} {{js "js/listing.js"}}
{{/if}} {{/if}}
{{/zone}} {{/zone}}
{{#zone "topCss"}}
<style>
.select2-dropdown {
z-index: 999999999;
}
.wr-input-control {
color: black;
}
.select2-selection__choice {
font-size: medium;
}
</style>
{{/zone}}

@ -391,14 +391,7 @@ function attachEvents() {
listAllRoles(groupId); listAllRoles(groupId);
var shareGroupNextLink = $("a#share-group-next-link"); var shareGroupNextLink = $("a#share-group-next-link");
shareGroupNextLink.click(function () { shareGroupNextLink.click(function () {
var roles = []; var roles = $("#roles").val();
$('.modal .roleCheckBoxes').each(
function () {
if ($(this).is(':checked')) {
roles.push($(this).data('role-name'));
}
}
);
updateGroupShare(groupId, roles); updateGroupShare(groupId, roles);
}); });
@ -505,15 +498,11 @@ function markAlreadySavedUsersRoles(groupId) {
data = JSON.parse(data); data = JSON.parse(data);
if (xhr.status == 200) { if (xhr.status == 200) {
if (data.roles.length > 0) { if (data.roles.length > 0) {
var selectedValues = [];
for (var i = 0; i < data.roles.length; i++) { for (var i = 0; i < data.roles.length; i++) {
$('.roleCheckBoxes').each( selectedValues.push(data.roles[i]);
function () {
if (data.roles[i] == $(this).data('role-name')) {
$(this).attr('checked', true);
}
}
);
} }
$("#roles").val(selectedValues).trigger("change");
} else { } else {
return; return;
} }
@ -533,22 +522,16 @@ function listAllRoles(groupId) {
data = JSON.parse(data); data = JSON.parse(data);
if (xhr.status == 200) { if (xhr.status == 200) {
if (data.roles.length > 0) { if (data.roles.length > 0) {
var html = "<br/>"; var html = '<select id="roles" class="form-control select2" multiple="multiple">';
for (var i = 0; i < data.roles.length; i++) { for (var i = 0; i < data.roles.length; i++) {
html += '<div class="wr-input-control"><label class="wr-input-control checkbox">' + html += '<option value="' + data.roles[i] + '">' + data.roles[i] + '</option>';
'<input class="roleCheckBoxes" type="checkbox" data-role-name="' + data.roles[i] + '" />' +
'<span class="helper" title="' + data.roles[i] + '">' + data.roles[i] +
'</span></label></div>';
$('.roleCheckBoxes').each(
function () {
if (data.roles[i] == $(this).data('role-name')) {
$(this).attr('checked', true);
}
}
);
} }
html += '</select>';
$("#rolesListing").html(html); $("#rolesListing").html(html);
markAlreadySavedUsersRoles(groupId); markAlreadySavedUsersRoles(groupId);
$("select.select2[multiple=multiple]").select2({
tags: false
});
} else { } else {
$("#rolesListing").html("No roles available"); $("#rolesListing").html("No roles available");
} }

Loading…
Cancel
Save