diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 5c0550a..0f52806 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -11,8 +11,8 @@ # @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 } + def direct_link(template, hidden = false, text = nil, id = nil, title = "My Plan") + params = { org_id: template.org.id, funder_id: '-1', template_id: template.id, title: title } cls = text.nil? ? 'direct-link' : 'direct-link btn btn-default' style = hidden ? 'display: none' : '' diff --git a/lib/assets/javascripts/views/plans/new.js b/lib/assets/javascripts/views/plans/new.js index 1979986..338598e 100644 --- a/lib/assets/javascripts/views/plans/new.js +++ b/lib/assets/javascripts/views/plans/new.js @@ -192,4 +192,16 @@ $('#plan_no_org').prop('checked', true).change(); $('#plan_no_funder').prop('checked', false).change(); }); + + $('#new_plan #plan_title').on('change', (e) => { + const planTitle = encodeURI(e.target.value); + const regex = /plan%5Btitle%5D=([^&]+)/; + const defaultBtn = $('#new_plan #end-default-btn'); + if (!defaultBtn.attr('href').match(regex)) { + defaultBtn.attr('href', `${defaultBtn.attr('href')}&plan%5Btitle%5D=${planTitle}`); + } else { + defaultBtn.attr('href', defaultBtn.attr('href').replace(regex, `plan%5Btitle%5D=${planTitle}`)); + defaultBtn.attr('href').replace(regex, `plan%5Btitle%5D=${planTitle}`); + } + }); });