|
1 | | -<% condition ||= nil %> |
| 1 | +<%# This partial is called from the following files: |
| 2 | + - app/controllers/org_admin/conditions_controller.rb |
| 3 | + - app/views/org_admin/conditions/_container.html.erb |
| 4 | + %> |
2 | 5 |
|
3 | 6 | <div class="row condition-partial mb-3"> |
4 | 7 | <% |
5 | | - action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]] |
6 | | - # name_start = "conditions[]condition_" + condition_no.to_s |
| 8 | + condition ||= nil |
7 | 9 | name_start = "conditions[#{condition_no.to_s}]" |
8 | | - remove_question_collection = later_question_list(question) |
9 | | - condition_exists = local_assigns.has_key? :condition |
10 | | - type_default = condition_exists ? (condition[:action_type] == "remove" ? :remove : :add_webhook) : :remove |
11 | | - remove_question_group = condition_exists ? |
12 | | - grouped_options_for_select(remove_question_collection, condition[:remove_question_id]) : |
13 | | - grouped_options_for_select(remove_question_collection) |
14 | | - multiple = (question.question_format.multiselectbox? || question.question_format.checkbox?) |
15 | | - view_email_content_info = _("Hover over the email address to view email content. To change email details you need to remove and add the condition again.") |
16 | 10 | %> |
17 | 11 |
|
18 | 12 | <%# If this is a new condition then display the interactive controls. otherwise just display the logic %> |
19 | 13 | <% if condition.nil? %> |
20 | | - <div class="form-label bold">Add condition</div> |
21 | | - <div class="row mb-3"> |
22 | | - <div class="col-md-9 pe-2"> |
23 | | - <div class="form-label bold"><%= _('Option') %></div> |
24 | | - <%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text", |
25 | | - condition_exists ? condition[:question_option_id] : question.question_options.sort_by(&:number)[0]), {class: 'form-select regular', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3', name: name_start + "[question_option][]"}) %> |
26 | | - </div> |
27 | | - <div class="col-md-3 pe-2"> |
28 | | - <div class="form-label bold"><%= _('Action') %></div> |
29 | | - <%= select_tag(:action_type, options_for_select(action_type_arr, type_default), {name: name_start + "[action_type]", class: 'action-type form-select narrow', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> |
30 | | - </div> |
31 | | - </div> |
32 | | - <div class="row d-flex mb-3"> |
33 | | - <div class="col-md-10 pe-2"> |
34 | | - <div class="form-label bold display-if-action-remove"><%= _('Target') %></div> |
35 | | - <div class="remove-dropdown"> |
36 | | - <%= select_tag(:remove_question_id, remove_question_group, {name: name_start + "[remove_question_id][]", class: 'form-select regular', multiple: true, 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3'}) %> |
37 | | - </div> |
38 | | - <div class="webhook-replacement display-off my-auto text-center"> |
39 | | - <%= link_to _('Edit email'), '#' %> |
40 | | - </div> |
41 | | - <%= hidden_field_tag(name_start + "[number]", condition_no) %> |
42 | | - </div> |
43 | | - <div class="col-md-2 align-self-center"> |
44 | | - <a href="#anotherurl" class="delete-condition btn btn-primary"><%= _('Remove') %></a> |
45 | | - </div> |
46 | | - <%= render partial: 'org_admin/conditions/webhook_form', locals: {name_start: name_start, condition_no: condition_no} %> |
47 | | - </div> |
| 14 | + <%= render partial: 'org_admin/conditions/new_condition_form', |
| 15 | + locals: { condition_no: condition_no, |
| 16 | + name_start: name_start, |
| 17 | + question: question |
| 18 | + } |
| 19 | + %> |
| 20 | + |
48 | 21 | <% else %> |
49 | | - <% |
50 | | - qopt = condition[:question_option_id].any? ? QuestionOption.find_by(id: condition[:question_option_id].first): nil |
51 | | - rquesArray = condition[:remove_question_id].any? ? Question.where(id: condition[:remove_question_id]) : nil |
52 | | - %> |
53 | | - <div class="col-md-3 pe-2"> |
54 | | - <%= qopt[:text]&.slice(0, 25) %> |
55 | | - <%= hidden_field_tag(name_start + "[question_option][]", condition[:question_option_id]) %> |
56 | | - </div> |
57 | | - <div class="col-md-3 pe-2"> |
58 | | - <%= condition[:action_type] == 'remove' ? 'Remove' : 'Email' %> |
59 | | - <%= hidden_field_tag(name_start + "[action_type]", condition[:action_type]) %> |
60 | | - </div> |
61 | | - <div class="col-md-3 pe-2"> |
62 | | - <% if !rquesArray.nil? %> |
63 | | - <% rquesArray.each do |rques| %> |
64 | | - Question <%= rques[:number] %>: <%= rques.text.gsub(%r{</?p>}, '').slice(0, 50) %> |
65 | | - <%= '...' if rques.text.gsub(%r{</?p>}, '').length > 50 %> |
66 | | - <br> |
67 | | - <% end %> |
68 | | - <%= hidden_field_tag(name_start + "[remove_question_id][]", condition[:remove_question_id]) %> |
69 | | - <% else %> |
70 | | - <% |
71 | | - hook_tip = "Name: #{condition[:webhook_data]['name']}\nEmail: #{condition[:webhook_data]['email']}\n" |
72 | | - hook_tip += "Subject: #{condition[:webhook_data]['subject']}\nMessage: #{condition[:webhook_data]['message']}" |
73 | | - %> |
74 | | - <span title="<%= hook_tip %>"><%= condition[:webhook_data]['email'] %></span> |
75 | | - <br>(<%= view_email_content_info %>) |
| 22 | + <%= render partial: 'org_admin/conditions/existing_condition_display', |
| 23 | + locals: { condition: condition, |
| 24 | + condition_no: condition_no, |
| 25 | + name_start: name_start, |
| 26 | + question: question |
| 27 | + } |
| 28 | + %> |
76 | 29 |
|
77 | | - <%= hidden_field_tag(name_start + "[webhook-email]", condition[:webhook_data]['email']) %> |
78 | | - <%= hidden_field_tag(name_start + "[webhook-name]", condition[:webhook_data]['name']) %> |
79 | | - <%= hidden_field_tag(name_start + "[webhook-subject]", condition[:webhook_data]['subject']) %> |
80 | | - <%= hidden_field_tag(name_start + "[webhook-message]", condition[:webhook_data]['message']) %> |
81 | | - <% end %> |
82 | | - <%= hidden_field_tag(name_start + "[number]", condition_no) %> |
83 | | - </div> |
84 | | - <div class="col-md-3"> |
85 | | - <a href="#anotherurl" class="delete-condition"><%= _('Remove') %></a> |
86 | | - </div> |
87 | 30 | <% end %> |
88 | 31 | </div> |
0 commit comments