diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index 56ff633..61a2238 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -300,11 +300,14 @@ end end end - + # If the no funder was specified OR the funder matches the org if funder_id.blank? || funder_id == org_id # Retrieve the Org's templates - templates << Template.published.organisationally_visible.where(org_id: org_id, customization_of: nil).to_a + templates << Template.published.organisationally_visible.where(org_id: org_id).to_a.map do |template| + template.title = "#{template.title} (#{d_('dmpopidor', 'Customized by ')} #{Org.find(org_id).name})" if template.customization_of + template + end end templates = templates.flatten.uniq end @@ -319,7 +322,7 @@ end templates = (templates.count > 0 ? templates.sort{|x,y| x.title <=> y.title} : []) - render json: {"templates": templates.collect{|t| {id: t.id, title: t.title} }}.to_json + render json: {"templates": templates.collect{|t| { id: t.id, title: t.title, default: t.is_default } }}.to_json end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 30a8b2b..eb62e10 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -30,6 +30,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/views/branded/plans/new.html.erb b/app/views/branded/plans/new.html.erb deleted file mode 100644 index 5a28baa..0000000 --- a/app/views/branded/plans/new.html.erb +++ /dev/null @@ -1,96 +0,0 @@ -<% title _('Create a new plan') %> -
-
- <%= form_for Plan.new, url: plans_path do |f| %> - -

* <%= _('Project title') %>

-
-
- <%= f.text_field(:title, class: 'form-control', 'aria-describedby': 'project-title', 'aria-required': 'true', - 'data-toggle': 'tooltip', - title: _('If applying for funding, state the project title exactly as in the proposal.')) %> -
-
 
-
- <%= label_tag(:is_test, raw("#{check_box_tag(:is_test, "1", false)} #{ d_('dmpopidor', 'Plan for testing, practice, or educational purposes')}")) %> -
-
- - -

<%= d_('dmpopidor', 'Choose a template') %>

-

- <%= d_('dmpopidor', 'Several template types are available:') %> -

- <%= link_to d_('dmpopidor', 'Find the list of the available templates'), public_templates_path, :target => "_blank" %> -

-

* <%= d_('dmpopidor', 'Select a research organisation:') %>

-
-
- <%= render partial: "shared/accessible_combobox", - locals: {name: 'plan[org_name]', - id: 'plan_org_name', - default_selection: @default_org, - models: @orgs, - attribute: 'name', - required: true, - error: _('You must select a research organisation from the list.'), - tooltip: _('Please select a valid research organisation from the list.')} %> -
-
- <%= _('or') %> -
-
-
- <% primary_research_org_message = d_('dmpopidor', 'No research organisation') %> - <%= label_tag(:plan_no_org, raw("#{check_box_tag(:plan_no_org)} #{primary_research_org_message}")) %> -
-
-
- - -

* <%= d_('dmpopidor', 'Select a funder:') %>

-
-
- <%= render partial: "shared/accessible_combobox", - locals: {name: 'plan[funder_name]', - id: 'plan_funder_name', - default_selection: nil, - models: @funders, - attribute: 'name', - required: true, - error: _('You must select a funding organisation from the list.'), - tooltip: _('Please select a valid funding organisation from the list.')} %> -
-
- <%= _('or') %> -
-
-
- <% primary_funding_message = d_('dmpopidor', 'No funder associated with this plan') %> - <%= label_tag(:plan_no_funder, raw("#{check_box_tag(:plan_no_funder)} #{primary_funding_message}")) %> -
-
-
- - -
- <%= hidden_field_tag 'template-option-target', org_admin_template_options_path %> -

<%= d_('dmpopidor', 'Select a template:') %>

-
-
- <%= select_tag(:plan_template_id, "", name: 'plan[template_id]', - class: 'form-control', 'aria-describedby': 'template-selection') %> -
-
- <%= d_('dmpopidor', 'We found multiple DMP templates corresponding to your choices.') %> -
-
-
- - <%= f.hidden_field(:visibility, value: @is_test ? 'is_test' : Rails.application.config.default_plan_visibility) %> - <%= f.button(_('Create plan'), class: "btn btn-primary", type: "submit") %> - <%= link_to _('Cancel'), plans_path, class: 'btn btn-default' %> - <% end %> -
-
diff --git a/app/views/plans/_form_v1.html.erb b/app/views/plans/_form_v1.html.erb new file mode 100644 index 0000000..ca67736 --- /dev/null +++ b/app/views/plans/_form_v1.html.erb @@ -0,0 +1,92 @@ +
+
+

