-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy path_form.html.erb
More file actions
111 lines (102 loc) · 6.52 KB
/
_form.html.erb
File metadata and controls
111 lines (102 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<% question_default_value_tooltip = _('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.') %>
<h4>
<%= question.id.present? ? _('Question %{number}:') % { number: question.number } : _('New question:') %>
</h4>
<%= form_for(question, url: url,
namespace: question.id.present? ? "q_#{question.id}" : 'new_question',
html: { method: method, class: 'question_form' }) do |f| %>
<% current_format = question.question_format.present? ? question.question_format : QuestionFormat.find_by(formattype: QuestionFormat.formattypes[:textarea]) %>
<div class="row">
<!--Question number -->
<div class="form-control mb-3 col-md-4">
<%= f.label(:number, _('Question Number'), class: "form-label") %>
<%= f.number_field(:number, in: 1..50, class: "form-control",
"aria-required": true) %>
</div>
<!--Question text -->
<div class="form-control mb-3 col-md-10">
<%= f.label(:text, _('Question text'), class: "form-label") %>
<%= f.text_area(:text, class: "question", spellcheck: true, "aria-required": true) %>
</div>
<!-- Question format -->
<div class="form-control mb-3 col-md-4">
<%= f.label(:question_format_id, _('Answer format'), class: "form-label") %>
<%= f.select :question_format_id,
options_from_collection_for_select(question_formats,
:id,
:title,
question.question_format_id),
{},
class: "form-select question_format",
'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-control mb-3 col-md-10" data-attribute="question_options" style="<%= current_format.option_based? ? '' : 'display:none;' %>">
<div class="col-md-offset-2">
<%= render "/org_admin/question_options/option_fields", f: f, q: question %>
<!--display for selecting comment box when multiple choice is being used-->
</div>
<% if question.id != nil && question.question_options[0].text != nil %>
<% cond_lbl = conditions&.any? ? 'Edit Conditions' : 'Add Conditions' %>
<%= link_to cond_lbl, org_admin_question_open_conditions_path(question_id: question.id, conditions: conditions), class: "add-logic btn btn-secondary", 'data-loaded': (conditions.size > 0).to_s, remote: true %>
<div id="content" class="col-md-offset-2">
<p>
<%= render partial: 'org_admin/conditions/container', locals: { f: f, question: question, conditions: conditions } %>
</p>
</div>
<% else %>
<div class="form-control mb-3" data-toggle="tooltip", title="<%= _('Save this question before adding conditions.') %>" >
<%= link_to _('Edit Conditions'), '#', class: "add-logic btn btn-secondary disabled" %>
</div>
<% end %>
</div>
<% comment_disp = current_format.option_based? || current_format.rda_metadata? %>
<div class="form-check mb-3 col-md-10" data-attribute="option_comment"
style="<%=comment_disp ? '' : 'display:none;'%>">
<%= f.check_box :option_comment_display, as: :check_boxes %>
<%= f.label(:option_comment_display, _('Display additional comment area'), class: 'form-check-label') %>
</div>
<!--Question default_value -->
<div class="form-control mb-3 col-md-10" data-attribute="default_value" style="<%= current_format.textfield? || current_format.textarea? ? '' : 'display: none;' %>">
<%= f.label(:default_value, _('Default answer'), class: "form-label") %>
<div class="" data-toggle="tooltip" title="<%= question_default_value_tooltip %>">
<em class="sr-only"><%= question_default_value_tooltip %></em>
<span data-attribute="textfield" style="<%= current_format.textfield? ? '' : 'display:none;' %>">
<%= f.text_field(:default_value, class: 'form-control', spellcheck: true) %>
</span>
<span data-attribute="textarea" style="<%= current_format.textarea? ? '' : 'display:none;' %>">
<%= text_area_tag('question[default_value]', question.default_value, id: "#{question.id.present? ? question.id : 'new'}_question_default_value_area", class: "form-control question") %>
</span>
</div>
</div>
</div>
<div class="row">
<%# example_answer and guidance annotations as nested fields %>
<% question.annotations_per_org(current_user.org_id).each do |annotation| %>
<%= f.fields_for(:annotations, annotation) do |annotation_fields| %>
<%= render partial: 'org_admin/annotations/form', locals: { f: annotation_fields } %>
<% end %>
<% end %>
<!-- Themes -->
<div class="form-control mb-3 col-md-10">
<%= render partial: 'org_admin/shared/theme_selector',
locals: { f: f, all_themes: Theme.all.order("title"), as_radio: false,
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-control mb-3 col-md-10">
<div class="float-end">
<%= f.submit _('Save'), class: "btn btn-secondary", role:'button' %>
<% if question.id.present? %>
<% href = org_admin_template_phase_section_question_path(template_id: template.id, phase_id: question.section.phase.id, section_id: question.section.id, id: question.id) %>
<%= link_to _('Delete'), href, method: :delete, class: "btn btn-secondary", role:'button', 'data-confirm': _("You are about to delete question #%{question_number}. Are you sure?") % { question_number: question.number } %>
<%= link_to _('Cancel'), href, class: "btn btn-secondary ajaxified-question", method: 'get', remote: true %>
<% else %>
<%= link_to _('Cancel'), '#', class: "btn btn-secondary cancel-new-question" %>
<% end %>
</div>
</div>
</div>
<% end %>