
js.permissionmanager.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of molgenis-core-ui Show documentation
Show all versions of molgenis-core-ui Show documentation
Spaghetti module containing core plugins and legacy UI components.
(function($, molgenis) {
"use strict";
$(function() {
function createGroupPermissionTable(data) {
var items = [];
$.each(data.entityIds, function(entityId, entityName) {
if(data.groupPermissionMap && data.groupPermissionMap[entityId.toLowerCase()]) {
$.each(data.groupPermissionMap[entityId.toLowerCase()], function(idx, perm) {
items.push('');
items.push('' + (idx == 0 ? entityName : '') + ' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
});
} else {
items.push('');
items.push('' + entityName + ' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
}
if(data.hierarchyPermissionMap && data.hierarchyPermissionMap[entityId.toLowerCase()]) {
$.each(data.hierarchyPermissionMap[entityId.toLowerCase()], function(idx, perm) {
items.push('');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
});
}
});
return items.join('');
}
function createUserPermissionTable(data) {
var items = [];
$.each(data.entityIds, function(entityId, entityName) {
if(data.userPermissionMap && data.userPermissionMap[entityId.toLowerCase()]) {
$.each(data.userPermissionMap[entityId.toLowerCase()], function(idx, perm) {
items.push('');
items.push('' + (idx == 0 ? entityName : '') + ' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
});
} else {
items.push(' ');
items.push('' + entityName + ' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
}
if(data.hierarchyPermissionMap && data.hierarchyPermissionMap[entityId.toLowerCase()]) {
$.each(data.hierarchyPermissionMap[entityId.toLowerCase()], function(idx, perm) {
items.push('');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
});
}
if(data.groupPermissionMap && data.groupPermissionMap[entityId.toLowerCase()]) {
$.each(data.groupPermissionMap[entityId.toLowerCase()], function(idx, perm) {
items.push('');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
items.push(' ');
});
}
});
return items.join('');
}
$('#plugin-group-select').change(function() {
$.get(molgenis.getContextUrl() + '/plugin/group/' + $(this).val(), function(data) {
$('#plugin-group-permission-table tbody').empty().html(createGroupPermissionTable(data));
});
});
$('#plugin-user-select').change(function() {
$.get(molgenis.getContextUrl() + '/plugin/user/' + $(this).val(), function(data) {
$('#plugin-user-permission-table tbody').empty().html(createUserPermissionTable(data));
});
});
$('#entity-class-group-select').change(function() {
$.get(molgenis.getContextUrl() + '/entityclass/group/' + $(this).val(), function(data) {
$('#entity-class-group-permission-table tbody').empty().html(createGroupPermissionTable(data));
});
});
$('#entity-class-user-select').change(function() {
$.get(molgenis.getContextUrl() + '/entityclass/user/' + $(this).val(), function(data) {
$('#entity-class-user-permission-table tbody').empty().html(createUserPermissionTable(data));
});
});
$('#plugin-group-permission-form,#plugin-user-permission-form,#entity-class-group-permission-form,#entity-class-user-permission-form').submit(function(e) {
e.preventDefault();
$.ajax({
type : $(this).attr('method'),
url : $(this).attr('action'),
data : $(this).serialize(),
success : function(data) {
$('#plugin-container .alert').remove();
$('#plugin-container').prepend('Success! Updated plugin permissions');
//Refresh
$('#plugin-group-select').change();
$('#entity-class-group-select').change();
$('#plugin-user-select').change();
$('#entity-class-user-select').change();
},
error: function (xhr, textStatus, errorThrown) {
var errorMessage = JSON.parse(xhr.responseText).errorMessage;
$('#plugin-container .alert').remove();
$('#plugin-container').prepend('Error! ' + errorMessage + '');
}
});
});
$('a[data-toggle="tab"][href="#plugin-group-permission-manager"]').on('show.bs.tab', function (e) {
$('#plugin-group-select').change();
});
$('a[data-toggle="tab"][href="#plugin-user-permission-manager"]').on('show.bs.tab', function (e) {
$('#plugin-user-select').change();
});
$('a[data-toggle="tab"][href="#entity-class-group-permission-manager"]').on('show.bs.tab', function (e) {
$('#entity-class-group-select').change();
});
$('a[data-toggle="tab"][href="#entity-class-user-permission-manager"]').on('show.bs.tab', function (e) {
$('#entity-class-user-select').change();
});
$('#plugin-group-select').change();
$('#entity-class-group-select').change();
});
}($, window.top.molgenis = window.top.molgenis || {}));
© 2015 - 2025 Weber Informatics LLC | Privacy Policy