diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 31aebae..385493e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -105,8 +105,8 @@ #preview a phase def admin_previewphase - @version = Version.find(params[:id]) - authorize @version.phase.dmptemplate + @template = Template.find(params[:id]) + authorize @template end @@ -138,16 +138,14 @@ @phase = Phase.find(params[:id]) authorize @phase.template @phase.description = params["phase-desc"] - respond_to do |format| - if @phase.update_attributes(params[:phase]) - format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + if @phase.update_attributes(params[:phase]) + redirect_to admin_phase_template_path(@phase), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end - #delete a version, sections and questions + #delete a phase def admin_destroyphase @phase = Phase.find(params[:phase_id]) authorize @phase.template @@ -160,14 +158,13 @@ #create a section def admin_createsection @section = Section.new(params[:section]) - authorize @section.version.phase.dmptemplate + authorize @section.phase.template @section.description = params["section-desc"] - respond_to do |format| - if @section.save - format.html { redirect_to admin_phase_template_path(:id => @section.version.phase_id, :version_id => @section.version_id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + if @section.save + redirect_to admin_phase_template_path(id: @section.phase_id, + :section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" end end @@ -205,7 +202,7 @@ @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] if @question.save - redirect_to admin_phase_template_path(id: @question.section.version.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_phase_template_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') else render action: "admin_phase" end @@ -214,32 +211,26 @@ #update a question of a template def admin_updatequestion @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate + authorize @question.section.phase.template @question.guidance = params["question-guidance-#{params[:id]}"] @question.default_value = params["question-default-value-#{params[:id]}"] @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + @phase = @section.phase + if @question.update_attributes(params[:question]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end - #delete a version, sections and questions + #delete question def admin_destroyquestion @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate + authorize @question.section.phase.template @section = @question.section - @version = @section.version - @phase = @version.phase + @phase = @section.phase @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') end @@ -247,13 +238,11 @@ #create suggested answers def admin_createsuggestedanswer @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate - respond_to do |format| - if @suggested_answer.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @suggested_answer.question.section.version.phase_id, :version_id => @suggested_answer.question.section.version_id, :section_id => @suggested_answer.question.section_id, :question_id => @suggested_answer.question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + authorize @suggested_answer.question.section.phase.template + if @suggested_answer.save + redirect_to admin_phase_template_path(id: @suggested_answer.question.section.phase_id, section_id: @suggested_answer.question.section_id, question_id: @suggested_answer.question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" end end @@ -261,84 +250,26 @@ #update a suggested answer of a template def admin_updatesuggestedanswer @suggested_answer = SuggestedAnswer.find(params[:id]) - authorize @suggested_answer.question.section.version.phase.dmptemplate + authorize @suggested_answer.question.section.phase.template @question = @suggested_answer.question @section = @question.section - @version = @section.version - @phase = @version.phase - - respond_to do |format| - if @suggested_answer.update_attributes(params[:suggested_answer]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + @phase = @section.phase + if @suggested_answer.update_attributes(params[:suggested_answer]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end #delete a suggested answer def admin_destroysuggestedanswer @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate + authorize @suggested_answer.question.section.phase.template @question = @suggested_answer.question @section = @question.section - @version = @section.version - @phase = @version.phase + @phase = @section.phase @suggested_answer.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') end -# GUIDANCES - - #create a guidance - def admin_createguidance - @question = Question.find(params[:question][:id]) - authorize @question.section.version.phase.dmptemplate - @guidance = Guidance.new(params[:guidance]) - @guidance.question_id = @question.id - #@question.guidance = params["new-question-guidance"] - #@question.default_value = params["new-question-default-value"] - respond_to do |format| - if @guidance.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #update a guidance of a template - def admin_updateguidance - @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #delete a version, sections and guidance - def admin_destroyguidance - @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase - @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - - end \ No newline at end of file diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index b7a2ad0..34524ab 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -5,7 +5,7 @@ belongs_to :org has_many :guidances # depricated but needed for migration "single_group_for_guidance" - has_and_belongs_to_many :guidances, join_table: "guidance_in_group" + # has_and_belongs_to_many :guidances, join_table: "guidance_in_group" ## # Possibly needed for active_admin diff --git a/app/models/question.rb b/app/models/question.rb index 8b162a9..d6ec73e 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -20,7 +20,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :suggested_answer, :text, :section_id, :question_format_id, :question_options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] @@ -92,26 +92,19 @@ # @param question [Question] the question to find guidance for # @param org_admin [Organisation] the organisation to find guidance for # @return [Hash{String => String}] - def guidance_for_question(question, org_admin) - # pulls together guidance from various sources for question - guidances = {} - theme_ids = question.theme_ids + def guidance_for_question(question, org) + # pulls together guidance from various sources for question + guidances = {} + theme_ids = question.theme_ids - GuidanceGroup.where("organisation_id = ?", org_admin.id).each do |group| - group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g - end - end + GuidanceGroup.where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.where("id IN (?)", theme_ids).each do |gg| + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g end - # Guidance link to directly to a question - question.guidances.each do |g_by_q| - g_by_q.guidance_groups.each do |group| - if group.organisation == org_admin - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase')] = g_by_q - end - end - end + end + end + return guidances end @@ -121,7 +114,7 @@ # @param org_id [Integer] the id for the organisation # @return [String] the suggested_answer for this question for the specified organisation def get_suggested_answer(org_id) - suggested_answer = suggested_answers.find_by_organisation_id(org_id) + suggested_answer = suggested_answers.find_by(org_id: org_id) return suggested_answer end diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 3e62265..b4df355 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -8,7 +8,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] + attr_accessible :org_id, :question_id, :text, :is_example, :as => [:default, :admin] # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/user.rb b/app/models/user.rb index f7e35b3..4a915eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -201,7 +201,7 @@ # # @return [String] the organisation type def org_type - org_type = organisation.organisation_type.name + org_type = org.organisation_type return org_type end diff --git a/app/views/templates/_add_suggested_answer.html.erb b/app/views/templates/_add_suggested_answer.html.erb index 03e11b7..8969086 100644 --- a/app/views/templates/_add_suggested_answer.html.erb +++ b/app/views/templates/_add_suggested_answer.html.erb @@ -1,25 +1,25 @@ -<%= form_for :suggested_answer, :url => {:action => "admin_createsuggestedanswer"} do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> - <%= f.hidden_field :question_id, :value => question.id %> - - - - - - -
<%= t("org_admin.questions.suggested_or_example_answer_label")%> -
    -
  • <%= f.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
  • -
  • <%= f.text_area :text, :rows => 5 %> -
  • -
