From 7e8508f9d4b386dd8baa98b3cea27c07140d4614 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Mon, 24 Aug 2020 15:33:17 +0200 Subject: [PATCH] Targets form allows only targets within one Goal --- app/views/targets/_form.html.erb | 78 ++++++++++++++++---------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/app/views/targets/_form.html.erb b/app/views/targets/_form.html.erb index 185de94..27b5e3b 100644 --- a/app/views/targets/_form.html.erb +++ b/app/views/targets/_form.html.erb @@ -1,53 +1,51 @@ <%= error_messages_for *@targets %> -<% @targets.group_by(&:goal).each do |goal, targets| %> -
-
- <% if goal.persisted? || goal.is_binding? %> -

<%= render partial: 'goals/show_form', locals: {goal: goal} %>

-

<%= f.date_field :effective_from, disabled: !goal.is_binding? %>

- <% else %> - <%= render partial: 'goals/form', locals: {goal: goal} %> - <% end %> -
+
+
+ <% if current_goal.persisted? %> +

<%= render partial: 'goals/show_form', locals: {goal: current_goal} %>

+

<%= f.date_field :effective_from, disabled: !current_goal.is_binding? %>

+ <% else %> + <%= render partial: 'goals/form', locals: {goal: current_goal} %> + <% end %> +
-
+
-
- <% targets.each do |target| %> -

- <%= f.fields_for 'targets', target, index: '' do |target_f| %> - <%= target_f.hidden_field :id %> - <%= target_f.hidden_field :_destroy %> - <%= t ".choose_quantity" %> - <% target.thresholds.each_with_index do |thr, index| %> - <%= target_f.fields_for 'thresholds_attributes', thr, index: '' do |threshold_f| %> - <%= threshold_f.hidden_field :id %> - <% if index == 0 %> - <%= threshold_f.select :quantity_id, quantity_options, - {include_blank: true, required: true, label: :field_target}, - onchange: "showQuantityPath(event);" %> - <%= target_f.select :condition, condition_options, required: true, - label: '' %> - <% end %> - <%= threshold_f.number_field :value, {size: 8, step: :any, label: ''} %> - <% if index == 0 %> - <%= threshold_f.select :unit_id, unit_options, {label: ''} %> - <% end %> +

+ <% @targets.each do |target| %> +

+ <%= f.fields_for 'targets', target, index: '' do |target_f| %> + <%= target_f.hidden_field :id %> + <%= target_f.hidden_field :_destroy %> + <%= t ".choose_quantity" %> + <% target.thresholds.each_with_index do |thr, index| %> + <%= target_f.fields_for 'thresholds_attributes', thr, index: '' do |threshold_f| %> + <%= threshold_f.hidden_field :id %> + <% if index == 0 %> + <%= threshold_f.select :quantity_id, quantity_options, + {include_blank: true, required: true, label: :field_target}, + onchange: "showQuantityPath(event);" %> + <%= target_f.select :condition, condition_options, required: true, + label: '' %> + <% end %> + <%= threshold_f.number_field :value, {size: 8, step: :any, label: ''} %> + <% if index == 0 %> + <%= threshold_f.select :unit_id, unit_options, {label: ''} %> <% end %> <% end %> - <%= link_to t(".button_delete_target"), '#', class: 'icon icon-del', - onclick: "deleteTarget(); return false;" %> <% end %> -

+ <%= link_to t(".button_delete_target"), '#', class: 'icon icon-del', + onclick: "deleteTarget(); return false;" %> <% end %> -

- <%= link_to t(".button_new_target"), '#', class: 'icon icon-add', - onclick: 'newTarget(); return false;' %>

-
+ <% end %> +

+ <%= link_to t(".button_new_target"), '#', class: 'icon icon-add', + onclick: 'newTarget(); return false;' %> +

-<% end %> +
<%= javascript_tag do %> function showQuantityPath(event) {