diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 540193f1d..b2340581a 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -135,9 +135,30 @@ var ProtocolsIndex = (function() { }); } - function initManageAccessButton() { - $('.protocols-index').on('click', '#manageProtocolAccess', function() { - $(`tr[data-row-id=${rowsSelected[0]}] .protocol-users-link`).click(); + function initManageAccess() { + let protocolsContainer = '.protocols-container'; + 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() { - var table = protocolsDatatable.table().node(); - var checkboxesAll = $("tbody input[type='checkbox']", protocolsTableEl); - var checkboxesChecked = $("tbody input[type='checkbox']:checked", protocolsTableEl); - var checkboxSelectAll = $("thead input[name='select_all']", table).get(0); + var table = $('.protocols-datatable'); + var checkboxes = table.find("tbody input[type='checkbox']"); + var selectedCheckboxes = table.find("tbody input[type='checkbox']:checked"); + var selectAllCheckbox = table.find("thead input[name='select_all']"); - if (checkboxesChecked.length === 0) { - // If none of the checkboxes are checked - checkboxSelectAll.checked = false; - if ('indeterminate' in checkboxSelectAll) { - checkboxSelectAll.indeterminate = false; - } - } else if (checkboxesChecked.length === checkboxesAll.length) { - // If all of the checkboxes are checked - checkboxSelectAll.checked = true; - if ('indeterminate' in checkboxSelectAll) { - checkboxSelectAll.indeterminate = false; - } + selectAllCheckbox.prop('indeterminate', false); + if (selectedCheckboxes.length === 0) { + selectAllCheckbox.prop('checked', false); + } else if (selectedCheckboxes.length === checkboxes.length) { + selectAllCheckbox.prop('checked', true); } else { - // If some of the checkboxes are checked - checkboxSelectAll.checked = true; - if ('indeterminate' in checkboxSelectAll) { - checkboxSelectAll.indeterminate = true; - } + selectAllCheckbox.prop('indeterminate', true); } } @@ -970,7 +980,7 @@ var ProtocolsIndex = (function() { } init(); - initManageAccessButton(); + initManageAccess(); initArchiveProtocols(); initRestoreProtocols(); initExportProtocols(); diff --git a/app/assets/stylesheets/protocols/index.scss b/app/assets/stylesheets/protocols/index.scss index 157c68fa2..e61e5d885 100644 --- a/app/assets/stylesheets/protocols/index.scss +++ b/app/assets/stylesheets/protocols/index.scss @@ -61,6 +61,10 @@ .dataTables_scrollBody { height: 100%; + td:first-child { + padding-top: 13px; + } + td:not(:first-child) { padding: 14px 8px; }