Fix checkboxes at the protocol template table [SCI-8099] (#5108)

This commit is contained in:
ajugo 2023-03-09 15:01:21 +01:00 committed by GitHub
parent 90ea8425ff
commit b1468df3e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 25 deletions

View file

@ -135,9 +135,30 @@ var ProtocolsIndex = (function() {
}); });
} }
function initManageAccessButton() { function initManageAccess() {
$('.protocols-index').on('click', '#manageProtocolAccess', function() { let protocolsContainer = '.protocols-container';
$(`tr[data-row-id=${rowsSelected[0]}] .protocol-users-link`).click(); let manageAccessModal = '.protocol-assignments-modal';
function loadManageAccessModal(href) {
$.get(href, function(data) {
$(protocolsContainer).append($.parseHTML(data.html));
$(manageAccessModal).modal('show');
// Remove modal when it gets closed
$(manageAccessModal).on('hidden.bs.modal', function() {
$(manageAccessModal).remove();
});
});
}
protocolsTableEl.on('click', '.protocol-users-link', function(e) {
loadManageAccessModal(this.href);
e.stopPropagation();
e.preventDefault();
});
$(protocolsContainer).on('click', '#manageProtocolAccess', function() {
loadManageAccessModal($(`tr[data-row-id=${rowsSelected[0]}] .protocol-users-link`).attr('href'));
}); });
} }
@ -643,29 +664,18 @@ var ProtocolsIndex = (function() {
} }
function updateDataTableSelectAllCheckbox() { function updateDataTableSelectAllCheckbox() {
var table = protocolsDatatable.table().node(); var table = $('.protocols-datatable');
var checkboxesAll = $("tbody input[type='checkbox']", protocolsTableEl); var checkboxes = table.find("tbody input[type='checkbox']");
var checkboxesChecked = $("tbody input[type='checkbox']:checked", protocolsTableEl); var selectedCheckboxes = table.find("tbody input[type='checkbox']:checked");
var checkboxSelectAll = $("thead input[name='select_all']", table).get(0); var selectAllCheckbox = table.find("thead input[name='select_all']");
if (checkboxesChecked.length === 0) { selectAllCheckbox.prop('indeterminate', false);
// If none of the checkboxes are checked if (selectedCheckboxes.length === 0) {
checkboxSelectAll.checked = false; selectAllCheckbox.prop('checked', false);
if ('indeterminate' in checkboxSelectAll) { } else if (selectedCheckboxes.length === checkboxes.length) {
checkboxSelectAll.indeterminate = false; selectAllCheckbox.prop('checked', true);
}
} else if (checkboxesChecked.length === checkboxesAll.length) {
// If all of the checkboxes are checked
checkboxSelectAll.checked = true;
if ('indeterminate' in checkboxSelectAll) {
checkboxSelectAll.indeterminate = false;
}
} else { } else {
// If some of the checkboxes are checked selectAllCheckbox.prop('indeterminate', true);
checkboxSelectAll.checked = true;
if ('indeterminate' in checkboxSelectAll) {
checkboxSelectAll.indeterminate = true;
}
} }
} }
@ -970,7 +980,7 @@ var ProtocolsIndex = (function() {
} }
init(); init();
initManageAccessButton(); initManageAccess();
initArchiveProtocols(); initArchiveProtocols();
initRestoreProtocols(); initRestoreProtocols();
initExportProtocols(); initExportProtocols();

View file

@ -61,6 +61,10 @@
.dataTables_scrollBody { .dataTables_scrollBody {
height: 100%; height: 100%;
td:first-child {
padding-top: 13px;
}
td:not(:first-child) { td:not(:first-child) {
padding: 14px 8px; padding: 14px 8px;
} }