Newer
Older
dmpopidor / app / views / branded / answers / _new_edit.html.erb
<%# locals: { template, question, answer, research_output, readonly, locking } %>
<!--
  This partial creates a form for each type of question. The local variables are: plan, answer, question, research_output, readonly
-->
<!-- Question text -->
<% q_format = question.question_format %>
<% if q_format.rda_metadata? %>
  <p>
    <div class="display-readonly-textarea-content">
      <strong><%= sanitize question.text %></strong>
    </div>
  </p>
  <% answer_hash = answer.answer_hash %>
  <div class="rda_metadata"><button class="remove-standard" style="display:none;"></button>
    <div class="selected_standards"><strong><%=_("Your Selected Standards:")%></strong><br/><ul class="list bullet"></ul></div>
    <div class="rda_right" style="float:right;width:50%;margin-bottom:5px;display:none;">
      OR Search:<br/>
      <input type="text" data-provide="typeahead" class="standards-typeahead"/><br/>
      <button class="btn btn-primary select_standard_typeahead"><%=_("Add Standard")%></button>
    </div>
    <div class="subject"><%=_("Please select a subject")%><br/>
      <select name="subject" class="form-control"></select>
    </div>
    <div class="sub-subject"><%=_("Please select a sub-subject")%><br/>
      <select name="sub-subject" class="form-control"></select>
    </div>
    <br/>
    <div class="suggested-answer-div">
      <span class="suggested-answer-intro">
          <strong><%=_("Browse Standards") %></strong>
      </span>

      <div class="browse-standards-border">
        <p class="suggested-answer">
          <strong><%=_("Please wait, Standards are loading")%></strong>
        </p>
      </div>
      <div>
        <a href="#" class="custom-standard"><strong>Standard not listed?  Add your own.</strong></a>
        <div class="add-custom-standard" style="display:none;">
          <input type="text" class="custom-standard-name"/>
          <button class="btn btn-primary submit_custom_standard">Add Standard</button>
        </div>
      </div>
    </div>
  </div>
<% end %>

<%= form_for answer, url: create_or_update_answers_path(question_id: question.id), html: {method: :post, 'data-autosave': question.id, class: 'form-answer', id: nil } do |f| %>
  <% if !readonly %>
    <%= f.hidden_field :plan_id, id: nil %>
    <%= f.hidden_field :question_id, id: nil %>
    <%= f.hidden_field :lock_version, id: nil %>
    <%= f.hidden_field :research_output_id, :value => research_output.id, id: nil%>
    <%= f.hidden_field :is_common, class: 'ans_is_common' if answer.research_output.main? %>
    <%= f.hidden_field :id, id: nil, class: 'answer_id' %>
    <% if q_format.rda_metadata? %>
      <%= hidden_field_tag :standards, answer_hash['standards'].to_json %>
    <% end %>
  <% end %>
  <fieldset aria-labelledby="answer-fieldset" <%= 'disabled' if readonly %> >
    <% if question.option_based? || question.question_format.rda_metadata? %>
        <%= render(partial: 'questions/new_edit_question_option_based', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
    <% elsif question.question_format.structured %>
      <%= f.label(:text, sanitize(question.text), class: 'control-label') unless question.nil? %>
      <div class="form-group structured-answer">   
        <% data = answer.structured_answer.data unless answer.structured_answer.nil? %>
        <%= render(partial: 'questions/new_edit_question_structured', locals: { f: f, data: data, readonly: readonly, schema: question.structured_data_schema.schema }) %>
      </div>
    <% elsif question.question_format.textfield?%>
        <%= render(partial: 'questions/new_edit_question_textfield', locals: { f: f, question: question, answer: answer, research_output: research_output }) %>
    <% elsif question.question_format.textarea? %>
        <%= render(partial: 'questions/new_edit_question_textarea', locals: { f: f, question: question, answer: answer, research_output: research_output, locking: locking, readonly: readonly}) %>
    <% elsif question.question_format.date? %>
        <%= render(partial: 'questions/new_edit_question_datefield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
    <% elsif question.question_format.number? %>
        <%= render(partial: 'questions/new_edit_question_numberfield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
    <% end %>
    <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
  </fieldset>
  <!--Example Answer area -->
  <% if template.present? && template.org.present? %>
    <% question.example_answers([base_template_org.id, template.org.id]).each do |annotation| %>
      <% if annotation.present? && annotation.org.present? && annotation.text.present? %>
        <div class="panel panel-default example-answer">
          <span class="label label-default example-answer-link" 
                data-toggle="collapse" 
                data-target="<%= "#example-#{question.id}-research-output-#{research_output.id}"  %>">
            <%="#{annotation.org.abbreviation} "%> <%=_('example answer')%>
            <i class="more-less fa fa-plus small"></i>
          </span>
          <div class="panel-body collapse" id="<%= "example-#{question.id}-research-output-#{research_output.id}"  %>">
            <%= sanitize annotation.text %>
          </div>
        </div>
      <% end %>
    <% end %>
  <% end %>
<% end %>