diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 361660b3b5..2a3fccff17 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -17,6 +17,10 @@ def index @organisationally_or_publicly_visible = Plan.organisationally_or_publicly_visible(current_user).page(1) end + + if params[:plan].present? + @template = Template.find(params[:plan][:template_id]) + end end # GET /plans/new diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 3905e98735..2a8392eddc 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,4 +33,22 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end + # Generate a direct plan creation link based on provided template + # @param template [Template] template used for plan creation + # @param hidden [Boolean] should the link be hidden? + # @param text [String] text for the link + # @param id [String] id for the link element + def direct_link(template, hidden = false, text = nil, id = nil) + params = { org_id: template.org.id, funder_id: '-1', template_id: template.id } + cls = text.nil? ? 'direct-link' : 'direct-link btn btn-default' + style = hidden ? 'display: none' : '' + + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, id: id, style: style) do + if text.nil? + ''.html_safe + else + text.html_safe + end + end + end end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index adbe7ed762..d612b09ed2 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -47,3 +47,4 @@ import '../views/usage/index'; import '../views/users/notification_preferences'; import '../views/users/admin_grant_permissions'; import '../views/super_admin/notifications/edit'; +import '../views/public_templates/show'; diff --git a/app/javascript/views/plans/index.js b/app/javascript/views/plans/index.js index b030b67f4e..b3cd74c1eb 100644 --- a/app/javascript/views/plans/index.js +++ b/app/javascript/views/plans/index.js @@ -26,4 +26,6 @@ $(() => { $(paginableSelector).on('ajax:error', '.set_test_plan', () => { // TODO adequate error handling for network error }); + + $('#create-modal').modal('show'); }); diff --git a/app/javascript/views/public_templates/show.js b/app/javascript/views/public_templates/show.js new file mode 100644 index 0000000000..16bf07f7dc --- /dev/null +++ b/app/javascript/views/public_templates/show.js @@ -0,0 +1,15 @@ +$(() => { + $('.copy-link').click((e) => { + const link = $(e.currentTarget).siblings('.direct-link'); + + $('#link-modal').on('show.bs.modal', () => { + $('#link').val(link.attr('href')); + }); + }); + + $('#copy-link-btn').click(() => { + $('#link').select(); + // eslint-disable-next-line + document.execCommand('copy'); + }); +}); diff --git a/app/views/paginable/templates/_organisational.html.erb b/app/views/paginable/templates/_organisational.html.erb index e19df20425..0fdba4df2a 100644 --- a/app/views/paginable/templates/_organisational.html.erb +++ b/app/views/paginable/templates/_organisational.html.erb @@ -76,14 +76,18 @@ 'data-confirm': _('Are you sure you want to remove "%{template_title}"? Any published versions will become unavailable to users.') % { template_title: template.title} %> <% end %> -
<%= _('Would you like to create a plan based on the "%{name}" template?') % { name: @template.title }%>
+