diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index acb5121..6dbe560 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -30,6 +30,7 @@ published: published, current_org: current_user.org, orgs: Org.all, + current_tab: params[:r] || 'all-templates', scopes: { all: all_templates_hash[:scopes], orgs: own_hash[:scopes], funders: customizable_hash[:scopes] } } end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 039f30a..e9d4521 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -65,7 +65,8 @@ phase: @phase, template: @phase.template, edit: @edit, - current_section: params.has_key?(:section_id) ? params[:section_id].to_i : nil + current_section: params.has_key?(:section_id) ? params[:section_id].to_i : nil, + current_tab: params[:r] || 'all-templates' }) end @@ -75,6 +76,7 @@ @phase = Phase.find(params[:id]) authorize @phase @template = @phase.template + @current_tab = params[:r] || 'all-templates' end @@ -88,7 +90,8 @@ render('/org_admin/templates/container', locals: { partial_path: 'admin_add', - template: @template + template: @template, + current_tab: params[:r] || 'all-templates' }) end @@ -100,15 +103,16 @@ @phase.description = params["phase-desc"] @phase.modifiable = true + @current_tab = params[:r] || 'all-templates' if @phase.save @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id), notice: success_message(_('phase'), _('created')) + redirect_to admin_show_phase_path(id: @phase.id, r: @current_tab), notice: success_message(_('phase'), _('created')) else flash[:alert] = failed_create_error(@phase, _('phase')) @template = @phase.template - redirect_to edit_org_admin_template_path(id: @phase.template_id) + redirect_to edit_org_admin_template_path(id: @phase.template_id, r: @current_tab) end end @@ -119,11 +123,12 @@ authorize @phase @phase.description = params["phase-desc"] + @current_tab = params[:r] || 'all-templates' if @phase.update_attributes(params[:phase]) @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(@phase), notice: success_message(_('phase'), _('saved')) + redirect_to admin_show_phase_path(@phase, r: @current_tab), notice: success_message(_('phase'), _('saved')) else @sections = @phase.sections @template = @phase.template @@ -139,7 +144,7 @@ else @original_org = @phase.template.org end - redirect_to admin_show_phase_path(@phase) + redirect_to admin_show_phase_path(@phase, r: @current_tab) end end @@ -148,11 +153,12 @@ @phase = Phase.find(params[:phase_id]) authorize @phase @template = @phase.template + @current_tab = params[:r] || 'all-templates' if @phase.destroy @template.dirty = true @template.save! - redirect_to edit_org_admin_template_path(@template), notice: success_message(_('phase'), _('deleted')) + redirect_to edit_org_admin_template_path(@template, r: @current_tab), notice: success_message(_('phase'), _('deleted')) else @sections = @phase.sections @@ -168,7 +174,7 @@ else @original_org = @phase.template.org end - render 'admin_show' + redirect_to admin_show_phase_path(@phase, r: @current_tab) end end end diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index b031a1e..44a73cb 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -8,6 +8,7 @@ @question = Question.new(question_params) authorize @question @question.modifiable = true + current_tab = params[:r] || 'all-templates' if @question.question_format.textfield? @question.default_value = params["question-default-value-textfield"] elsif @question.question_format.textarea? @@ -24,7 +25,7 @@ guidance = Annotation.new({question_id: @question.id, org_id: current_user.org_id, text: params[:guidance], type: Annotation.types[:guidance]}) guidance.save end - redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id), notice: success_message(_('question'), _('created')) + redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, r: current_tab), notice: success_message(_('question'), _('created')) else @edit = (@question.section.phase.template.org == current_user.org) @open = true @@ -40,7 +41,7 @@ else @original_org = @phase.template.org end - redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id) + redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, r: current_tab) end rescue ActionController::ParameterMissing => e flash[:alert] = e.message @@ -53,6 +54,7 @@ authorize @question guidance = @question.get_guidance_annotation(current_user.org_id) + current_tab = params[:r] || 'all-templates' if params["question-guidance-#{params[:id]}"].present? unless guidance.present? guidance = Annotation.new(type: :guidance, org_id: current_user.org_id, question_id: @question.id) @@ -87,7 +89,7 @@ @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id), notice: success_message(_('question'), _('saved')) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, r: current_tab), notice: success_message(_('question'), _('saved')) else @edit = (@phase.template.org == current_user.org) @open = true @@ -101,7 +103,7 @@ else @original_org = @phase.template.org end - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, r: current_tab) end end @@ -111,13 +113,14 @@ authorize @question @section = @question.section @phase = @section.phase + current_tab = params[:r] || 'all-templates' if @question.destroy @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id), notice: success_message(_('question'), _('deleted')) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, r: current_tab), notice: success_message(_('question'), _('deleted')) else - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id), alert: failed_destroy_error(@question, 'question') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, r: current_tab), alert: failed_destroy_error(@question, 'question') end end diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index a1c8125..e02d8a4 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -9,11 +9,12 @@ @section.description = params["section-desc"] @section.modifiable = true @phase = @section.phase + current_tab = params[:r] || 'all-templates' if @section.save @section.phase.template.dirty = true @section.phase.template.save! - redirect_to admin_show_phase_path(id: @section.phase_id, + redirect_to admin_show_phase_path(id: @section.phase_id, r: current_tab, :section_id => @section.id), notice: success_message(_('section'), _('created')) else @edit = (@phase.template.org == current_user.org) @@ -27,7 +28,7 @@ else @original_org = @phase.template.org end - redirect_to admin_show_phase_path(id: @phase.id) + redirect_to admin_show_phase_path(id: @phase.id, r: current_tab) end end @@ -38,11 +39,12 @@ authorize @section @section.description = params["section-desc"] @phase = @section.phase + current_tab = params[:r] || 'all-templates' if @section.update_attributes(params[:section]) @section.phase.template.dirty = true @section.phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id), notice: success_message(_('section'), _('saved')) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, r: current_tab), notice: success_message(_('section'), _('saved')) else @edit = (@phase.template.org == current_user.org) @open = true @@ -55,7 +57,7 @@ else @original_org = @phase.template.org end - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, r: current_tab) end end @@ -65,11 +67,11 @@ @section = Section.includes(phase: :template).find(params[:section_id]) authorize @section @phase = @section.phase - + current_tab = params[:r] || 'all-templates' if @section.destroy @phase.template.dirty = true @phase.template.save! - redirect_to admin_show_phase_path(id: @phase.id), notice: success_message(_('section'), _('deleted')) + redirect_to admin_show_phase_path(id: @phase.id, r: current_tab), notice: success_message(_('section'), _('deleted')) else @edit = (@phase.template.org == current_user.org) @open = true @@ -83,7 +85,7 @@ else @original_org = @phase.template.org end - redirect_to(admin_show_phase_path(id: @phase.id)) + redirect_to(admin_show_phase_path(id: @phase.id, r: current_tab)) end end diff --git a/app/views/org_admin/templates/_admin_nav_tabs.html.erb b/app/views/org_admin/templates/_admin_nav_tabs.html.erb index 70dd9d1..23246f1 100644 --- a/app/views/org_admin/templates/_admin_nav_tabs.html.erb +++ b/app/views/org_admin/templates/_admin_nav_tabs.html.erb @@ -1,17 +1,17 @@ diff --git a/app/views/org_admin/templates/index.html.erb b/app/views/org_admin/templates/index.html.erb index 4cb0ca6..7731189 100644 --- a/app/views/org_admin/templates/index.html.erb +++ b/app/views/org_admin/templates/index.html.erb @@ -1,4 +1,4 @@ -<% # locals: funder_templates, org_templates, current_user, current_org, orgs %> +<% # locals: funder_templates, org_templates, current_user, current_org, orgs, current_tab %>

