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