Skip to content
4 changes: 4 additions & 0 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/template_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
'<span class="fa fa-plus-square"></span>'.html_safe
else
text.html_safe
end
end
end
end
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 2 additions & 0 deletions app/javascript/views/plans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ $(() => {
$(paginableSelector).on('ajax:error', '.set_test_plan', () => {
// TODO adequate error handling for network error
});

$('#create-modal').modal('show');
});
15 changes: 15 additions & 0 deletions app/javascript/views/public_templates/show.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
22 changes: 14 additions & 8 deletions app/views/paginable/templates/_organisational.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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} %>
</li>
<% end %>
<li><%= link_to template_export_org_admin_template_url(template, format: :pdf),
title: export_as_pdf,
target: '_blank',
class: 'has-new-window-popup-info' do %>
<%= export_as_pdf %>
<em class="sr-only"><%= _('(new window)') %></em>
<span class="new-window-popup-info"><%= _('Opens in new window') %></span>
<% end %>
<li><%= link_to template_export_org_admin_template_url(template, format: :pdf),
title: export_as_pdf,
target: '_blank',
class: 'has-new-window-popup-info' do %>
<%= export_as_pdf %>
<em class="sr-only"><%= _('(new window)') %></em>
<span class="new-window-popup-info"><%= _('Opens in new window') %></span>
<% end %>
</li>
<li>
<%= direct_link(template, true) %>
<a href="" class="copy-link" data-toggle="modal" data-target="#link-modal"><%= _('Copy link') %></a>
</li>
</ul>
</div>
Expand All @@ -94,3 +98,5 @@
</tbody>
</table>
</div>

<%= render 'shared/copy_link_modal' %>
9 changes: 8 additions & 1 deletion app/views/paginable/templates/_publicly_visible.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th scope="col"><%= _('Organisation Name') %>&nbsp;<%= paginable_sort_link('orgs.name') %></th>
<th scope="col" class="date-column"><%= _('Last Updated') %>&nbsp;<%= paginable_sort_link('templates.updated_at') %></th>
<th scope="col" class="sorter-false"><%= _('Funder Links') %></th>
<th><%= _('Actions') %></th>
<th scope="col" class="sorter-false" data-toggle="tooltip" title="<%= sample_plans_tooltip %>">
<%= _('Sample Plans') %><br><small><%= _('(if available)') %></small>
<em class="sr-only"><%= sample_plans_tooltip %></em>
Expand Down Expand Up @@ -39,11 +40,17 @@
<td>
<%= sanitize links_to_a_elements(template.links['funder'], '<br>') %>
</td>
<td class="text-center">
<%= direct_link(template) %>
<a href="" class="copy-link" data-toggle="modal" data-target="#link-modal"><span class="fa fa-clipboard"></span></a>
</td>
<td>
<%= sanitize links_to_a_elements(template.links['sample_plan'], '<br>') %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

<%= render 'shared/copy_link_modal' %>
2 changes: 2 additions & 0 deletions app/views/plans/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
<% end %>
</div>
</div>

<%= render 'shared/create_plan_modal' unless @template.nil? %>
16 changes: 16 additions & 0 deletions app/views/shared/_copy_link_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div id="link-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal">&times;</button>
<h4 class="modal-title">
<%= _('Copy link') %>
</h4>
</div>
<div class="modal-body">
<input type="text" id="link" readonly="readonly" style="width: 100%">
</div>
<div class="modal-footer">
<button id="copy-link-btn" class="btn btn-default"><%= _('Copy link') %></button>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions app/views/shared/_create_plan_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="create-modal" class="modal in" role="dialog">
<div class="modal-dialog">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><%= _('Create plan') %></h4>
</div>
<div class="modal-body">
<p><%= _('Would you like to create a plan based on the "%{name}" template?') % { name: @template.title }%></p>
</div>
<div class="modal-footer">
<%= direct_link(@template, false, _('Yes')) %>
<button class="btn btn-default" data-dismiss="modal"><%= _('No') %></button>
</div>
</div>
</div>