Newer
Older
dmpopidor / app / views / phases / _answer.html.erb
@ray.carrick ray.carrick on 1 Mar 2017 2 KB Optimistic Locking
<!-- 
  **Project: DMPRoadmap
  **Description: this partial renders an answer when there is a conflict.
  **Arguments transferred: question, answer
  **Copyright: Digital Curation Centre and University of California Curation Center
-->

<% qformat = question.question_format %>

<!-- this semantic form is completely useless but it seems better at the moment
  to mirror how the answer is rendered in the answer_form partial.
  TODO: I think we need to move away from formtastic and move to raw HTML as that will
  make it easier to have a partial which renders an answer either in a form or not 
  right now you'd need to parameterise it with the form parameter which doesn't exist
  if you are coming from /answer/update -->

<p> While you were editing <%= answer.user.name %> saved the following answer: </p>

<%= semantic_form_for answer, :url => {:controller => :answers, :action => :update }, :remote => true do |af| %>
  <%= af.inputs do %>

    <!-- if the question has multiple choices pull out the options -->
    <% if question.isOptionBased? %>
      <% options = question.options.order("number") %>

      <!-- work through the various format options -->
      <% if qformat.checkbox? %>
        <%= af.input :options,
          :as => :check_boxes,
          :collection => options,
          :label => false,
          :input_html => { :disabled => :true }
        %>
      <% elsif qformat.multiselectbox? %>
        <%= af.input :options,
          :as => :select,
          :collection => options,
          :label => false,
          :input_html => { :multiple => true , :disabled => :true } %>
      <% elsif qformat.radiobuttons %>
        <ol class="choices-group">
          <% options.each do |op| %>
            <li class= "choices-group">
              <% checked = (answer.option_ids[0] == op.id) %>
              <%= af.radio_button :option_ids, op.id, :checked => checked, id: "answer_option_ids_#{op.id}"%> 
              <%= raw op.text %>
            </li>
          <% end %>
        </ol>
      <% elsif qformat.dropdown? %>
        <%= af.input :options,
          :as => :select,
          :collection => options,
          :label => false,
          :input_html => { :multiple => false, :disabled => :true }
        %>
      <% end %>

      <!-- Comment text area for the multiple choice answers-->
      <% if question.option_comment_display %>
        <%= label_tag("answer-text-Ans#{question.id}".to_sym, t("helpers.comment")) %>
        <%= text_area_tag("answer-text-Ans#{question.id}".to_sym, answer.text, class: "tinymce") %>
      <%end%>
    <% end %>  <!-- if multiple choice -->

    <% if qformat.textfield? %>
      <%= text_field_tag("answer-text-Ans#{question.id}".to_sym, strip_tags(answer.text), class: "question_text_field") %>
    <% elsif qformat.textarea? %>
      <%= text_area_tag("answer-text-Ans#{question["id"]}".to_sym, strip_tags(answer.text), class: "tinymce") %>
    <% end %>

  <% end %>   <!-- inputs -->
<% end %>     <!-- form -->

<p>Combine with your answer and save.</p>