Skip to content

Commit

Permalink
Merge pull request #415 from DigitalCurationCentre/issue414
Browse files Browse the repository at this point in the history
Issue414
  • Loading branch information
vyruss authored Jun 12, 2017
2 parents c6a10f9 + 0a0bcfe commit 2244fcf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
17 changes: 12 additions & 5 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def admin_create
@question = Question.new(question_params)
authorize @question
@question.modifiable = true
if @question.question_format.textfield?
@question.default_value = params["question-default-value-textfield"]
elsif @question.question_format.textarea?
@question.default_value = params["question-default-value-textarea"]
end
if @question.save
@question.section.phase.template.dirty = true
@question.section.phase.template.save!
Expand Down Expand Up @@ -50,7 +55,11 @@ def admin_update
guidance.text = params["question-guidance-#{params[:id]}"]
guidance.save
end
@question.default_value = params["question-default-value-#{params[:id]}"]
if @question.question_format.textfield?
@question.default_value = params["question-default-value-textfield"]
elsif @question.question_format.textarea?
@question.default_value = params["question-default-value-textarea"]
end
@section = @question.section
@phase = @section.phase
template = @phase.template
Expand Down Expand Up @@ -94,10 +103,8 @@ def question_params
permitted = params.require(:question).except(:created_at, :updated_at).tap do |question_params|
question_params.require(:question_format_id)
q_format = QuestionFormat.find(question_params[:question_format_id])
if q_format.option_based
question_params.delete(:default_value)
else
question_params.delete(:question_options_attributes)
if !q_format.option_based?
question_params.delete(':question_options_attributes')
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/questions/_add_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ in the admin interface.
<td>
<div class="div_left_icon">
<div>
<%= f.text_field(:default_value, class: "default_answer_textfield", style: 'display:none') %>
<%= text_area(:question, :default_value, class: "default_answer_textarea tinymce") %>
<%= text_field_tag("question-default-value-textfield", @new_question.default_value, class: "default_answer_textfield", style: 'display:none') %>
<%= text_area_tag("question-default-value-textarea", @new_question.default_value, class: "default_answer_textarea tinymce") %>
</div>
</div>
<div class="div_right_icon">
Expand Down
47 changes: 20 additions & 27 deletions app/views/questions/_edit_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ in the admin interface.
<!-- Question format -->
<tr>
<td class="first_template"><%= _('Answer format')%></td>
<td><div id="ques-<%= question.id %>-format" class="ques_format">
<td>
<div id="ques-<%= question.id %>-format" class="ques_format">
<div class="div_left_icon">
<%= f.hidden_field :id,{ class: "quest_id" } %>
<%= f.select :question_format_id,
options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id),
{}, id: "#{question.id}-select-format"%>
{}, class: "question_format", id: "#{question.id}-select-format"%>
</div>
<div class="div_right_icon">
<%= link_to( image_tag("help_button.png"), "#", class: "question_format_popover", rel: "popover", "data-html" => "true", "data-content" => _("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>"))%>
Expand All @@ -42,7 +43,7 @@ in the admin interface.
</div>

<!--display form to enter option from checkbox/radio button/ dropdown/ multi select box-->
<div id="options-<%= question.id %>" style="display:none;" class="ques_format_option">
<div id="options-<%= question.id %>" style="<%= question.question_format.option_based? ? '' : 'display:none;'%>" class="ques_format_option">
<table class="options_table">
<thead>
<tr>
Expand Down Expand Up @@ -71,39 +72,31 @@ in the admin interface.

<a href="#" class="add-option"><%= _('Add option') %></a>

<div class="clearfix"></div>
<!--display for selecting comment box when multiple choice is being used-->
<%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label _('Display additional comment area.'), class: "checkbox inline"%>
<div class="clearfix"></div>
<!--display for selecting comment box when multiple choice is being used-->
<%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label _('Display additional comment area.'), class: "checkbox inline"%>
</div>
<div class="clearfix"></div>
<!--display for default value for text field label-->
<div id='default-text-field-<%= question.id %>' style="display:none;" class="ques_format">
<div class="border_bottom"></div>
</td>
</tr>
<!--Question default_value -->
<tr class="default_answer" style="<%= !question.question_format.option_based? ? '' : 'display:none;'%>">
<td class="first_template"><%= _('Default answer')%></td>
<td>
<div class="div_left_icon">
<div>
<%= _('Default answer')%>
</div>
</div>
<div class="clearfix"></div>
<!--display for default value for text area label -->
<div id="default-text-area-<%= question.id %>" style="display:none;" class="ques_format">
<div >
<%= _('Default answer')%>
<%= text_field_tag("question-default-value-textfield", question.default_value, class: "default_answer_textfield", style: question.question_format.textfield? ? '' : 'display:none;') %>
<%= text_area_tag("question-default-value-textarea", question.default_value, class: "default_answer_textarea tinymce", style: question.question_format.textarea? ? '' : 'display:none;') %>
</div>
</div>
<div class="clearfix"></div>
<div id="default-value-field-<%= question.id %>" style="display:none;" class="ques_format">
<div class="div_left_icon">
<%= text_area_tag("question-default-value-#{question.id}", question.default_value, class: "tinymce") %>
</div>
<div class="div_right_icon">
<%= link_to( image_tag("help_button.png"), "#", class: "default_answer_popover", rel: "popover", "data-html" => "true", "data-content" => _('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.'))%>
</div>
<div class="div_right_icon">
<%= link_to( image_tag("help_button.png"), "#", class: "default_answer_popover", rel: "popover", "data-html" => "true", "data-content" => _('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.'))%>
</div>
<div class="add_space"></div>
<div class="clearfix"></div>
<div class="border_bottom"></div>
</td>
</tr>

<!-- Suggested answer or Example-->
<tr>
<td class="first_template"><%= _('Example Answer')%></td>
Expand All @@ -116,7 +109,7 @@ in the admin interface.
<%= f.fields_for :annotations, example_answer do |s|%>
<%= s.hidden_field :org_id, value: current_user.org.id %>
<ul>
<li><%= s.text_area :text, rows: 5 %>
<li><%= s.text_area(:text, class: "tinymce") %>
</li>
</ul>
<% end %>
Expand Down

0 comments on commit 2244fcf

Please sign in to comment.