diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index a693330..82e3156 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -37,37 +37,38 @@ @plan.data_contact = current_user.email @plan.funder_name = plan_params[:funder_name] - if plan_params[:title].blank? - @plan.title = current_user.firstname.blank? ? _('My Plan') : - current_user.firstname + "'s" + _(" Plan") - else - @plan.title = plan_params[:title] - end - # If a template hasn't been identified look for the available templates if plan_params[:template_id].blank? template_options(plan_params[:org_id], plan_params[:funder_id]) -puts "TEMPLATES: #{@templates.collect{|t| t.id }.join(', ')}" - # Return the 'Select a template' section respond_to do |format| format.js {} end - # Otherwise create the plan else @plan.template = Template.find(plan_params[:template_id]) - -puts "CREATING" -puts @plan.inspect - -=begin + + if plan_params[:title].blank? + @plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' : + current_user.firstname + "'s" + _(" Plan") + else + @plan.title = plan_params[:title] + end + if @plan.save @plan.assign_creator(current_user) - flash[:notice] = _('Plan was successfully created.') + default = Template.find_by(is_default: true) + + if !default.nil? && default == @plan.template + flash[:notice] = _('Plan was successfully created.') + '
' + + _('The funder you selected does not have an official Data Management Plan. We have provided you with the generic plan.') + else + flash[:notice] = _('Plan was successfully created.') + end + respond_to do |format| format.js { render js: "window.location='#{plan_url(@plan)}'" } end @@ -79,7 +80,6 @@ format.js {} end end -=end end end @@ -424,7 +424,7 @@ # Collect all of the templates available for the org+funder combination # -------------------------------------------------------------------------- def template_options(org_id, funder_id) - templates = [] + @templates = [] if !org_id.blank? || !funder_id.blank? if funder_id.blank? @@ -463,7 +463,7 @@ @templates << Template.find_by(is_default: true) end - @templates = templates.sort{|x,y| x.title <=> y.title } if templates.count > 1 + @templates = @templates.sort{|x,y| x.title <=> y.title } if @templates.count > 1 end end diff --git a/app/views/plans/_available_templates.html.erb b/app/views/plans/_available_templates.html.erb index df96337..72c8089 100644 --- a/app/views/plans/_available_templates.html.erb +++ b/app/views/plans/_available_templates.html.erb @@ -1,16 +1,18 @@

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

- - <%= _('We found multiple DMP templates corresponding to your funder.') %> - +
+ <%= _('We found multiple DMP templates corresponding to your funder.') %> +
+