<%= _('Create a new plan') %>

+ +

+ <%= _("Before you get started, we need some information about your research project to set you up with the best DMP template for your needs.") %> +

+
+
+ +
+
+ <%= form_for Plan.new, url: plans_path do |f| %> + +

<%= _('What research project are you planning?') %>

+
+
+ <%= f.text_field(:title, class: 'form-control', 'aria-describedby': 'project-title', 'aria-required': 'true', + 'data-toggle': 'tooltip', + title: _('If applying for funding, state the project title exactly as in the proposal.')) %> +
+
 
+
+ <%= label_tag(:is_test, raw("#{check_box_tag(:is_test, "1", false)} #{_('mock project for testing, practice, or educational purposes')}")) %> +
+
+ + +

<%= _('Select the primary research organisation') %>

+
+
+ <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[org_name]', + id: 'plan_org_name', + default_selection: @default_org, + models: @orgs, + attribute: 'name', + required: true, + error: _('You must select a research organisation from the list.'), + tooltip: _('Please select a valid research organisation from the list.')} %> +
+
- <%= _('or') %> -
+
+
+ <%= label_tag(:plan_no_org, raw("#{check_box_tag(:plan_no_org)} #{_('My research organisation is not on the list')} #{_(' or ')} #{_('no research organisation is associated with this plan')}")) %> +
+
+
+ + +

<%= _('Select the primary funding organisation') %>

+
+
+ <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[funder_name]', + id: 'plan_funder_name', + default_selection: nil, + models: @funders, + attribute: 'name', + required: true, + error: _('You must select a funding organisation from the list.'), + tooltip: _('Please select a valid funding organisation from the list.')} %> +
+
- <%= _('or') %> -
+
+
+ <%= label_tag(:plan_no_funder, raw("#{check_box_tag(:plan_no_funder)} #{_('No funder associated with this plan')}")) %> +
+
+
+ + +
+ <%= hidden_field_tag 'template-option-target', org_admin_template_options_path %> +

<%= _('Which DMP template would you like to use?') %>

+
+
+ <%= select_tag(:plan_template_id, "", name: 'plan[template_id]', + class: 'form-control', 'aria-describedby': 'template-selection') %> +
+
+ <%= _('We found multiple DMP templates corresponding to your funder.') %> +
+
+
+ + <%= f.hidden_field(:visibility, value: @is_test ? 'is_test' : Rails.application.config.default_plan_visibility) %> + <%= f.button(_('Create plan'), class: "btn btn-primary", type: "submit") %> + <%= link_to _('Cancel'), plans_path, class: 'btn btn-default' %> + <% end %> +
+
diff --git a/app/views/plans/_form_v2.html.erb b/app/views/plans/_form_v2.html.erb new file mode 100644 index 0000000..b39aeea --- /dev/null +++ b/app/views/plans/_form_v2.html.erb @@ -0,0 +1,120 @@ + +
+
+

<%= _('Create a new plan') %>

+
+
+ +
+
+ <%= form_for Plan.new, url: plans_path do |f| %> + + + + + +
+ +
+

+ <%= d_('dmpopidor', 'Would you like to use the default template "%{template_name}"?') % { :template_name => @default_template.title } %> +

+ <%= direct_link(@default_template, false, d_('dmpopidor', 'Use Default Template')) %> + + <% if @default_org %> + <%= hidden_field_tag('own_org_name', @default_org.name) %> + <%= hidden_field_tag('own_org_id', @default_org.id) %> + <% end %> +
+ + +
+

+ <%= d_('dmpopidor', 'Would you like to choose the template of another organisation?') %> +

+ + <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[org_name]', + id: 'plan_org_name', + default_selection: @default_org, + models: @orgs, + attribute: 'name', + required: true, + error: _('You must select a research organisation from the list.'), + tooltip: _('Please select a valid research organisation from the list.')} %> +
+ + +
+

+ <%= d_('dmpopidor', 'Would you like to choose the template of a funder?') %> +

+ + <%= render partial: "shared/accessible_combobox", + locals: {name: 'plan[funder_name]', + id: 'plan_funder_name', + default_selection: nil, + models: @funders, + attribute: 'name', + required: true, + error: _('You must select a funding organisation from the list.'), + tooltip: _('Please select a valid funding organisation from the list.')} %> +
+ + + <%= check_box_tag(:plan_no_org, '', false, style: 'display: none;') %> + <%= check_box_tag(:plan_no_funder, '', true, style: 'display: none;') %> + + + + + + + + + + + + <% unless @default_org %> +
+

