Skip to content

Commit 0a0bcfe

Browse files
author
Jose Lloret
committed
Fixed problem when changing question format for editing. Implemented default answer for textfield and textarea. Example answer now loads tinymce for editing too. #414
1 parent e1eded9 commit 0a0bcfe

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

app/controllers/questions_controller.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ def admin_create
88
@question = Question.new(question_params)
99
authorize @question
1010
@question.modifiable = true
11+
if @question.question_format.textfield?
12+
@question.default_value = params["question-default-value-textfield"]
13+
elsif @question.question_format.textarea?
14+
@question.default_value = params["question-default-value-textarea"]
15+
end
1116
if @question.save
1217
@question.section.phase.template.dirty = true
1318
@question.section.phase.template.save!
@@ -50,7 +55,11 @@ def admin_update
5055
guidance.text = params["question-guidance-#{params[:id]}"]
5156
guidance.save
5257
end
53-
@question.default_value = params["question-default-value-#{params[:id]}"]
58+
if @question.question_format.textfield?
59+
@question.default_value = params["question-default-value-textfield"]
60+
elsif @question.question_format.textarea?
61+
@question.default_value = params["question-default-value-textarea"]
62+
end
5463
@section = @question.section
5564
@phase = @section.phase
5665
template = @phase.template
@@ -94,10 +103,8 @@ def question_params
94103
permitted = params.require(:question).except(:created_at, :updated_at).tap do |question_params|
95104
question_params.require(:question_format_id)
96105
q_format = QuestionFormat.find(question_params[:question_format_id])
97-
if q_format.option_based
98-
question_params.delete(:default_value)
99-
else
100-
question_params.delete(:question_options_attributes)
106+
if !q_format.option_based?
107+
question_params.delete(':question_options_attributes')
101108
end
102109
end
103110
end

app/views/questions/_add_question.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ in the admin interface.
9191
<td>
9292
<div class="div_left_icon">
9393
<div>
94-
<%= f.text_field(:default_value, class: "default_answer_textfield", style: 'display:none') %>
95-
<%= text_area(:question, :default_value, class: "default_answer_textarea tinymce") %>
94+
<%= text_field_tag("question-default-value-textfield", @new_question.default_value, class: "default_answer_textfield", style: 'display:none') %>
95+
<%= text_area_tag("question-default-value-textarea", @new_question.default_value, class: "default_answer_textarea tinymce") %>
9696
</div>
9797
</div>
9898
<div class="div_right_icon">

app/views/questions/_edit_question.html.erb

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ in the admin interface.
2828
<!-- Question format -->
2929
<tr>
3030
<td class="first_template"><%= _('Answer format')%></td>
31-
<td><div id="ques-<%= question.id %>-format" class="ques_format">
31+
<td>
32+
<div id="ques-<%= question.id %>-format" class="ques_format">
3233
<div class="div_left_icon">
3334
<%= f.hidden_field :id,{ class: "quest_id" } %>
3435
<%= f.select :question_format_id,
3536
options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id),
36-
{}, id: "#{question.id}-select-format"%>
37+
{}, class: "question_format", id: "#{question.id}-select-format"%>
3738
</div>
3839
<div class="div_right_icon">
3940
<%= 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>"))%>
@@ -42,7 +43,7 @@ in the admin interface.
4243
</div>
4344

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

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

74-
<div class="clearfix"></div>
75-
<!--display for selecting comment box when multiple choice is being used-->
76-
<%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label _('Display additional comment area.'), class: "checkbox inline"%>
75+
<div class="clearfix"></div>
76+
<!--display for selecting comment box when multiple choice is being used-->
77+
<%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label _('Display additional comment area.'), class: "checkbox inline"%>
7778
</div>
7879
<div class="clearfix"></div>
79-
<!--display for default value for text field label-->
80-
<div id='default-text-field-<%= question.id %>' style="display:none;" class="ques_format">
80+
<div class="border_bottom"></div>
81+
</td>
82+
</tr>
83+
<!--Question default_value -->
84+
<tr class="default_answer" style="<%= !question.question_format.option_based? ? '' : 'display:none;'%>">
85+
<td class="first_template"><%= _('Default answer')%></td>
86+
<td>
87+
<div class="div_left_icon">
8188
<div>
82-
<%= _('Default answer')%>
83-
</div>
84-
</div>
85-
<div class="clearfix"></div>
86-
<!--display for default value for text area label -->
87-
<div id="default-text-area-<%= question.id %>" style="display:none;" class="ques_format">
88-
<div >
89-
<%= _('Default answer')%>
89+
<%= text_field_tag("question-default-value-textfield", question.default_value, class: "default_answer_textfield", style: question.question_format.textfield? ? '' : 'display:none;') %>
90+
<%= text_area_tag("question-default-value-textarea", question.default_value, class: "default_answer_textarea tinymce", style: question.question_format.textarea? ? '' : 'display:none;') %>
9091
</div>
9192
</div>
92-
<div class="clearfix"></div>
93-
<div id="default-value-field-<%= question.id %>" style="display:none;" class="ques_format">
94-
<div class="div_left_icon">
95-
<%= text_area_tag("question-default-value-#{question.id}", question.default_value, class: "tinymce") %>
96-
</div>
97-
<div class="div_right_icon">
98-
<%= 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.'))%>
99-
</div>
93+
<div class="div_right_icon">
94+
<%= 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.'))%>
10095
</div>
101-
<div class="add_space"></div>
10296
<div class="clearfix"></div>
10397
<div class="border_bottom"></div>
10498
</td>
10599
</tr>
106-
107100
<!-- Suggested answer or Example-->
108101
<tr>
109102
<td class="first_template"><%= _('Example Answer')%></td>
@@ -116,7 +109,7 @@ in the admin interface.
116109
<%= f.fields_for :annotations, example_answer do |s|%>
117110
<%= s.hidden_field :org_id, value: current_user.org.id %>
118111
<ul>
119-
<li><%= s.text_area :text, rows: 5 %>
112+
<li><%= s.text_area(:text, class: "tinymce") %>
120113
</li>
121114
</ul>
122115
<% end %>

0 commit comments

Comments
 (0)