diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 83c119f..6cba2fb 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -9,6 +9,10 @@ authorize Plan @plans = Plan.active(current_user).page(1) @organisationally_or_publicly_visible = Plan.organisationally_or_publicly_visible(current_user).page(1) + + if params[:plan].present? + @template = Template.find(params[:plan][:template_id]) + end end # GET /plans/new @@ -153,18 +157,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 +176,7 @@ guidance_groups: guidance_groups, answers: answers }) end - + # PUT /plans/1 # PUT /plans/1.json def update @@ -186,7 +190,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 +199,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" } diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index bfe0888..3ed80ea 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -6,15 +6,17 @@ a.join(separator) end - def direct_link(template, hidden = false) - params = { - org_id: template.org.id, - funder_id: '-1', - template_id: template.id, - } + def direct_link(template, hidden = false, text = nil) + params = { org_id: template.org.id, funder_id: '-1', template_id: template.id } + cls = text.nil? ? 'direct-link' : 'direct-link btn btn-default' + style = hidden ? 'display: none' : '' - link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: 'direct-link', style: hidden ? 'display: none' : '') do - ''.html_safe + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, style: style) do + if text.nil? + ''.html_safe + else + text.html_safe + end end end end diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index 862d276..e8e9397 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -1,6 +1,6 @@ <% title _('My Dashboard') %>
-
+

<%= _('My Dashboard') %>

@@ -19,7 +19,7 @@ <%= paginable_renderise( partial: '/paginable/plans/privately_visible', controller: 'paginable/plans', - action: 'privately_visible', + action: 'privately_visible', scope: @plans, query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>

@@ -43,3 +43,5 @@ <% end %>
+ +<%= render 'shared/create_plan_modal' unless @template.nil? %> diff --git a/app/views/shared/_copy_link_modal.html.erb b/app/views/shared/_copy_link_modal.html.erb index 5f62bfc..c9c8d07 100644 --- a/app/views/shared/_copy_link_modal.html.erb +++ b/app/views/shared/_copy_link_modal.html.erb @@ -10,7 +10,7 @@ diff --git a/app/views/shared/_create_plan_modal.html.erb b/app/views/shared/_create_plan_modal.html.erb new file mode 100644 index 0000000..6523ae4 --- /dev/null +++ b/app/views/shared/_create_plan_modal.html.erb @@ -0,0 +1,15 @@ + diff --git a/lib/assets/javascripts/views/plans/index.js b/lib/assets/javascripts/views/plans/index.js index b030b67..b3cd74c 100644 --- a/lib/assets/javascripts/views/plans/index.js +++ b/lib/assets/javascripts/views/plans/index.js @@ -26,4 +26,6 @@ $(paginableSelector).on('ajax:error', '.set_test_plan', () => { // TODO adequate error handling for network error }); + + $('#create-modal').modal('show'); });