1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/views/targets/_form.html.erb
cryptogopher 406eabaccc Fix target subtreshold listing
Route targets under goal
2021-03-06 13:00:50 +01:00

64 lines
2.1 KiB
Plaintext

<% if goal_f.object.is_binding? %>
<p>
<%= goal_f.date_field :effective_from, value: @effective_from, required: true %>
</p>
<% end %>
<%= goal_f.fields_for :targets, @targets, child_index: '' do |target_f| %>
<p class="target">
<%= target_f.hidden_field :_destroy %>
<em class="info"><%= t ".choose_quantity" %></em>
<%= target_f.select :quantity_id, quantity_options,
{include_blank: true, required: true, label: :field_target},
onchange: "showQuantityPath(event);" %>
<%= render partial: 'targets/thresholds_form',
locals: {target_f: target_f,
last_quantity: target_f.object.thresholds.last.quantity} %>
<%= link_to t(".button_delete_target"), '#', class: 'icon icon-del',
style: (@targets.many? ? "" : "display:none"),
onclick: "deleteTarget(); return false;" %>
</p>
<% end %>
<p>
<%= link_to t(".button_new_target"), '#', class: 'icon icon-add',
onclick: 'newTarget(); return false;' %>
</p>
<%= javascript_tag do %>
function showQuantityPath(event) {
$(event.target).prevAll('em').text($('option:selected', event.target)
.attr('data-path'));
}
$(document).ajaxComplete(function() {
$('p.target select:first-child[id$=__quantity_id]').trigger(jQuery.Event('change'));
})
function newTarget() {
var form = $(event.target).closest('form');
var row = form.find('p.target:visible:last');
var new_row = row.clone().insertAfter(row);
new_row.find('em').text('<%= t ".choose_quantity" %>');
new_row.find('input, select').val('');
new_row.find('select[id$=__unit_id]').val(row.find('select[id$=__unit_id]').val());
new_row.find('label:first').hide();
form.find('p.target:visible a.icon-del').show();
}
function deleteTarget() {
var form = $(event.target).closest('form');
var row = $(event.target).closest('p.target');
if (row.find('input[id$=__id]').val()) {
row.hide();
row.find('input[id$=__destroy]').val('1');
} else {
row.remove();
}
form.find('p.target:visible:first label:first').show();
if (form.find('p.target:visible').length <= 1) {
form.find('p.target:visible a.icon-del').hide();
}
}
<% end %>