<%= _('Templates') %>

@@ -24,16 +24,16 @@
diff --git a/app/views/phases/_edit_phase.html.erb b/app/views/phases/_edit_phase.html.erb index 03c4811..ec55c1f 100644 --- a/app/views/phases/_edit_phase.html.erb +++ b/app/views/phases/_edit_phase.html.erb @@ -1,4 +1,4 @@ -<%= form_for :phase, { url: admin_update_phase_path(phase.id), html: { method: :put }} do |f| %> +<%= form_for :phase, { url: admin_update_phase_path(phase.id, r: current_tab), html: { method: :put }} do |f| %>
<%= f.label(:title, _('Title') ,class: "control-label") %> <%= f.text_field(:title, class: "form-control", 'aria-required': false, 'data-toggle': 'tooltip', title: _('Enter a title for the phase e.g. intial DMP, full DMP... This is what users will see in the tabs when completing a plan. If you only have one phase, call it something generic e.g. Glasgow DMP')) %> diff --git a/app/views/phases/_show_phase.html.erb b/app/views/phases/_show_phase.html.erb index 6b8d0f2..325a3b5 100644 --- a/app/views/phases/_show_phase.html.erb +++ b/app/views/phases/_show_phase.html.erb @@ -10,7 +10,7 @@
  • <%= link_to(_('Edit phase details'), '#', { class: "btn btn-default phase_edit_link", role: "button" }) %>
  • -
  • <%= link_to(_('Preview'), admin_preview_phase_path(phase), { class: 'btn btn-default phase_preview_link', role: 'button' }) %>
  • +
  • <%= link_to(_('Preview'), admin_preview_phase_path(phase, r: current_tab), { class: 'btn btn-default phase_preview_link', role: 'button' }) %>
