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:
@@ -20,5 +20,6 @@ $(document).ready(function() {
|
||||
// Bind user table buttons
|
||||
$("#widget-organisation-members").on("pagerComplete.ufTable", function () {
|
||||
bindUserButtons($(this));
|
||||
bindUserButtonsExtra($(this));
|
||||
});
|
||||
});
|
||||
|
||||
13
assets/avsdev/js/pages/user.js
Normal file
13
assets/avsdev/js/pages/user.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on uf-table.js, moment.js, handlebars-helpers.js
|
||||
*
|
||||
* Target page: /users/u/{user_name}
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
// Control buttons
|
||||
bindUserButtonsExtra($("#view-user"), { delete_redirect: page.delete_redirect });
|
||||
});
|
||||
15
assets/avsdev/js/pages/users.js
Normal file
15
assets/avsdev/js/pages/users.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on widgets/users.js, uf-table.js, moment.js, handlebars-helpers.js
|
||||
*
|
||||
* Target page: /users
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
// Bind table buttons
|
||||
$("#widget-users").on("pagerComplete.ufTable", function () {
|
||||
bindUserButtonsExtra($(this));
|
||||
});
|
||||
});
|
||||
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