Newer
Older
dmpopidor / app / views / questions / _edit_question.html.erb
<!--
**Project: DMPRoadmap
**Description: This block displays editing a question, its guidance, and options when multiple choice is selected
in the admin interface.
**Arguments transferred: an instance of 'question'
**Copyright: Digital Curation Centre and California Digital Library
-->
<div class="row">
  <div class="col-md-12">
    <div class="row">
      <div class="col-md-12">
        <%= 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" %>
          <!--Question number -->
          <div class="form-group col-md-4">
            <%= f.label(:number, _('Question Number'), class: "control-label") %>
            <%= f.number_field(:number, in: 1..50, class: "form-control", "aria-required": true, 'aria-required': true) %>
          </div>
          <!--Question text -->
          <div class="form-group col-md-10">
            <%= f.label(:text, _('Question text'), class: "control-label") %>
            <%= f.text_area(:text, class: "question") %>
          </div>
          <!-- Question format -->
          <div class="form-group col-md-4">
            <%= f.label(:question_format_id, _('Answer format'), class: "control-label") %>
              <%= f.select :question_format_id,
                options_from_collection_for_select(QuestionFormat.all.order("title"),
                :id,
                :title,
                question.question_format_id),
                {},
                class: "form-control",
                'data-toggle': 'tooltip',
                'data-html': true,
                title: _("You can choose from:<ul><li>- text area (large box for paragraphs);</li> <li>- text field (for a short answer);</li> <li>- checkboxes where options are presented in a list and multiple values can be selected;</li> <li>- radio buttons where options are presented in a list but only one can be selected;</li> <li>- dropdown like this box - only one option can be selected;</li> <li>- multiple select box allows users to select several options from a scrollable list, using the CTRL key;</li></ul>")
              %>
          </div>
          <!--display form to enter option for option_based questions -->
          <div class="form-group col-md-10" data-attribute="question_options" style="<%= question.question_format.option_based? ? '' : 'display:none;' %>">
            <div class="col-md-offset-2">
              <%= render "/question_options/option_fields", f: f, q: question %>
              <!--display for selecting comment box when multiple choice is being used-->
            </div>
          </div>
          <% comment_disp = question.question_format.option_based? || question.question_format.rda_metadata? %>
          <div class="form-group col-md-10" data-attribute="option_comment" style="<%=comment_disp ? '' : 'display:none;'%>">
            <label>
              <%= f.check_box :option_comment_display, as: :check_boxes %><%= _('Display additional comment area.') %>
            </label>
          </div>
          <!--Question default_value -->
          <div class="form-group col-md-10" data-attribute="default_value" style="<%= question.question_format.textfield? || question.question_format.textarea? ? '' : 'display: none;' %>">
            <%= f.label(:default_value, _('Default answer'), class: "control-label") %>
            <div class="" data-toggle="tooltip" title="<%= _('Anything you enter here will display in the answer box. If you want an answer in a certain format (e.g. tables), you can enter that style here.') %>">
              <span data-attribute="textfield" style="<%= question.question_format.textfield? ? '' : 'display:none;' %>">
                <%= text_field_tag("question-default-value-textfield", question.default_value, class: 'form-control') %>
              </span>
              <span data-attribute="textarea" style="<%= question.question_format.textarea? ? '' : 'display:none;' %>">
                <%= text_area_tag("question-default-value-textarea", question.default_value, class: 'question') %>
              </span>
            </div>
          </div>
          <!-- Suggested answer or Example for Question -->
          <div class="form-group col-md-10">
            <%= f.label(:example_answer, _('Example Answer'), class: "control-label") %>
            <div class="" data-toggle="tooltip" title="<%= ('You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted.') %>">
              <% example_answer = question.get_example_answers(current_user.org.id).first %>
              <% if example_answer.nil? %>
                  <% example_answer = question.annotations.build %>
                  <% example_answer.type = :example_answer %>
              <% end %>
              <%= f.fields_for :annotations, example_answer do |s|%>
                <%= s.hidden_field :org_id, value: current_user.org.id %>
                  <%= s.text_area(:text, class: 'question') %>
              <% end %>
            </div>
          </div>
          <!-- Guidance for Question -->
          <div class="form-group col-md-10">
            <%= f.label(:guidance, _('Guidance'), class: "control-label") %>
            <div data-toggle="tooltip" title="<%= _("Enter specific guidance to accompany this question. If you have guidance by themes too, this will be pulled in based on your selections below so it's best not to duplicate too much text.") %>">
              <% guidance = question.get_guidance_annotation(current_user.org_id) %>
              <% guidance_text = guidance.present? ? guidance.text : "" %>
              <%= text_area_tag("question-guidance-#{question.id}", guidance_text , class: 'question') %>
            </div>
          </div>
          <!-- Themes -->
          <div class="form-group col-md-10">
            <%= render partial: 'org_admin/shared/theme_selector',
                       locals: { f: f, all_themes: Theme.all.order("title"),
                                 popover_message: _('Select one or more themes that are relevant to this question. This will allow similarly themed organisation-level guidance to appear alongside your question.') } %>
          </div>
          <div class="form-group col-md-10">
            <div class="pull-right">
              <%= 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, 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' %>
            </div>
          </div>
        <% end %>

      </div>
    </div>
  </div>
  <div class="col-md-5">
    <%#= render partial: "guidances/guidance_display", locals: {question: question} %>
  </div>
</div>