+ <%= d_('dmpopidor', 'You are not linked to an organisation, we can\'t suggest you a template. Please choose an organisation in your profile') %> +

+
+ <% end %> + + +
+ <%= f.button(_('Yes'), class: "btn btn-primary", type: "submit") %> + <%= link_to _('No'), '', class: 'btn btn-primary', id: 'no-btn' %> + <%= direct_link(@default_template, true, d_('dmpopidor', 'Use Default Template'), 'end-default-btn') %> +
+
+ <% end %> +
+
diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index 963960e..8c53f8e 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -1,95 +1,5 @@ -<% title _('Create a new plan') %> -
-
-

<%= _('Create a new plan') %>

- -

- <%= _("Before you get started, we need some information about your research project to set you up with the best DMP template for your needs.") %> -

-
-
- -
-
- <%= form_for Plan.new, url: plans_path do |f| %> - -

* <%= _('What research project are you planning?') %>

-
-
- <%= f.text_field(:title, class: 'form-control', 'aria-describedby': 'project-title', 'aria-required': 'true', 'aria-label': 'project-title', - 'data-toggle': 'tooltip', - title: _('If applying for funding, state the project title exactly as in the proposal.')) %> -
-
 
-
- <%= label_tag(:is_test, raw("#{check_box_tag(:is_test, "1", false)} #{_('mock project for testing, practice, or educational purposes')}")) %> -
-
- - -

* <%= _('Select the primary research organisation') %>

-
-
- <%= render partial: "shared/accessible_combobox", - locals: {name: 'plan[org_name]', - id: 'plan_org_name', - default_selection: @default_org, - models: @orgs, - attribute: 'name', - required: true, - error: _('You must select a research organisation from the list.'), - tooltip: _('Please select a valid research organisation from the list.')} %> -
-
- <%= _('or') %> -
-
-
- <% primary_research_org_message = _('No research organisation associated with this plan or my research organisation is not listed') %> - <%= label_tag(:plan_no_org, raw("#{check_box_tag(:plan_no_org)} #{primary_research_org_message}")) %> -
-
-
- - -

* <%= _('Select the primary funding organisation') %>

-
-
- <%= render partial: "shared/accessible_combobox", - locals: {name: 'plan[funder_name]', - id: 'plan_funder_name', - default_selection: nil, - models: @funders, - attribute: 'name', - required: true, - error: _('You must select a funding organisation from the list.'), - tooltip: _('Please select a valid funding organisation from the list.')} %> -
-
- <%= _('or') %> -
-
-
- <% primary_funding_message = _('No funder associated with this plan or my funder is not listed') %> - <%= label_tag(:plan_no_funder, raw("#{check_box_tag(:plan_no_funder)} #{primary_funding_message}")) %> -
-
-
- - -
- <%= hidden_field_tag 'template-option-target', org_admin_template_options_path %> -

<%= _('Which DMP template would you like to use?') %>

