Refactor cloning feature to better prepare for bulk clone [SCI-7990]

This commit is contained in:
Martin Artnik 2023-02-28 14:22:02 +01:00
parent 219814ec06
commit a3ffb38d2b
3 changed files with 17 additions and 14 deletions

View file

@ -495,25 +495,29 @@ var ProtocolsIndex = (function() {
function initDuplicateProtocols() {
$('.protocols-index').on('click', '#duplicateProtocol', function() {
duplicateProtocols(rowsSelected[0]);
duplicateProtocols($(this));
});
}
function duplicateProtocols(id) {
var row = $("tr[data-row-id='" + id + "']");
animateSpinner();
$.post(row.attr('data-clone-url'), (data) => {
animateSpinner(null, false);
HelperModule.flashAlertMsg(data.message, 'success');
reloadTable();
}).error((data) => {
function duplicateProtocols($el) {
$.ajax(
{
type: 'POST',
url: $el.data('url'),
data: JSON.stringify({ ids: rowsSelected }),
contentType: 'application/json'
},
(data) => {
animateSpinner(null, false);
HelperModule.flashAlertMsg(data.message, 'success');
reloadTable();
}
).error((data) => {
animateSpinner(null, false);
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
}
function initLinkedChildrenModal() {
// Only do this if the repository is public/private
if (repositoryType !== 'archive') {

View file

@ -89,8 +89,7 @@ class ProtocolsDatatable < CustomDatatable
{
DT_RowId: record.id,
DT_RowAttr: {
'data-permissions-url': permissions_protocol_path(record),
'data-clone-url': clone_protocols_path(ids: [record.id])
'data-permissions-url': permissions_protocol_path(record)
},
'1': name_html(record),
'2': record.code,

View file

@ -7,7 +7,7 @@
<i class="fas fa-door-open"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span>
</button>
<button id="duplicateProtocol" class="btn btn-light single-object-action hidden only-active" data-for="copyable">
<button id="duplicateProtocol" class="btn btn-light single-object-action hidden only-active" data-url="<%= clone_protocols_path %>" data-for="copyable">
<i class="fas fa-copy"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.duplicate") %></span>
</button>