diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 83c119f..e601777 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -4,6 +4,7 @@ helper PaginableHelper helper SettingsTemplateHelper after_action :verify_authorized, except: [:overview] + before_filter :set_templates, only: :new def index authorize Plan @@ -153,18 +154,18 @@ def edit plan = Plan.find(params[:id]) authorize plan - + plan, phase = Plan.load_for_phase(params[:id], params[:phase_id]) - + readonly = !plan.editable_by?(current_user.id) - + guidance_groups_ids = plan.guidance_groups.collect(&:id) - + guidance_groups = GuidanceGroup.where(published: true, id: guidance_groups_ids) # Since the answers have been pre-fetched through plan (see Plan.load_for_phase) # we create a hash whose keys are question id and value is the answer associated answers = plan.answers.reduce({}){ |m, a| m[a.question_id] = a; m } - + render('/phases/edit', locals: { base_template_org: phase.template.base_org, plan: plan, phase: phase, readonly: readonly, @@ -172,7 +173,7 @@ guidance_groups: guidance_groups, answers: answers }) end - + # PUT /plans/1 # PUT /plans/1.json def update @@ -186,7 +187,7 @@ guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i).uniq @plan.guidance_groups = GuidanceGroup.where(id: guidance_group_ids) @plan.save - + if @plan.update_attributes(attrs) format.html { redirect_to overview_plan_path(@plan), notice: success_message(_('plan'), _('saved')) } format.json {render json: {code: 1, msg: success_message(_('plan'), _('saved'))}} @@ -195,7 +196,7 @@ format.html { render action: "edit" } format.json {render json: {code: 0, msg: flash[:alert]}} end - + rescue Exception flash[:alert] = failed_update_error(@plan, _('plan')) format.html { render action: "edit" } @@ -447,4 +448,13 @@ end plan.delete(src_plan_key) end + + def set_templates + @templates = current_user + .org + .templates + .published + .organisationally_visible + .where(customization_of: nil) + end 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..16da10b --- /dev/null +++ b/app/views/plans/_form_v2.html.erb @@ -0,0 +1,95 @@ + +
+
+

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

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

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

+ + <%= hidden_field_tag('own_org_name', current_user.org.name) %> + <%= hidden_field_tag('own_org_id', current_user.org.id) %> +

+ <%= _('Your organisation provides multiple templates, would you like to choose one of them') %> +

+
+ + +
+

+ <%= _('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.')} %> +

+ <%= _('The chosen organisation has more than one template, please choose one of them') %> +

+
+ + +
+

+ <%= _('Would you like to choose a 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.')} %> +

+ <%= _('The chosen funder has more than one template, please choose one of them') %> +

+
+ + <%= check_box_tag(:plan_no_org, '', false, style: 'display: block;') %> + <%= check_box_tag(:plan_no_funder, '', true, style: 'display: block;') %> + <%= hidden_field_tag 'template-option-target', org_admin_template_options_path %> + <%= select_tag( + :plan_template_id, options_from_collection_for_select( + @templates, 'id', 'title', @templates.first.id + )) %> + + +
+ <%= 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;' %> +
+
+ <% end %> +
+
diff --git a/app/views/plans/new.html.erb b/app/views/plans/new.html.erb index 963960e..e7dcfcc 100644 --- a/app/views/plans/new.html.erb +++ b/app/views/plans/new.html.erb @@ -1,95 +1,7 @@ -<% 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[:v2] == "true" %> +<%= link_to 'Form v1', new_plan_path(v2: false) %> +<%= render "form_v2" %> +<% else %> +<%= link_to 'Form v2', new_plan_path(v2: true) %> +<%= render "form_v1" %> +<% end %> diff --git a/lib/assets/javascripts/views/plans/new.js b/lib/assets/javascripts/views/plans/new.js index 1c4141f..1ca7623 100644 --- a/lib/assets/javascripts/views/plans/new.js +++ b/lib/assets/javascripts/views/plans/new.js @@ -121,4 +121,36 @@ if ($('#plan_no_funder').prop('checked')) { handleCheckboxClick('funder', $('#plan_no_funder').prop('checked')); } + + // 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_funder').prop('checked', true); + }); + + // 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()); + handleComboboxChange(); + }); });