<% end %> diff --git a/app/views/phases/admin_preview.html.erb b/app/views/phases/admin_preview.html.erb index c0fb015..bde064b 100644 --- a/app/views/phases/admin_preview.html.erb +++ b/app/views/phases/admin_preview.html.erb @@ -3,8 +3,8 @@

<%= @template.title %>

    -
  • <%= link_to _('Back to edit phase'), admin_show_phase_path(id: @phase.id), class: 'btn btn-primary' %>
  • -
  • <%= link_to _('View all templates'), org_admin_templates_path, class: 'btn btn-primary' %>
  • +
  • <%= link_to _('Back to edit phase'), admin_show_phase_path(id: @phase.id, r: @current_tab), class: 'btn btn-primary' %>
  • +
  • <%= link_to _('View all templates'), org_admin_templates_path(r: @current_tab), class: 'btn btn-primary' %>
@@ -12,7 +12,7 @@
- <%= render partial: "/org_admin/templates/admin_nav_tabs", locals: { template: @template, active: @phase.id } %> + <%= render partial: "/org_admin/templates/admin_nav_tabs", locals: { template: @template, active: @phase.id, current_tab: @current_tab } %>
diff --git a/app/views/questions/_add_question.html.erb b/app/views/questions/_add_question.html.erb index 5942b39..72045fa 100644 --- a/app/views/questions/_add_question.html.erb +++ b/app/views/questions/_add_question.html.erb @@ -7,7 +7,7 @@ --> <% @new_question = Question.new %> <% @new_question.number = section.questions.count + 1 %> -<%= form_for @new_question, url: admin_create_question_path , html: {id: "new_question_#{section.id}", class: 'question_form'} do |f| %> +<%= form_for @new_question, url: admin_create_question_path(r: current_tab) , html: {id: "new_question_#{section.id}", class: 'question_form'} do |f| %> <%= f.hidden_field :section_id, value: section.id %> <%= hidden_field_tag :section_id, section.id, class: "section_id_new" %> diff --git a/app/views/questions/_edit_question.html.erb b/app/views/questions/_edit_question.html.erb index bbddf14..7d354f9 100644 --- a/app/views/questions/_edit_question.html.erb +++ b/app/views/questions/_edit_question.html.erb @@ -9,7 +9,7 @@
- <%= form_for(question, url: admin_update_question_path(question), html: { method: :put, class: 'question_form' }) do |f| %> + <%= form_for(question, url: admin_update_question_path(question, r: current_tab), html: { method: :put, class: 'question_form' }) do |f| %> <%= f.hidden_field :id,{ class: "quest_id" } %> <%= hidden_field_tag :question_id, question.id, class: "question_id" %> @@ -95,7 +95,7 @@
<%= f.submit _('Save'), class: "btn btn-default", role:'button' %> <% if !question.section.phase.template.published? %> - <%= link_to _('Delete'), admin_destroy_question_path(question_id: question.id), + <%= link_to _('Delete'), admin_destroy_question_path(question_id: question.id, r: current_tab), confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-default", role:'button'%> <% end %> <%= link_to _('Cancel'), '#', class: "btn btn-default edit_question_cancel", role: 'button' %> diff --git a/app/views/questions/_show_question.html.erb b/app/views/questions/_show_question.html.erb index f53382e..5e713d5 100644 --- a/app/views/questions/_show_question.html.erb +++ b/app/views/questions/_show_question.html.erb @@ -91,7 +91,7 @@
<% if (question.modifiable) %> <%= link_to _('Edit question'), "#question_edit#{question.id}", class: "btn btn-default question_edit_link", role: "button" %> - <%= link_to _('Delete question'), admin_destroy_question_path(question_id: question.id), + <%= link_to _('Delete question'), admin_destroy_question_path(question_id: question.id, r: current_tab), confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-default", role:"button" %> <% end %>
diff --git a/app/views/sections/_add_section.html.erb b/app/views/sections/_add_section.html.erb index 3bfa3fc..d64c5a2 100644 --- a/app/views/sections/_add_section.html.erb +++ b/app/views/sections/_add_section.html.erb @@ -1,7 +1,7 @@ <% new_section = Section.new %> <% new_section.number = phase.sections.count + 1 %> -<%= form_for new_section, { url: admin_create_section_path, html: { class: 'form-horizontal' }} do |f| %> +<%= form_for new_section, { url: admin_create_section_path(r: current_tab), html: { class: 'form-horizontal' }} do |f| %> <%= f.hidden_field :phase_id, value: phase.id %>
diff --git a/app/views/sections/_edit_section.html.erb b/app/views/sections/_edit_section.html.erb index 1e638a1..6e677cc 100644 --- a/app/views/sections/_edit_section.html.erb +++ b/app/views/sections/_edit_section.html.erb @@ -5,7 +5,7 @@
- <%= form_for(section, url: admin_update_section_path(section, phase: phase), html: { method: :put }) do |f| %> + <%= form_for(section, url: admin_update_section_path(section, phase: phase, r: current_tab), html: { method: :put }) do |f| %>
<%= f.label(:title, _('Title') ,class: "control-label") %> <%= f.text_field(:title, { class: "form-control", 'aria-required': false, placeholder: _('Enter a title for the section'), 'data-toggle': 'tooltip', title: _('Enter a title for the section')} ) %> @@ -30,7 +30,7 @@
<%= f.button(_('Save'), class: 'btn btn-default', type: "submit") %> - <%= link_to _('Delete'), admin_destroy_section_path(section_id: section.id), 'data-method': 'delete', rel: 'nofollow', + <%= link_to _('Delete'), admin_destroy_section_path(section_id: section.id, r: current_tab), 'data-method': 'delete', rel: 'nofollow', 'data-confirm': _("You are about to delete '%{section_title}'. This will affect questions linked to this section. Are you sure?") % { :section_title => section.title }, class: 'btn btn-default', role:'button' %> <%= link_to _('Cancel'), admin_show_phase_path(section.phase), class: 'btn btn-default', role: 'button' %>
@@ -44,10 +44,10 @@ <% questions.each do |question| %>
"> - <%= render partial: 'questions/show_question', locals: {template: template, question: question} %> + <%= render partial: 'questions/show_question', locals: {template: template, question: question, current_tab: current_tab} %>
" style="display: none;"> - <%= render partial: 'questions/edit_question', locals: {template: template, question: question} %> + <%= render partial: 'questions/edit_question', locals: {template: template, question: question, current_tab: current_tab} %>
<%= raw("
") if questions.last.id == question.id %> <% end %> @@ -60,7 +60,7 @@ <%= link_to(_('Add Question'), '#', { class: 'btn btn-default question_new_link', role: "button" }) %>
diff --git a/app/views/sections/_show_section.html.erb b/app/views/sections/_show_section.html.erb index c8f14c0..557d968 100644 --- a/app/views/sections/_show_section.html.erb +++ b/app/views/sections/_show_section.html.erb @@ -13,11 +13,11 @@ <% questions.each do |question| %>
"> - <%= render partial: 'questions/show_question', locals: {template: template, question: question} %> + <%= render partial: 'questions/show_question', locals: {template: template, question: question, current_tab: current_tab} %>
<% if question.modifiable %>
" style="display: none;"> - <%= render partial: 'questions/edit_question', locals: {template: template, question: question} %> + <%= render partial: 'questions/edit_question', locals: {template: template, question: question, current_tab: current_tab} %>
<% end %> <% if questions.last.id != question.id %> diff --git a/test/functional/phases_controller_test.rb b/test/functional/phases_controller_test.rb index c0648d3..a7571b0 100644 --- a/test/functional/phases_controller_test.rb +++ b/test/functional/phases_controller_test.rb @@ -154,7 +154,7 @@ post admin_create_phase_path(@template.phases.first), {phase: params} assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_response :redirect - assert_redirected_to admin_show_phase_path(id: Phase.last.id) + assert_redirected_to admin_show_phase_path(id: Phase.last.id, r: 'all-templates') assert assigns(:phase) assert_equal 'Phase: Tester 2', Phase.last.title, "expected the record to have been created!" @@ -187,7 +187,7 @@ put admin_update_phase_path(@template.phases.first), {phase: params} assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect - assert_redirected_to admin_show_phase_url(@template.phases.first) + assert_redirected_to admin_show_phase_url(@template.phases.first, r: 'all-templates') assert assigns(:phase) assert_equal 'Phase - UPDATE', @template.phases.first.title, "expected the record to have been updated" @@ -221,7 +221,7 @@ delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: id) assert_response :redirect - assert_redirected_to edit_org_admin_template_path(@template) + assert_redirected_to edit_org_admin_template_path(@template, r: 'all-templates') assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Phase.find(id).nil? diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index 4f30352..bbe42f4 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -56,7 +56,7 @@ post admin_create_question_path(@section), {question: params} assert_response :redirect assert assigns(:question) - assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id, question_id: Question.last.id) + assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id, question_id: Question.last.id, r: 'all-templates') assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal 'Test Question', Question.last.text, "expected the record to have been created!" @@ -94,7 +94,7 @@ put admin_update_question_path(@section.questions.first), {question: params} assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect - assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id, question_id: @section.questions.first.id) + assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id, question_id: @section.questions.first.id, r: 'all-templates') assert assigns(:phase) assert assigns(:section) assert assigns(:question) @@ -136,7 +136,7 @@ assert assigns(:phase) assert assigns(:section) assert assigns(:question) - assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id) + assert_redirected_to admin_show_phase_url(id: @section.phase.id, section_id: @section.id, r: 'all-templates') assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Question.find(id).nil? diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index 7e17fb4..5ee66de 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -50,7 +50,7 @@ post admin_create_section_path(@phase), {section: params} assert_response :redirect - assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: Section.last.id) + assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: Section.last.id, r: 'all-templates') assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal 'Section Tester', Section.last.title, "expected the record to have been created!" @@ -86,7 +86,7 @@ put admin_update_section_path(@phase.sections.first), {section: params} assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect - assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: @phase.sections.first.id) + assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: @phase.sections.first.id, r: 'all-templates') assert_equal 'Phase - UPDATE', @phase.sections.first.title, "expected the record to have been updated" # Make sure that the template's dirty flag got set @@ -122,7 +122,7 @@ assert_response :redirect assert assigns(:section) assert assigns(:phase) - assert_redirected_to admin_show_phase_url(id: @phase.id) + assert_redirected_to admin_show_phase_url(id: @phase.id, r: 'all-templates') assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Section.find(id).nil?