diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 1e3244165..2506f8552 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -420,13 +420,13 @@ var ProtocolsIndex = (function() { }); } - function initArchiveMyModules() { + function initArchiveProtocols() { $('.protocols-index').on('click', '#archiveProtocol', function(e) { - archiveMyModules(e.currentTarget.dataset.url, rowsSelected); + archiveProtocols(e.currentTarget.dataset.url, rowsSelected); }); } - function archiveMyModules(url, ids) { + function archiveProtocols(url, ids) { $.post(url, { protocol_ids: ids }, (data) => { HelperModule.flashAlertMsg(data.message, 'success'); protocolsDatatable.ajax.reload(); @@ -435,6 +435,24 @@ var ProtocolsIndex = (function() { }); } + function initExportProtocols() { + $('.protocols-index').on('click', '#exportProtocol', function(e) { + exportProtocols(e.currentTarget.dataset.url, rowsSelected); + }); + } + + function exportProtocols(url, ids) { + if (ids.length > 0) { + let params = '?protocol_ids[]=' + ids[0]; + for (let i = 1; i < ids.length; i += 1) { + params += '&protocol_ids[]=' + ids[i]; + } + params = encodeURI(params); + window.location.href = url + params; + } + } + + function initLinkedChildrenModal() { // Only do this if the repository is public/private if (repositoryType !== 'archive') { @@ -951,7 +969,8 @@ var ProtocolsIndex = (function() { init(); initManageAccessButton(); - initArchiveMyModules(); + initArchiveProtocols(); + initExportProtocols(); initdeleteDraftModal(); return { diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 72eb25a2e..66f047488 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -803,6 +803,7 @@ class ProtocolsController < ApplicationController # Create folder and xml file for each protocol and populate it @protocols.each do |protocol| + protocol = protocol.published_versions.order(version_number: :desc).first || protocol protocol_dir = get_guid(protocol.id).to_s ostream.put_next_entry("#{protocol_dir}/eln.xml") ostream.print(generate_protocol_xml(protocol)) diff --git a/app/views/protocols/index/_action_toolbar.html.erb b/app/views/protocols/index/_action_toolbar.html.erb index ebc98b12e..8def82d42 100644 --- a/app/views/protocols/index/_action_toolbar.html.erb +++ b/app/views/protocols/index/_action_toolbar.html.erb @@ -11,7 +11,7 @@ <%= t("protocols.index.action_toolbar.duplicate") %> -