<!--
**Project: DMPRoadmap
**Description: This block shows a question, its guidance, and options when multiple choice is selected.
**Arguments transferred: 'question'
**Copyright: Digital Curation Centre and University of California Curation Center
-->
<div class="question-div">
<table class="dmp_details_table phase">
<!--Question number -->
<tr>
<td class="first_template"><%= _('Question number')%></td>
<td><%= question.number %></td>
</tr>
<!--Question text -->
<tr>
<td class="first_template"><%= _('Question text')%></td>
<td><%= raw question.text %>
</br>
<div class="answer-readonly">
<% q_format = question.question_format %>
<% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %>
<ul class='options'>
<% if question.question_options.is_a? QuestionOption %>
<li>- <%= question.question_options.text %></li>
<% else %>
<% if !question.question_options.to_a.nil? %>
<% question.question_options.to_a.sort_by{|op| op['number']}.each do |o| %>
<li>- <%= o.text %></li>
<% end %>
<% end %>
<% end %>
</ul>
<% end %>
</div>
</td>
</tr>
<!--Default value -->
<% if q_format.title == _('Text field') || q_format.title == _('Text area') %>
<% if !question.default_value.nil? %>
<tr>
<td class="first_template"><%= _('Default value')%></td>
<td><%= raw question.default_value %></td>
</tr>
<% end %>
<% end %>
<!-- Question format -->
<tr>
<td class="first_template"><%= _('Answer format')%></td>
<td><%= q_format.title %>
</br>
<% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %>
<% if question.option_comment_display == true %>
<%= _('Additional comment area will be displayed.')%>
<% else %>
<%= _('No additional comment area will be displayed.')%>
<% end %>
<% end %>
<div class="add_space"></div>
</td>
</tr>
<!-- Suggested answer or Example-->
<% if question.section.phase.template.org.org_type != constant("organisation_types.funder") %>
<% suggested_answer = question.get_suggested_answer(current_user.org_id) %>
<% if !suggested_answer.nil? && suggested_answer.text != "" %>
<tr>
<td class="first_template">
<% if suggested_answer.is_example? %>
<%= _('Example of answer')%>
<% else %>
<%= _('Suggested answer')%>
<% end %>
</td>
<td><%= raw suggested_answer.text %></td>
</tr>
<% end %>
<% end %>
<!-- Guidance linked to this question -->
<% if !question.guidance.nil? %>
<tr>
<td class="first_template"><%= _('Guidance')%></td>
<td><%= raw question.guidance %></td>
</tr>
<% end %>
<!-- Themes -->
<% themes_q = question.themes %>
<% if !themes_q.nil? %>
<tr>
<td class="first_template"><%= _('Themes')%></td>
<td><% i = 1%>
<% themes_q.each do |t|%>
<%= t.title %>
<% if themes_q.count > i %>
,
<% i +=1 %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</table>
<br/>
<!-- Add suggested or example answers to a funders template-->
<% if !question.modifiable %>
<% suggested_answer = question.get_suggested_answer(current_user.org_id) %>
<% if !suggested_answer.nil? && suggested_answer.text != "" %>
<div id="show_suggested_answer_div_<%= question.id%>">
<%= render partial: 'suggested_answers/show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %>
</div>
<div id="edit_suggested_answer_div_<%= question.id%>" style="display: none">
<%= render partial: 'suggested_answers/edit_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %>
</div>
<% end %>
<div id="add_suggested_answer_block_<%= question.id%>" style="display: none">
<%= render partial: 'suggested_answers/add_suggested_answer', locals: {question: question} %>
</div>
<% end %>
<br/>
<!-- edit question button-->
<% if (@edit && question.section.modifiable) || question.section.phase.template.customization_of.present? %>
<div class="move_2_right">
<%= hidden_field_tag :question_id, question.id, class: "question_id" %>
<%= link_to _('Edit question'), '# ', class: "btn btn-primary edit_question_button"%>
<% if !question.section.published? %>
<%= link_to _('Delete question'), admin_destroy_question_path(question_id: question.id),
confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary"%>
<% end %>
</div>
<% elsif !@edit && question.modifiable %>
<% suggested_answer = question.get_suggested_answer(current_user.org_id) %>
<% if suggested_answer.nil? %>
<div id="add_suggested_answer_button_<%= question.id%>">
<div class="move_2_right">
<%= hidden_field_tag :question_id, question.id, class: "question_id" %>
<%= link_to _('Add suggested answer/ example'), '# ', class: "btn btn-primary add_suggested_answer_button"%>
</div>
</div>
<% end %>
<% end %>
<div class="div_clear"></div>
</div>
<!--guidance block -->
<%= render partial: 'guidances/guidance_display', locals: {question: question}%>