diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index ba39688..4662041 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -126,7 +126,8 @@ # Get all Guidance Groups applicable for the plan and group them by org @all_guidance_groups = @plan.get_guidance_group_options @all_ggs_grouped_by_org = @all_guidance_groups.sort.group_by(&:org) - + @selected_guidance_groups = @plan.guidance_groups + # Important ones come first on the page - we grab the user's org's GGs and "Organisation" org type GGs @important_ggs = [] @important_ggs << [current_user.org, @all_ggs_grouped_by_org.delete(current_user.org)] @@ -135,11 +136,18 @@ @important_ggs << [org,ggs] @all_ggs_grouped_by_org.delete(org) end + + # If this is one of the already selected guidance groups its important! + if !(ggs & @selected_guidance_groups).empty? + @important_ggs << [org,ggs] + @all_ggs_grouped_by_org.delete(org) + end end # Sort the rest by org name for the accordion + @important_ggs = @important_ggs.sort_by{|org,gg| org.name} @all_ggs_grouped_by_org = @all_ggs_grouped_by_org.sort_by {|org,gg| org.name} - @selected_guidance_groups = @plan.guidance_groups.pluck(:id) + @selected_guidance_groups = @selected_guidance_groups.collect{|gg| gg.id} @based_on = (@plan.template.customization_of.nil? ? @plan.template : Template.where(dmptemplate: @plan.template.customization_of).first) @@ -156,6 +164,7 @@ # if we have a phase then we are editing that phase. # # GET /plans/1/edit +=begin def edit @plan = Plan.find(params[:id]) authorize @plan @@ -192,7 +201,7 @@ respond_to :html end - +=end # PUT /plans/1 # PUT /plans/1.json @@ -201,6 +210,10 @@ authorize @plan attrs = plan_params + # Save the guidance group selections + guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i) + save_guidance_selections(guidance_group_ids) + respond_to do |format| if @plan.update_attributes(attrs) format.html { redirect_to @plan, :editing => false, notice: success_message(_('plan'), _('saved')) } @@ -213,31 +226,17 @@ end - +# TODO: Do we need this is selections are saved with rest of form? def update_guidance_choices @plan = Plan.find(params[:id]) authorize @plan guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i) - all_guidance_groups = @plan.get_guidance_group_options - plan_groups = @plan.guidance_groups - guidance_groups = GuidanceGroup.where( id: guidance_group_ids) - all_guidance_groups.each do |group| - # case where plan group exists but not in selection - if plan_groups.include?(group) && ! guidance_groups.include?(group) - # remove from plan groups - @plan.guidance_groups.delete(group) - end - # case where plan group dosent exist and in selection - if !plan_groups.include?(group) && guidance_groups.include?(group) - # add to plan groups - @plan.guidance_groups << group - end - end + save_guidance_selections(guidance_group_ids) @plan.save flash[:notice] = success_message(_('guidance choices'), _('saved')) redirect_to action: "show" end - + def share @plan = Plan.find(params[:id]) authorize @plan @@ -419,9 +418,32 @@ private def plan_params - params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title, :visibility) + params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title, :visibility, + :grant_number, :description, :identifier, :principal_investigator, + :principal_investigator_email, :principal_investigator_identifier, + :data_contact, :data_contact_email, :guidance_group_ids) end + def save_guidance_selections(guidance_group_ids) + all_guidance_groups = @plan.get_guidance_group_options + plan_groups = @plan.guidance_groups + guidance_groups = GuidanceGroup.where(id: guidance_group_ids) + all_guidance_groups.each do |group| + # case where plan group exists but not in selection + if plan_groups.include?(group) && ! guidance_groups.include?(group) + # remove from plan groups + @plan.guidance_groups.delete(group) + end + # case where plan group dosent exist and in selection + if !plan_groups.include?(group) && guidance_groups.include?(group) + # add to plan groups + @plan.guidance_groups << group + end + end + @plan.save + end + + # different versions of the same template have the same dmptemplate_id # but different version numbers so for each set of templates with the # same dmptemplate_id choose the highest version number. diff --git a/app/models/plan.rb b/app/models/plan.rb index ab84aca..6579f97 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -32,7 +32,7 @@ :exported_plans, :project, :title, :template, :grant_number, :identifier, :principal_investigator, :principal_investigator_identifier, :description, :data_contact, :funder_name, :visibility, :exported_plans, - :roles, :users, :org, :data_contact_email, :data_contact_phone, + :roles, :users, :org, :data_contact_email, :principal_investigator_email, :as => [:default, :admin] accepts_nested_attributes_for :roles diff --git a/app/views/plans/_edit_details.html.erb b/app/views/plans/_edit_details.html.erb index 6a7afd6..af39574 100644 --- a/app/views/plans/_edit_details.html.erb +++ b/app/views/plans/_edit_details.html.erb @@ -8,7 +8,7 @@ <%= f.text_field :title, class: "input-extra-large left-indent", 'data-toggle': "tooltip", 'data-content': _('If applying for funding, state the name exactly as in the grant proposal.') %>
- + /> @@ -28,8 +28,8 @@
<%= f.label _('Project Abstract'), for: :description %> - <%= text_area_tag('abstract', :description, id: "abstract", class: 'left-indent') %> - <%= tinymce(selector: "#abstract", content_css: asset_path('application.css')) %> + <%= f.text_area :description, class: "left-indent" %> + <%= tinymce(selector: "#plan_description", content_css: asset_path('application.css')) %>
Questions to consider:
  • - What is the nature of your research project?
  • - What research questions are you addressing?
  • - For what purpose are the data being collected or created?

