diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 1a4584c..2638d92 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -24,6 +24,9 @@ # Get the current user's org @default_org = current_user.org if @orgs.include?(current_user.org) + # Get the default template + @default_template = Template.default + flash[:notice] = "#{_('This is a')} #{_('test plan')}" if params[:test] @is_test = params[:test] ||= false respond_to :html diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 42ab240..2a37227 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -5,4 +5,24 @@ end a.join(separator) end -end \ No newline at end of file + + # TODO: to be removed upon merge with direct link feature + # Generate a direct plan creation link with 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] HTML 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/views/plans/_form_v2.html.erb b/app/views/plans/_form_v2.html.erb index f687fe5..12ace5e 100644 --- a/app/views/plans/_form_v2.html.erb +++ b/app/views/plans/_form_v2.html.erb @@ -29,7 +29,7 @@

<%= _('Would you like to use the default template "Default Template"?') %>

- + <%= direct_link(@default_template, false, _('Use Default Template')) %> <% if @default_org %> <%= hidden_field_tag('own_org_name', @default_org.name) %> @@ -120,7 +120,7 @@
<%= f.button(_('Yes'), class: "btn btn-primary", type: "submit") %> <%= link_to _('No'), '', class: 'btn btn-primary', id: 'no-btn' %> - <%= link_to _('Default template'), '', class: 'btn btn-primary', id: 'end-default-btn', style: 'display: none;' %> + <%= direct_link(@default_template, true, _('Use Default Template'), 'end-default-btn') %>
<% end %>