diff --git a/app/views/ingredients/_contextual.html.erb b/app/views/ingredients/_contextual.html.erb index 4d50933..b57c92f 100644 --- a/app/views/ingredients/_contextual.html.erb +++ b/app/views/ingredients/_contextual.html.erb @@ -1,6 +1,6 @@ <% if User.current.allowed_to?(:manage_common, @project) %> - <%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-multiple', + <%= link_to t(".link_import_ingredients"), '#', :class => 'icon icon-multiple', :onclick => '$("#import-ingredients").show(); $("#filename").focus(); return false;' %> - <%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add', + <%= link_to t(".link_new_ingredient"), '#', :class => 'icon icon-add', :onclick => '$("#add-ingredient").show(); $("#ingredient_name").focus(); return false;' %> <% end %> diff --git a/app/views/measurements/_form.html.erb b/app/views/measurements/_form.html.erb new file mode 100644 index 0000000..e47e2f8 --- /dev/null +++ b/app/views/measurements/_form.html.erb @@ -0,0 +1,59 @@ +
> +

<%= t ".heading_new_measurement" %>

+ + <%= labelled_form_for @measurement, + :url => project_measurements_path(@project), + :html => {:id => 'measurement-form'} do |f| %> + <%= error_messages_for @measurement %> + +
+

<%= f.text_field :name, size: 40, required: true %>

+

<%= f.select :source_id, source_options, required: false, include_blank: true %>

+ <% @measurements.readouts.each_with_index do |r, index| %> + <%= f.fields_for 'readouts_attributes', r, index: '' do |ff| %> +

+ <%= ff.select :quantity_id, quantity_options, + {include_blank: true, label: (index > 0 ? '' : :field_readouts)} %> + <%= 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;" %> +

+ <% end %> + <% end %> +

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

+
+ <%= submit_tag l(:button_create) %> + <%= link_to l(:button_cancel), "#", :onclick => '$("#add-measurement").hide()' %> + <% end %> +
+
+ +<%= javascript_tag do %> + function addReadout() { + var row = $('p.readout:visible:last'); + var new_row = row.clone().insertAfter(row); + new_row.find('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 %> diff --git a/app/views/measurements/_list.html.erb b/app/views/measurements/_list.html.erb new file mode 100644 index 0000000..2f3d649 --- /dev/null +++ b/app/views/measurements/_list.html.erb @@ -0,0 +1,34 @@ +<% if @measurements.any? { |m| m.persisted? } %> + + + + + + + + + + <% @measurements.each do |m| %> + <% next if m.new_record? %> + + + + + + <% end %> + +
<%= l(:field_name) %><%= l(:field_source) %><%= l(:field_action) %>
+ <%= link_to '', toggle_measurement_path(m), { + remote: true, + method: :post, + class: "icon icon-eye" + } %> + <%= m.name %> + + <%= m.source.name if m.source.present? %> + + <%= delete_link measurement_path(m), {remote: true, data: {}} %> +
+<% else %> +

<%= l(:label_no_data) %>

+<% end %> diff --git a/app/views/measurements/index.html.erb b/app/views/measurements/index.html.erb index c32b768..9ca440b 100644 --- a/app/views/measurements/index.html.erb +++ b/app/views/measurements/index.html.erb @@ -1 +1,17 @@ -

MeasurementsController#index

+<% content_for :sidebar do %> + <%= render :partial => 'body_trackers/sidebar' %> +<% end %> + +
+ <% if User.current.allowed_to?(:manage_common, @project) %> + <%= link_to t(".link_new_measurement"), '#', :class => 'icon icon-add', + :onclick => '$("#add-measurement").show(); $("#measurement_name").focus(); return false;' %> + <% end %> +
+ +<%= render :partial => 'measurements/form' %> + +

<%= t ".heading" %>

+
+ <%= render :partial => 'measurements/list' %> +
diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index ae0b998..372f627 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -4,7 +4,7 @@
<% if User.current.allowed_to?(:manage_common, @project) %> - <%= link_to t(".heading_new_quantity"), '#', :class => 'icon icon-add', + <%= link_to t(".link_new_quantity"), '#', :class => 'icon icon-add', :onclick => '$("#add-quantity").show(); $("#quantity_name").focus(); return false;' %> <% end %>
diff --git a/app/views/sources/index.html.erb b/app/views/sources/index.html.erb index 8a8adbf..c077c9b 100644 --- a/app/views/sources/index.html.erb +++ b/app/views/sources/index.html.erb @@ -4,7 +4,7 @@
<% if User.current.allowed_to?(:manage_common, @project) %> - <%= link_to t(".heading_new_source"), '#', :class => 'icon icon-add', + <%= link_to t(".link_new_source"), '#', :class => 'icon icon-add', :onclick => '$("#add-source").show(); $("#source_name").focus(); return false;' %> <% end %>
diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index f33212f..8af07b9 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -4,7 +4,7 @@
<% if User.current.allowed_to?(:manage_common, @project) %> - <%= link_to t(".heading_new_unit"), '#', :class => 'icon icon-add', + <%= link_to t(".link_new_unit"), '#', :class => 'icon icon-add', :onclick => '$("#add-unit").show(); $("#unit_shortname").focus(); return false;' %> <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index d8bc1a9..a01c557 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,7 @@ # English strings go here for Rails i18n en: body_trackers_menu_caption: 'Body trackers' + field_readouts: 'Readouts' field_order: 'Order' field_action: 'Action' field_reference: 'Reference' @@ -51,11 +52,14 @@ en: confirm_defaults: 'This will load default quantities and units. Continue?' measurements: form: + heading_new_measurement: 'New measurement' index: + heading: 'Measurements' + link_new_measurement: 'New measurement' ingredients: contextual: - heading_import_ingredients: 'Import' - heading_new_ingredient: 'New ingredient' + link_import_ingredients: 'Import' + link_new_ingredient: 'New ingredient' import: heading_import_ingredients: 'Import' label_import_select_csv_file: 'Select CSV file' @@ -84,11 +88,11 @@ en: sources: index: heading: 'Data sources' - heading_new_source: 'New source' + link_new_source: 'New source' quantities: index: heading: 'Quantities' - heading_new_quantity: 'New quantity' + link_new_quantity: 'New quantity' form: domains: measurement: 'measurement' @@ -100,4 +104,4 @@ en: units: index: heading: 'Units' - heading_new_unit: 'New unit' + link_new_unit: 'New unit'