1
0

Preliminary Target #new support

This commit is contained in:
cryptogopher
2020-06-27 21:52:32 +02:00
parent 1dd2e2b596
commit 0df2c6ec4f
18 changed files with 177 additions and 26 deletions

View File

@@ -25,7 +25,7 @@
<%= f.fields_for 'nutrients_attributes', n, index: '' do |ff| %>
<p class="nutrient">
<%= ff.hidden_field :id %>
<%= ff.select :quantity_id, quantity_options,
<%= ff.select :quantity_id, quantity_options(:diet),
{include_blank: true, required: true, label: (index > 0 ? '' : :field_nutrients)} %>
<%= ff.number_field :amount, {size: 8, min: 0, step: :any, label: ''} %>
<%= ff.select :unit_id, unit_options, {label: ''} %>

View File

@@ -0,0 +1,13 @@
<div class="tabular">
<%= fields_for 'measurement[routine_attributes]', routine do |ff| %>
<%= ff.hidden_field :id %>
<p>
<label><%= l(:field_name) %><span class="required"> *</span></label>
<%= ff.text_field :name, required: true, style: "width: 95%;" %>
</p>
<p>
<label><%= l(:field_description) %></label>
<%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %>
</p>
<% end %>
</div>

View File

@@ -0,0 +1,27 @@
<div>
<%= fields_for 'target[goal_attributes]', goal do |ff| %>
<p>
<label><%= l(:field_goal) %><span class="required"> *</span></label>
<%= ff.select :id,
options_from_collection_for_select(@project.goals, :id, :name, goal.id),
{required: true}, autocomplete: 'off',
onchange: "var goal_id = $('#target_goal_attributes_id').val();
$.ajax({
url: '#{goal_path(id: :goal_id)}'.replace('goal_id', goal_id),
dataType: 'script'
});
return false;" %>
<%= link_to l(:button_edit), '#',
onclick: "var goal_id = $('#target_goal_attributes_id').val();
$.ajax({
url: '#{edit_goal_path(id: :goal_id)}'.replace('goal_id', goal_id),
dataType: 'script'
});
return false;",
class: 'icon icon-edit' %>
</p>
<% end %>
<% if goal.description? %>
<p style='white-space: pre-wrap;' ><%= goal.description %></p>
<% end %>
</div>

View File

@@ -21,7 +21,7 @@
class: 'icon icon-edit' %>
</p>
<% end %>
<% unless routine.description.empty? %>
<% if routine.description? %>
<p style='white-space: pre-wrap;' ><%= routine.description %></p>
<% end %>
</div>

View File

@@ -30,7 +30,7 @@
<%= f.fields_for 'readouts_attributes', r, index: '' do |ff| %>
<p class="readout">
<%= ff.hidden_field :id %>
<%= ff.select :quantity_id, quantity_options,
<%= ff.select :quantity_id, quantity_options(:measurement),
{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: ''} %>

View File

@@ -0,0 +1,65 @@
<%= error_messages_for @target %>
<div class="box">
<div id='goal-form' class="tabular">
<% if @target.goal.persisted? %>
<%= render partial: 'goals/show_form', locals: {goal: @target.goal} %>
<%= f.date_field(:effective_from, required: true) if @target.is_binding? %>
<% else %>
<%= render partial: 'goals/form', locals: {goal: @target.goal} %>
<% end %>
</div>
<hr style="width: 95%;">
<div class="tabular">
<p class="target">
<% @target.thresholds.each_with_index do |t, index| %>
<%= f.fields_for 'thresholds_attributes', t, index: '' do |ff| %>
<% if index == 0 %>
<%= ff.select :quantity_id, quantity_options,
{include_blank: true, required: true, label: :field_target} %>
<%= f.select :condition, condition_options, required: true %>
<% end %>
<%= ff.hidden_field :id %>
<%= ff.number_field :value, {size: 8, step: :any, label: ''} %>
<% if index == 0 %>
<%= ff.select :unit_id, unit_options, {label: ''} %>
<% end %>
<% end %>
<% end %>
<%= link_to t(".button_delete_target"), '#',
class: 'icon icon-del',
onclick: "deleteTarget(); return false;" %>
</p>
<%= link_to t(".button_new_target"), '#',
class: 'icon icon-add',
onclick: 'newTarget(); return false;' %>
</div>
</div>
<%= 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 %>

View File

@@ -0,0 +1,18 @@
<h2><%= t ".heading_new_target" %></h2>
<%= labelled_form_for @target,
url: project_targets_path(@project, @view_params),
remote: true,
html: {id: 'new-target-form', name: 'new-target-form'} do |f| %>
<%= render partial: 'targets/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: '$("#new-target").empty(); return false;' %>
</p>
</div>
<% end %>
<hr>

View File

@@ -0,0 +1 @@
$('#new-target').html('<%= j render partial: 'targets/new_form' %>');