Guidance:

Briefly summarise the type of study (or studies) to help others understand the purposes for which the data are being collected or created.

") %>" @@ -99,44 +99,54 @@

<%= _('Plan Guidance Configuration') %>

<%= _('To help you write your plan, %{application_name} can show you guidance from a variety of organisations.') % {application_name: Rails.configuration.branding[:application][:name]} %>

<%= _('Select up to 3 organisations to see their guidance.') %>

-Important - <% @important_ggs.each do |org, groups| %> -
+ +
    + <% @important_ggs.each do |org, groups| %> <% if groups && groups.size == 1 %> - <%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %> - <%= f.label org.name, for: groups[0].id, class: 'inline checkbox-label regular-text' %> - <% elsif groups %> - - - <% groups.each do |group| %> -
    - └─ - <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> - <%= f.label group.name, for: group.id %> -
    - <% end %> - <% end%> -
- <% end %> -Others - <% @all_ggs_grouped_by_org.each do |org, groups| %> -
- <% if groups && groups.size == 1 %> +
  • <%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %> - <%= f.label org.name, for: groups[0].id, class: "left-indent checkbox-label regular-text" %> + <%= f.label org.name, for: groups[0].id, class: 'inline checkbox-label regular-text' %> +
  • <% elsif groups %> +
  • - <% groups.each do |group| %> -
    - └─ - <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> - <%= f.label group.name, for: group.id, class: "left-indent checkbox-label regular-text" %> -
    - <% end %> +
  • + <% groups.each do |group| %> +
  • + └─ + <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> + <%= f.label group.name, for: group.id, class: "left-indent checkbox-label regular-text" %> +
  • + <% end %> + <% end%> + <% end %> + + +
    <%= _('See guidance from additional organisations') %> + +
    - <% end %> + <% end %> +
    <% end %> diff --git a/app/views/plans/_plan_title.html.erb b/app/views/plans/_plan_title.html.erb index 93b7c28..f445526 100644 --- a/app/views/plans/_plan_title.html.erb +++ b/app/views/plans/_plan_title.html.erb @@ -1,8 +1 @@ -

    <%= plan.title %>

    - -<% if plan.visibility == 'is_test' %> -
    - - <%= _('This is a') %> <%= _('test plan') %>. -
    -<% end %> +

    <%= plan.title %>

    \ No newline at end of file diff --git a/lib/assets/javascripts/views/plans/show.js b/lib/assets/javascripts/views/plans/show.js index 7161876..2018509 100644 --- a/lib/assets/javascripts/views/plans/show.js +++ b/lib/assets/javascripts/views/plans/show.js @@ -5,6 +5,16 @@ toggleDataContact(); }) + $("#show-other-guidance-orgs").click(function(){ + if($("#other-guidance-orgs").css('display') === 'block'){ + $("#other-guidance-orgs").hide(); + $(this).html($(this).html().replace('Hide', __('See'))); + }else{ + $("#other-guidance-orgs").show(); + $(this).html($(this).html().replace('See', __('Hide'))); + } + }); + function toggleDataContact(){ if($("#show-data-contact").is(':checked')){ $(".data-contact-info").hide(); diff --git a/lib/assets/stylesheets/dmproadmap/forms.scss b/lib/assets/stylesheets/dmproadmap/forms.scss index 2e81f91..d6bbe7e 100644 --- a/lib/assets/stylesheets/dmproadmap/forms.scss +++ b/lib/assets/stylesheets/dmproadmap/forms.scss @@ -665,6 +665,14 @@ display: inline-block; width: 35%; + h2 { + margin-top: 0; + } + + ul { + list-style: none; + } + .fa { vertical-align: top; font-size: 18px;