Provide ability for admins to manage user organisation membership & admin rights
- Required overwriting a bunch of base code to slot in the handling - Admins are shown with yellow text in their organisation label
This commit is contained in:
56
assets/avsdev/js/widgets/users.js
Normal file
56
assets/avsdev/js/widgets/users.js
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
/**
|
||||
* Link extra user action buttons in addition to the base ones.
|
||||
* @param {module:jQuery} el jQuery wrapped element to target.
|
||||
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
|
||||
*/
|
||||
function bindUserButtonsExtra(el, options) {
|
||||
// Manage user organisations button
|
||||
el.find('.js-user-organisations').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var userName = $(this).data('user_name');
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/users/organisations",
|
||||
ajaxParams: {
|
||||
user_name: userName
|
||||
},
|
||||
msgTarget: $("#alerts-page")
|
||||
});
|
||||
|
||||
$("body").on('renderSuccess.ufModal', function(data) {
|
||||
var modal = $(this).ufModal('getModal');
|
||||
var form = modal.find('.js-form');
|
||||
|
||||
// Set up collection widget
|
||||
var organisationWidget = modal.find('.js-form-organisations');
|
||||
organisationWidget.ufCollection({
|
||||
dropdown: {
|
||||
ajax: {
|
||||
url: site.uri.public + '/api/organisations'
|
||||
},
|
||||
placeholder: "Select an organisation"
|
||||
},
|
||||
dropdownTemplate: modal.find('#user-organisations-select-option').html(),
|
||||
rowTemplate: modal.find('#user-organisations-row').html()
|
||||
});
|
||||
|
||||
// Get current organisations and add to widget
|
||||
$.getJSON(site.uri.public + '/api/users/u/' + userName + '/organisations')
|
||||
.done(function(data) {
|
||||
$.each(data.rows, function(idx, organisation) {
|
||||
organisation.text = organisation.name;
|
||||
organisationWidget.ufCollection('addRow', organisation);
|
||||
});
|
||||
});
|
||||
|
||||
// Set up form for submission
|
||||
form.ufForm()
|
||||
.on("submitSuccess.ufForm", function() {
|
||||
// Reload page on success
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user