-
-
- - -
- <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), "#", :id => "cancel_suugested_answer", :class => "btn cancel" %> -
+<%= form_for :suggested_answer, url: {action: "admin_createsuggestedanswer"} do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> + <%= f.hidden_field :question_id, value: question.id %> + + + + + + +
<%= t("org_admin.questions.suggested_or_example_answer_label")%> +
    +
  • <%= f.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
  • +
  • <%= f.text_area :text, rows: 5 %> +
  • +
+
+
+ + +
+ <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), "#", id: "cancel_suugested_answer", class: "btn cancel" %> +
<%end%> diff --git a/app/views/templates/_edit_question.html.erb b/app/views/templates/_edit_question.html.erb index ab12c02..9f93a84 100644 --- a/app/views/templates/_edit_question.html.erb +++ b/app/views/templates/_edit_question.html.erb @@ -6,169 +6,169 @@ **Copyright: Digital Curation Centre and University of California Curation Center --> -<%= form_for(question, :url => admin_updatequestion_dmptemplate_path(question), :html => { :method => :put}) do |f| %> +<%= form_for(question, url: admin_updatequestion_template_path(question), html: { method: :put}) do |f| %>
- - - - - - +
<%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, :in => 1..50, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> -
-
+ + + + + - - - - - + + + + + - - - - + + +
<%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> +
+
<%= t("org_admin.questions.question_text_label")%><%= f.text_area :text, :rows => "5" %> -
-
<%= t("org_admin.questions.question_text_label")%><%= f.text_area :text, rows: "5" %> +
+
<%= t("org_admin.questions.answer_format_label")%>
-
- <%= f.hidden_field :id,{ :class => "quest_id" } %> - <%= f.select :question_format_id, - options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id), - {}, :id => "#{question.id}-select-format"%> -
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_format_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%> -
+ +
<%= t("org_admin.questions.answer_format_label")%>
+
+ <%= f.hidden_field :id,{ class: "quest_id" } %> + <%= f.select :question_format_id, + options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id), + {}, id: "#{question.id}-select-format"%> +
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_format_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%> +
-
+ - -
+ + <%= t("org_admin.add_option_label") %>
- <%= f.check_box :option_comment_display, :as => :check_boxes%><%= f.label t("org_admin.questions.option_comment_display_checkbox"), :class => "checkbox inline"%> -
-
- - -
- - -
- -
-
-
- - + <%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label t("org_admin.questions.option_comment_display_checkbox"), class: "checkbox inline"%> + +
+ + +
+ + +
+ +
+
+
+ + - - - <%= t("org_admin.questions.suggested_or_example_answer_label")%> -
- <% suggested_answer = question.suggested_answers.find_by_organisation_id(current_user.organisation.id) %> - <% if suggested_answer.nil? then %> - <% suggested_answer = question.suggested_answers.build %> - <%end%> - <%= f.fields_for :suggested_answers, suggested_answer do |s|%> - <%= s.hidden_field :organisation_id, :value => current_user.organisation.id %> - - <%end%> -
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "suggested_answer_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%> -
-
-
- - - - - <%= t("org_admin.questions.guidance_label")%> -
- <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %> -
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_guidance_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%> -
-
-
- - - - - <%= t("org_admin.questions.themes_label")%> -
- <%= f.collection_select(:theme_ids, - Theme.all.order("title"), - :id, :title, {:prompt => false, :include_blank => "None"}, {:multiple => true})%> -
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_themes_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%> -
- - - -
- -
- <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <% if !question.section.version.published? then%> - <%= link_to t("helpers.submit.delete"), admin_destroyquestion_dmptemplate_path(:question_id => question.id), - :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%end%> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("helpers.submit.cancel"), "#", :class => "btn cancel cancel_edit_question" %> -
- + + + <%= t("org_admin.questions.suggested_or_example_answer_label")%> +
+ <% suggested_answer = question.suggested_answers.find_by_org_id(current_user.org.id) %> + <% if suggested_answer.nil? %> + <% suggested_answer = question.suggested_answers.build %> + <% end %> + <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= s.hidden_field :org_id, value: current_user.org.id %> + + <% end %> +
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "suggested_answer_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%> +
+
+
+ + + + + <%= t("org_admin.questions.guidance_label")%> +
+ <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %> +
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_guidance_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%> +
+
+
+ + + + + <%= t("org_admin.questions.themes_label")%> +
+ <%= f.collection_select(:theme_ids, + Theme.all.order("title"), + :id, :title, {prompt: false, include_blank: "None"}, {multiple: true})%> +
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_themes_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%> +
+ + + +
+ +
+ <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <% if !question.section.phase.template.published?%> + <%= link_to t("helpers.submit.delete"), admin_destroyquestion_template_path(question_id: question.id), + confirm: t("org_admin.questions.delete_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("helpers.submit.cancel"), "#", class: "btn cancel cancel_edit_question" %> +
+ -<%= render :partial => "guidance_display", locals: {question: question}%> -<%end%> +<%= render partial: "guidance_display", locals: {question: question}%> +<% end %> diff --git a/app/views/templates/_edit_suggested_answer.html.erb b/app/views/templates/_edit_suggested_answer.html.erb index 2f78934..8e1b496 100644 --- a/app/views/templates/_edit_suggested_answer.html.erb +++ b/app/views/templates/_edit_suggested_answer.html.erb @@ -1,26 +1,26 @@ -<%= form_for(suggested_answer, :url => admin_updatesuggestedanswer_dmptemplate_path(suggested_answer), :html => { :method => :put}) do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> +<%= form_for(suggested_answer, url: admin_updatesuggestedanswer_template_path(suggested_answer), html: { method: :put}) do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> - - - - - -
<%= t('org_admin.questions.suggested_or_example_answer_label')%> -
    -
  • <%= f.select :is_example, {t('org_admin.questions.example_answer_label') => true, t('org_admin.questions.suggested_answer_label') => false} %>
  • -
  • <%= f.text_area :text, :rows => 5 %>
  • -
-
-
+ + + + + +
<%= t('org_admin.questions.suggested_or_example_answer_label')%> +
    +
  • <%= f.select :is_example, {t('org_admin.questions.example_answer_label') => true, t('org_admin.questions.suggested_answer_label') => false} %>
  • +
  • <%= f.text_area :text, rows: 5 %>
  • +
+
+
- -
- <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_dmptemplate_path(:suggested_answer => suggested_answer.id), - :confirm => t("org_admin.questions.delete_suggested_answer_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t('helpers.submit.cancel'), '#', :class => 'btn cancel cancel_edit_suggested_answer' %> -
+ +
+ <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_template_path(suggested_answer: suggested_answer.id), + confirm: t("org_admin.questions.delete_suggested_answer_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t('helpers.submit.cancel'), '#', class: 'btn cancel cancel_edit_suggested_answer' %> +
<%end%> diff --git a/app/views/templates/_guidance_display.html.erb b/app/views/templates/_guidance_display.html.erb index 4082baf..d0276d9 100644 --- a/app/views/templates/_guidance_display.html.erb +++ b/app/views/templates/_guidance_display.html.erb @@ -1,36 +1,36 @@
-
- <% if !question.guidance.nil? && question.guidance != "" then %> - - <% end %> - - <% question.guidance_for_question(question, current_user.organisation).each_pair do |title,guidance| %> -
- -
-
<%= raw guidance.text %>
-
-
- <% end %> -
- -
\ No newline at end of file +
+ <% if !question.guidance.nil? && question.guidance != "" then %> +
+ +
+
<%= raw question.guidance %>
+
+
+ <% end %> + + <% question.guidance_for_question(question, current_user.org).each_pair do |title,guidance| %> +
+ +
+
<%= raw guidance.text %>
+
+
+ <% end %> +
+ + \ No newline at end of file diff --git a/app/views/templates/_show_question.html.erb b/app/views/templates/_show_question.html.erb index df79c2b..6ac50fc 100644 --- a/app/views/templates/_show_question.html.erb +++ b/app/views/templates/_show_question.html.erb @@ -1,151 +1,151 @@ -
- - - - - - +
<%= t('org_admin.questions.question_number_label')%><%= question.number%>
+ + + + + - - - - - - - <%if q_format.title == t("helpers.text_field") || q_format.title == t("helpers.text_area") then %> - <%if !question.default_value.nil? then %> - - - - - <%end%> - <% end %> - - - - - + + + + + + + <% if q_format.title == t("helpers.text_field") || q_format.title == t("helpers.text_area") %> + <% if !question.default_value.nil? %> + + + + + <% end %> + <% end %> + + + + + - - <% if (question.section.version.phase.dmptemplate.org_type != constant("organisation_types.funder") && question.section.organisation_id == current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> - - - - - <%end%> - <%end%> - - <%if !question.guidance.nil? then %> - - - - - <%end%> - - <% themes_q = question.themes %> - <%if !themes_q.nil? then%> - - - - - <%end%> -
<%= t('org_admin.questions.question_number_label')%><%= question.number %>
<%= t('org_admin.questions.question_text_label')%><%= raw question.text %> -
-
- <% q_format = question.question_format %> - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> -
    - <% if question.options.is_a? Option then %> -
  • - <%= question.options.text %>
  • - <% else %> - <% if !question.options.to_a.nil? then %> - <% question.options.to_a.sort_by{|op| op['number']}.each do |o| %> -
  • - <%= o.text %>
  • - <%end%> - <% end %> - <% end %> -
- <% end %> -
-
<%= t('org_admin.questions.default_value_label')%><%= raw question.default_value %>
<%= t('org_admin.questions.answer_format_label')%><%= q_format.title %> -
- <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> - <% if question.option_comment_display == true then%> - <%= t("org_admin.questions.option_comment_display")%> - <%else%> - <%= t("org_admin.questions.option_comment_hide")%> - <%end%> - <%end%> -
-
<%= t('org_admin.questions.question_text_label')%><%= raw question.text %> +
+
+ <% q_format = question.question_format %> + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> +
    + <% if question.question_options.is_a? QuestionOption %> +
  • - <%= question.question_options.text %>
  • + <% else %> + <% if !question.question_options.to_a.nil? %> + <% question.question_options.to_a.sort_by{|op| op['number']}.each do |o| %> +
  • - <%= o.text %>
  • + <% end %> + <% end %> + <% end %> +
+ <% end %> +
+
<%= t('org_admin.questions.default_value_label')%><%= raw question.default_value %>
<%= t('org_admin.questions.answer_format_label')%><%= q_format.title %> +
+ <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> + <% if question.question_option_comment_display == true %> + <%= t("org_admin.questions.option_comment_display")%> + <% else %> + <%= t("org_admin.questions.option_comment_hide")%> + <% end %> + <% end %> +
+
- <% if suggested_answer.is_example? then %> - <%= t('org_admin.questions.example_answer_label')%> - <%else%> - <%= t('org_admin.questions.suggested_answer_label')%> - <%end%> - <%= raw suggested_answer.text %>
<%= t('org_admin.questions.guidance_label')%><%= raw question.guidance %>
<%= t('org_admin.questions.themes_label')%><% i = 1%> - <% themes_q.each do |t|%> - <%= t.title %> - <% if themes_q.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> -
-
- - <% if (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id != current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> -
- <%= render :partial => 'show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> -
- + + <% if question.section.phase.template.org_type != constant("organisation_types.funder") %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> + + + <% if suggested_answer.is_example? %> + <%= t('org_admin.questions.example_answer_label')%> + <% else %> + <%= t('org_admin.questions.suggested_answer_label')%> + <% end %> + + <%= raw suggested_answer.text %> + + <% end %> + <% end %> + + <% if !question.guidance.nil? %> + + <%= t('org_admin.questions.guidance_label')%> + <%= raw question.guidance %> + + <% end %> + + <% themes_q = question.themes %> + <% if !themes_q.nil? %> + + <%= t('org_admin.questions.themes_label')%> + <% i = 1%> + <% themes_q.each do |t|%> + <%= t.title %> + <% if themes_q.count > i %> + , + <% i +=1 %> + <% end %> + <% end %> + + + <% end %> + +
+ + <% if !question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> +
+ <%= render :partial => 'show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> +
+ - <%end%> + <% end %> - + - <%end%> + <% end %> -
- - <%if (@edit == 'true'&& question.section.organisation_id == current_user.organisation_id) || (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id == current_user.organisation_id && current_user.org_type != constant("organisation_types.funder")) then%> -
- <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("org_admin.questions.question_edit_button"), '# ', :class => "btn btn-primary edit_question_button"%> - <% if !question.section.version.published? then%> - <%= link_to t("org_admin.questions.question_delete_button"), admin_destroyquestion_dmptemplate_path(:question_id => question.id), - :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%end%> -
- <%elsif (@edit == 'false' && question.section.organisation_id != current_user.organisation_id )|| (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id != current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if suggested_answer.nil? then %> -
-
- <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("org_admin.questions.suggested_or_example_answer_button"), '# ', :class => "btn btn-primary add_suggested_answer_button"%> -
-
- <%end%> - <%end%> -
+
+ + <% if (@edit == 'true' && question.modifiable) %> +
+ <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> + <%= link_to t("org_admin.questions.question_edit_button"), '# ', :class => "btn btn-primary edit_question_button"%> + <% if !question.section.published? %> + <%= link_to t("org_admin.questions.question_delete_button"), admin_destroyquestion_template_path(:question_id => question.id), + :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> + <% end %> +
+ <% elsif @edit == 'false' && question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if suggested_answer.nil? %> +
+
+ <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> + <%= link_to t("org_admin.questions.suggested_or_example_answer_button"), '# ', :class => "btn btn-primary add_suggested_answer_button"%> +
+
+ <% end %> + <% end %> +