56 lines
2.1 KiB
Plaintext
56 lines
2.1 KiB
Plaintext
<%= error_messages_for @measurement %>
|
|
|
|
<div class="box tabular">
|
|
<p><%= f.select :source_id, source_options,
|
|
{required: false, include_blank: t('.null_source')} %></p>
|
|
<p><%= f.text_field :name, size: 40, required: true %></p>
|
|
<p>
|
|
<%= f.date_field :taken_at_date, required: true %>
|
|
<%= f.time_field :taken_at_time, value: @measurement.taken_at.strftime("%H:%M"),
|
|
required: true, label: '' %>
|
|
</p>
|
|
<% @measurement.readouts.each_with_index do |r, index| %>
|
|
<%= f.fields_for 'readouts_attributes', r, index: '' do |ff| %>
|
|
<p class="readout">
|
|
<%= ff.select :quantity_id, quantity_options,
|
|
{include_blank: true, required: true, label: (index > 0 ? '' : :field_readouts)} %>
|
|
<%= ff.number_field :value, {size: 8, step: :any, label: ''} %>
|
|
<%= ff.select :unit_id, unit_options, {label: ''} %>
|
|
<%= ff.check_box :_destroy, {style: "display:none", label: ''} %>
|
|
<%= link_to t(".button_delete_readout"), '#',
|
|
class: 'icon icon-del',
|
|
style: (@measurement.readouts.length > 1 ? "" : "display:none"),
|
|
onclick: "deleteReadout(); return false;" %>
|
|
</p>
|
|
<% end %>
|
|
<% end %>
|
|
<p>
|
|
<%= link_to t(".button_add_readout"), '#', class: 'icon icon-add',
|
|
onclick: 'addReadout(); return false;' %>
|
|
</p>
|
|
</div>
|
|
|
|
<%= javascript_tag do %>
|
|
function addReadout() {
|
|
var row = $('p.readout:visible:last');
|
|
var new_row = row.clone().insertAfter(row);
|
|
new_row.find('input[id$=_value], select[id$=_quantity_id]').val('');
|
|
new_row.find('select[id$=_unit_id]').val(row.find('select[id$=_unit_id]').val());
|
|
new_row.find('label:first').text('');
|
|
if ($('p.readout:visible').length > 1) {
|
|
$('p.readout a.icon-del').show();
|
|
}
|
|
}
|
|
|
|
function deleteReadout() {
|
|
var row = $(event.target).closest('p.readout');
|
|
row.find('[id$=_destroy]').val(1);
|
|
// FIXME: should only hide() row if record already saved (to send _destroy to backend)
|
|
row.remove();
|
|
$('p.readout:visible:first label:first').text('<%= t "field_readouts" %>');
|
|
if ($('p.readout:visible').length <= 1) {
|
|
$('p.readout a.icon-del').hide();
|
|
}
|
|
}
|
|
<% end %>
|