Newer
Older
dmpopidor / app / views / answers / _new_edit.html.erb
@Jose Lloret Jose Lloret on 11 Sep 2017 1 KB DMPRoadmap/roadmap#562
<!--
  This partial creates a form for each type of question. The local variables are: plan, answer, question, readonly
-->
<%= form_for answer, url: {controller: :answers, action: :update}, html: {method: :put, 'data-autosave': question.id, class: 'form-answer' } do |f| %>
  <% if !readonly %>
    <%= f.hidden_field :id %>
    <%= f.hidden_field :plan_id %>
    <%= f.hidden_field :user_id %>
    <%= f.hidden_field :question_id %>
    <%= f.hidden_field :lock_version %>
  <% end %>
  <div class="form-input">
      <% if question.option_based? %>
        <%= render(partial: 'questions/new_edit_question_option_based', locals: { f: f, question: question, answer: answer, readonly: @readonly }) %>
      <% elsif question.question_format.textfield?%>
        <%= render(partial: 'questions/new_edit_question_textfield', locals: { f: f, question: question, answer: answer, readonly: @readonly }) %>
      <% elsif question.question_format.textarea? %>
        <%= render(partial: 'questions/new_edit_question_textarea', locals: { f: f, question: question, answer: answer, readonly: @readonly }) %>
      <% end %>
      <!--Example Answer area-->
      <% if !readonly && question.annotations.where(type: Annotation.types[:example_answer]).any? %>
        <% annotation = question.annotations.where(type: Annotation.types[:example_answer]).order(:created_at).first %>
        <% if annotation.text.present? %>
          <div class="suggested-answer-div lefgt-indent">
            <span class="suggested-answer-intro">
              <%="#{annotation.org.abbreviation} "%> <%=_('example answer')%>
            </span>

            <div class="suggested-answer-border">
              <p class="suggested-answer"><%= raw annotation.text %></p>
            </div>
          </div>
        <% end %>
      <% end %>
    </div>
    <% if !readonly %>
      <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
    <% end %>
<% end %>