Test pass: test_edit
This commit is contained in:
@@ -53,7 +53,8 @@ class TargetsController < ApplicationController
|
||||
end
|
||||
|
||||
def edit
|
||||
@targets = @goal.targets.where(effective_from: params[:effective_from])
|
||||
@targets = @goal.targets.where(effective_from: params[:date]).to_a
|
||||
@effective_from = @targets.first&.effective_from
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
15
app/views/targets/_edit_form.html.erb
Normal file
15
app/views/targets/_edit_form.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<%= labelled_form_for @targets,
|
||||
url: project_targets_path(@project, @view_params),
|
||||
method: :patch, remote: true,
|
||||
html: {id: 'edit-target-form', name: 'edit-target-form'} do |f| %>
|
||||
|
||||
<%= render partial: 'targets/form', locals: {f: f} %>
|
||||
|
||||
<div class="tabular">
|
||||
<p>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<%= link_to l(:button_cancel), "#",
|
||||
onclick: '$(this).closest("tr").remove(); return false;' %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -57,7 +57,7 @@
|
||||
<tbody>
|
||||
<% @targets_by_date.each do |date, targets| %>
|
||||
<% row_class = "date #{cycle('odd', 'even')}" %>
|
||||
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="primary <%= row_class %>">
|
||||
<tr id="date-<%= date %>" class="primary <%= row_class %>">
|
||||
<td class="date unwrappable" style="cursor: pointer;"
|
||||
onclick="$(this).closest('tr').toggle();
|
||||
$(this).closest('tr').nextUntil('tr.primary', '.date').toggle();
|
||||
|
||||
7
app/views/targets/edit.js.erb
Normal file
7
app/views/targets/edit.js.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
$('tr[id=date-<%= @effective_from %>]').nextUntil('tr.primary', ':not(.date)').remove();
|
||||
var columns = $('table > thead > tr > th').length;
|
||||
$('tr[id=date-<%= @effective_from %>]').nextUntil('tr.primary').addBack().last().after(
|
||||
'<tr><td class="form" colspan="'+columns+'"><div id="edit-target">' +
|
||||
'<%= j render partial: 'targets/edit_form' %>' +
|
||||
'</div></td></tr>'
|
||||
);
|
||||
Reference in New Issue
Block a user