-
-
- <%= select_tag(:plan_template_id, "", name: 'plan[template_id]', - class: 'form-control', 'aria-describedby': 'template-selection') %> -
-
- <%= _('We found multiple DMP templates corresponding to your funder.') %> -
-
-
- - <%= f.hidden_field(:visibility, value: @is_test ? 'is_test' : Rails.application.config.default_plan_visibility) %> - <%= f.button(_('Create plan'), class: "btn btn-primary", type: "submit") %> - <%= link_to _('Cancel'), plans_path, class: 'btn btn-default' %> - <% end %> -
-
+<% if params[:v1] == "true" %> + <%= render "form_v1" %> +<% else %> + <%= render "form_v2" %> +<% end %> diff --git a/config/locale/dmpopidor.pot b/config/locale/dmpopidor.pot index 50601e1..6898d0e 100644 --- a/config/locale/dmpopidor.pot +++ b/config/locale/dmpopidor.pot @@ -165,6 +165,39 @@ msgid "You" msgstr "" +msgid "Your organisation" +msgstr "" + +msgid "Other organisation" +msgstr "" + +msgid "Use Default Template" +msgstr "" + +msgid "Would you like to use the default template \"%{template_name}\"?" +msgstr "" + +msgid "Would you like to choose the template of another organisation?" +msgstr "" + +msgid "Would you like to choose the template of a funder?" +msgstr "" + +msgid "The organisation provides multiple templates, which one would you like to use?" +msgstr "" + +msgid "This organisation provides a template. Would you like to create a plan from the \"__template_title__\" template?" +msgstr "" + +msgid "This organisation does not provide a template. Would you like to create a plan using the default \"__template_title__\" template?" +msgstr "" + +msgid "You are not linked to an organisation, we can\'t suggest you a template. Please choose an organisation in your profile" +msgstr "" + +msgid "Customized by " +msgstr "" + msgid "Copy link" msgstr "" diff --git a/config/locale/en_GB/dmpopidor.po b/config/locale/en_GB/dmpopidor.po index 89a1e84..1423736 100644 --- a/config/locale/en_GB/dmpopidor.po +++ b/config/locale/en_GB/dmpopidor.po @@ -163,6 +163,39 @@ msgid "You" msgstr "You" +msgid "Your organisation" +msgstr "Your organisation" + +msgid "Other organisation" +msgstr "Other organisation" + +msgid "Use Default Template" +msgstr "Use Default Template" + +msgid "Would you like to use the default template \"%{template_name}\"?" +msgstr "Would you like to use the default template \"%{template_name}\"?" + +msgid "Would you like to choose the template of another organisation?" +msgstr "Would you like to choose the template of another organisation?" + +msgid "Would you like to choose the template of a funder?" +msgstr "Would you like to choose the template of a funder?" + +msgid "The organisation provides multiple templates, which one would you like to use?" +msgstr "The organisation provides multiple templates, which one would you like to use?" + +msgid "This organisation provides a template. Would you like to create a plan from the \"__template_title__\" template?" +msgstr "This organisation provides a template. Would you like to create a plan from the \"__template_title__\" template?" + +msgid "This organisation does not provide a template. Would you like to create a plan using the default \"__template_title__\" template?" +msgstr "This organisation does not provide a template. Would you like to create a plan using the default \"__template_title__\" template?" + +msgid "You are not linked to an organisation, we can\'t suggest you a template. Please choose an organisation in your profile" +msgstr "You are not linked to an organisation, we can\'t suggest you a template. Please choose an organisation in your profile" + +msgid "Customized by " +msgstr "Customized by " + msgid "Copy link" msgstr "Copy link" diff --git a/config/locale/fr_FR/dmpopidor.po b/config/locale/fr_FR/dmpopidor.po index 1d17624..b7f887c 100644 --- a/config/locale/fr_FR/dmpopidor.po +++ b/config/locale/fr_FR/dmpopidor.po @@ -162,6 +162,39 @@ msgid "You" msgstr "Vous" +msgid "Your organisation" +msgstr "Votre organisation" + +msgid "Other organisation" +msgstr "Autre organisation" + +msgid "Use Default Template" +msgstr "Utiliser le modèle par défaut" + +msgid "Would you like to use the default template \"%{template_name}\"?" +msgstr "Souhaitez-vous utiliser le modèle par défaut \"%{template_name}\" ?" + +msgid "Would you like to choose the template of another organisation?" +msgstr "Souhaitez-vous choisir le modèle d'une autre organisation ?" + +msgid "Would you like to choose the template of a funder?" +msgstr "Souhaitez-vous utiliser le modèle d'un financeur ?" + +msgid "The organisation provides multiple templates, which one would you like to use?" +msgstr "Cette organisation propose plusieurs modèles, lequel souhaitez-vous utiliser ?" + +msgid "This organisation provides a template. Would you like to create a plan from the \"__template_title__\" template?" +msgstr "Cette organisation propose un modèle. Souhaitez-vous créer un plan à partir du modèle \"__template_title__\" ?" + +msgid "This organisation does not provide a template. Would you like to create a plan using the default \"__template_title__\" template?" +msgstr "Cette organisation ne propose pas de modèle. Souhaitez-vous créer un plan à partir du modèle par défaut \"__template_title__\" ?" + +msgid "You are not linked to an organisation, we can\'t suggest you a template. Please choose an organisation in your profile" +msgstr "Vous n'êtes pas liés à une organisation, nous ne pouvons vous proposer un modèle. Veuillez choisir une organisation dans votre profil." + +msgid "Customized by " +msgstr "Personnalisé par " + msgid "Copy link" msgstr "Copier le lien" diff --git a/lib/assets/javascripts/views/plans/new.js b/lib/assets/javascripts/views/plans/new.js index 1c4141f..68c9f3f 100644 --- a/lib/assets/javascripts/views/plans/new.js +++ b/lib/assets/javascripts/views/plans/new.js @@ -37,11 +37,27 @@ // If there is only one template, set the input field value and submit the form // otherwise show the dropdown list and the 'Multiple templates found message' if (data.templates.length === 1) { + const templateTitle = data.templates[0].title; $('#plan_template_id option').attr('selected', 'true'); $('#multiple-templates').hide(); + if ($('#plan_org_id').val() !== '-1') { + if (data.templates[0].default) { + $('#default-template .single-template-name').html($('#default-template .single-template-name').html().replace('__template_title__', templateTitle)); + $('#default-template').show(); + $('#single-template').hide(); + } else { + $('#single-template .single-template-name').html($('#single-template .single-template-name').html().replace('__template_title__', templateTitle)); + $('#single-template').show(); + $('#default-template').hide(); + } + } else if ($('#plan_funder_id').val() !== '-1') { + $('#single-template .single-template-name').html($('#single-template .single-template-name').html().replace('__template_title__', templateTitle)); + $('#single-template').show(); + } } else { $('#multiple-templates').show(); $('#available-templates').fadeIn(); + $('#single-template, #default-template').hide(); } toggleSubmit(); } else { @@ -105,7 +121,7 @@ // If the user clicks the no Org/Funder checkbox disable the dropdown // and hide clear button - $('#new_plan #plan_no_org, #new_plan #plan_no_funder').click((e) => { + $('#new_plan #plan_no_org, #new_plan #plan_no_funder').change((e) => { const whichOne = $(e.currentTarget).prop('id').split('_')[2]; handleCheckboxClick(whichOne, e.currentTarget.checked); }); @@ -121,4 +137,55 @@ if ($('#plan_no_funder').prop('checked')) { handleCheckboxClick('funder', $('#plan_no_funder').prop('checked')); } + + // For form v2 + + // Clicking on the 'No' button activates the next tabs + $('#no-btn').click((e) => { + e.preventDefault(); + const nextTabId = $('.form-tabs li.active').next().children().attr('href'); + if (nextTabId) $(`.nav-tabs a[href="${nextTabId}"]`).tab('show'); + }); + + // Watch for tab change for dynamic buttons ('No' and 'Default Template') + $('a[data-toggle="tab"]').on('shown.bs.tab', () => { + const activeTab = $('.form-tabs li.active a').attr('href'); + const lastTab = $('.form-tabs li a').last().attr('href'); + if (activeTab === lastTab) { + $('#no-btn').hide(); + $('#end-default-btn').show(); + } else { + $('#no-btn').show(); + $('#end-default-btn').hide(); + } + }); + + // First and second tab are equivalent to checking the "No funder" checkbox + $('a[href="#own_org"], a[href="#other_org"]').on('shown.bs.tab', () => { + $('#plan_no_org').prop('checked', false).change(); + $('#plan_no_funder').prop('checked', true).change(); + }); + + // Empty combobox on second tab activation + const emptySecondTab = () => { + // $('#plan_org_id').val('-1'); + $('#plan_org_name').val(''); + $('#single-template, #default-template').hide(); + }; + + // Empty combobox on second tab activation + $('a[href="#other_org"]').on('shown.bs.tab', emptySecondTab); + $('a[href="#other_org"]').on('hidden.bs.tab', emptySecondTab); + + // Restore default organisation when activating first tab + $('a[href="#own_org"]').on('shown.bs.tab', () => { + $('#plan_org_name').val($('#own_org_name').val()); + $('#plan_org_id').val($('#own_org_id').val()); + }); + + // Last tab is equivalent to checking the "No org" checkbox + $('a[href="#funder"]').on('shown.bs.tab', () => { + $('#plan_no_org').prop('checked', true).change(); + $('#plan_no_funder').prop('checked', false).change(); + }); }); diff --git a/lib/assets/stylesheets/dmpopidor.scss b/lib/assets/stylesheets/dmpopidor.scss index 9e119a4..d6ea4b5 100644 --- a/lib/assets/stylesheets/dmpopidor.scss +++ b/lib/assets/stylesheets/dmpopidor.scss @@ -143,6 +143,11 @@ font-size: 20px; } + h3 { + color: $blue; + font-size: 17px; + } + a { color: $blue; } @@ -574,4 +579,15 @@ top: 50%; left: 50%; transform: translate(-50%, -50%); +} + +/* + PLAN CREATION +*/ + +.plan-form { + .tab-content { + padding: 25px 25px 50px 25px; + border: 1px solid $blue; + } } \ No newline at end of file