diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index a2903b8..27ab643 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -2,7 +2,7 @@ class MeasurementsController < ApplicationController menu_item :body_trackers before_action :find_project_by_project_id, only: [:index, :create] - before_action :find_measurement, only: [:destroy, :retake] + before_action :find_measurement, only: [:edit, :update, :destroy, :retake] before_action :authorize def index @@ -25,6 +25,19 @@ class MeasurementsController < ApplicationController end end + def edit + prepare_measurements + render :index + end + + def update + if @measurement.update(measurement_params) + flash[:notice] = 'Updated measurement' + end + prepare_measurements + render :index + end + def destroy # FIXME: don't destroy if there are any readout values if @measurement.destroy diff --git a/app/views/measurements/_index.html.erb b/app/views/measurements/_index.html.erb index 5021bee..5d41ef6 100644 --- a/app/views/measurements/_index.html.erb +++ b/app/views/measurements/_index.html.erb @@ -2,8 +2,8 @@
<%= l(:field_name) %> | <%= l(:field_taken_at_date) %> | +<%= l(:field_name) %> | <%= l(:field_source) %> | <%= l(:field_action) %> |
---|---|---|---|---|
<%= m.name %> | <%= m.taken_at.strftime("%F %R") %> | +<%= m.name %> | <%= m.source.name if m.source.present? %> | <%= link_to l(:button_retake), retake_measurement_path(m), { - remote: true, - class: "icon icon-reload" - } %> + remote: true, + class: "icon icon-reload" + } %> + <%= link_to l(:button_edit), edit_measurement_path(m), { + remote: true, + class: "icon icon-edit" + } %> <%= delete_link measurement_path(m), {remote: true, data: {}} %> |
+
+ <%= labelled_form_for @measurement,
+ url: measurement_path(@measurement),
+ method: :patch, remote: true,
+ html: {id: 'measurement-edit-form', name: 'measurement-edit-form'} do |f| %>
+
+ <%= render partial: 'measurements/form', locals: {f: f} %>
+
+
+
+
+ <% end %>
+ + <%= submit_tag l(:button_save) %> + <%= link_to l(:button_cancel), "#", + onclick: '$(this).closest("tr").remove(); return false;' %> + + |
+