Updated ItemsWithQuantities to work with MeasurementRoutine Replaced ColumnViews HABTM with polymorphic HMT Added Measurement notes Added destroy restrictions on Quantity Replaced BodyTrackingPluginController with Finders concern Removed 'body_trackers' prefix from paths Unified styling for textarea
74 lines
2.7 KiB
Plaintext
74 lines
2.7 KiB
Plaintext
<%= error_messages_for @measurement %>
|
|
|
|
<fieldset class="box">
|
|
<legend ><%= t('.label_routine') %></legend>
|
|
<div class="tabular">
|
|
<%= f.fields_for :routine do |ff| %>
|
|
<p><%= ff.text_field :name, required: true, style: "width: 95%;" %></p>
|
|
<p><%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %></p>
|
|
<% end %>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset class="box">
|
|
<legend ><%= t('.label_measurement') %></legend>
|
|
<div class="tabular">
|
|
<p><%= f.select :source_id, source_options,
|
|
{required: false, include_blank: t('.null_source')} %></p>
|
|
<p><%= f.text_area :notes, cols: 40, rows: 1, style: "width: 95%;" %></p>
|
|
<p>
|
|
<%= f.date_field :taken_at_date, required: true %>
|
|
<%= f.time_field :taken_at_time, value: format_time(@measurement), 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.hidden_field :id %>
|
|
<%= 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.hidden_field :_destroy %>
|
|
<%= 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_new_readout"), '#', class: 'icon icon-add',
|
|
onclick: 'newReadout(); return false;' %>
|
|
</p>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<%= javascript_tag do %>
|
|
function newReadout() {
|
|
var form = $(event.target).closest('form');
|
|
var row = form.find('p.readout:visible:last');
|
|
var new_row = row.clone().insertAfter(row);
|
|
new_row.find('input[id$=__id], 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('input[id$=__destroy]').val('');
|
|
new_row.find('label:first').hide();
|
|
form.find('p.readout:visible a.icon-del').show();
|
|
}
|
|
|
|
function deleteReadout() {
|
|
var form = $(event.target).closest('form');
|
|
var row = $(event.target).closest('p.readout');
|
|
if (row.find('input[id$=__id]').val()) {
|
|
row.hide();
|
|
row.find('input[id$=__destroy]').val('1');
|
|
} else {
|
|
row.remove();
|
|
}
|
|
form.find('p.readout:visible:first label:first').show();
|
|
if (form.find('p.readout:visible').length <= 1) {
|
|
form.find('p.readout:visible a.icon-del').hide();
|
|
}
|
|
}
|
|
<% end %>
|