diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index eed54dc7c..c892e59f0 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -191,7 +191,13 @@ function initKeywordFiltering() { function initProtocolPreviewModal() { // Only do this if the repository is public/private if (repositoryType !== "archive") { - protocolsTableEl.on("click", "a[data-action='protocol-preview']", function(e) { + // If you are in protocol repository + var protocolsEl = protocolsTableEl; + // If you are in search results + if (document.getElementById("search-content")) { + protocolsEl = $("#search-content"); + } + protocolsEl.on("click", "a[data-action='protocol-preview']", function(e) { var link = $(this); $.ajax({ url: link.attr("data-url"), diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index ee40a4c92..1f3d46130 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -17,4 +17,16 @@ module SearchHelper link_to text, path end end + + def route_to_other_org_btn(path, search_org, text) + if search_org != current_organization + link_to text, + path, + class: 'btn btn-primary', + data: { confirm: t('users.settings.changed_org_in_search', + team: search_org.name) } + else + link_to text, path, class: 'btn btn-primary' + end + end end diff --git a/app/views/protocols/index/_protocol_preview_modal_footer.html.erb b/app/views/protocols/index/_protocol_preview_modal_footer.html.erb index 430b7e028..6b60460a4 100644 --- a/app/views/protocols/index/_protocol_preview_modal_footer.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_footer.html.erb @@ -1,4 +1,6 @@ <% if can_edit_protocol(@protocol) %> - <%= link_to t("general.edit"), edit_protocol_path(@protocol), :class => "btn btn-primary" %> + <%= route_to_other_org_btn edit_protocol_path(protocol), + protocol.organization, + t("general.edit") %> <% end %> diff --git a/app/views/search/results/_protocols.html.erb b/app/views/search/results/_protocols.html.erb index 2a9de39b0..e3aea0810 100644 --- a/app/views/search/results/_protocols.html.erb +++ b/app/views/search/results/_protocols.html.erb @@ -1,3 +1,5 @@ +<%= render partial: "protocols/index/protocol_preview_modal.html.erb" %> + <% results.each do |protocol| %> <% has_description = protocol.description.present? && !protocol.description.empty? %> <% has_authors = protocol.authors.present? && !protocol.authors.empty? %> @@ -119,3 +121,20 @@