WIP: Targets configurable with Quantities
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
<label for="goal_id"><%= l(:field_goal) %><span class="required"> *</span></label>
|
||||
<%= select_tag :goal_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),
|
||||
<%= goal_f.collection_select :id, @project.goals, :id, :name,
|
||||
{include_blank: false, required: true, label: :field_goal},
|
||||
autocomplete: 'off',
|
||||
onchange: "$.ajax({
|
||||
url: '#{goal_path(id: :goal_id)}'
|
||||
.replace('goal_id', $('#target_goal_attributes_id').val()),
|
||||
dataType: 'script'
|
||||
});
|
||||
return false;" %>
|
||||
<%= link_to l(:button_add), '#',
|
||||
onclick: "var goal_id = $('#target_goal_attributes_id').val();
|
||||
$.ajax({
|
||||
url: '#{edit_goal_path(id: :goal_id)}'.replace('goal_id', goal_id),
|
||||
onclick: "$.ajax({
|
||||
url: '#{edit_goal_path(id: :goal_id)}'
|
||||
.replace('goal_id', $('#target_goal_attributes_id').val()),
|
||||
dataType: 'script'
|
||||
});
|
||||
return false;",
|
||||
class: 'icon icon-add' %>
|
||||
<% if @goal.description? %>
|
||||
<p style='white-space: pre-wrap;' ><%= @goal.description %></p>
|
||||
<% if goal_f.object.description? %>
|
||||
<p style='white-space: pre-wrap;' ><%= goal_f.object.description %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
{autocomplete: 'off',
|
||||
data: {remote: true,
|
||||
url: parents_project_quantities_path(@project),
|
||||
params: "form=#{f.options[:html][:id]}"}}
|
||||
%></p>
|
||||
params: "form=#{f.options[:html][:id]}"}} %></p>
|
||||
<p><%= f.select :parent_id, parent_options(@quantity.domain),
|
||||
{required: true, label: :field_parent_quantity, include_blank: t('.null_parent')} %></p>
|
||||
<p><%= f.text_field :name, size: 25, required: true %></p>
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
<div class="box">
|
||||
<div id='goal-form' class="tabular">
|
||||
<% if @goal.persisted? %>
|
||||
<p><%= render partial: 'goals/show_form' %></p>
|
||||
<p><%= f.date_field :effective_from, disabled: !@goal.is_binding? %></p>
|
||||
<% if goal_f.object.persisted? %>
|
||||
<p><%= render partial: 'goals/show_form', locals: {goal_f: goal_f} %></p>
|
||||
<p><%= goal_f.date_field :effective_from, value: @effective_from,
|
||||
disabled: !goal_f.object.is_binding? %></p>
|
||||
<% else %>
|
||||
<%= render partial: 'goals/form' %>
|
||||
<% end %>
|
||||
@@ -13,34 +14,30 @@
|
||||
<hr style="width: 95%;">
|
||||
|
||||
<div class="tabular">
|
||||
<% @targets.each do |target| %>
|
||||
<p class="target">
|
||||
<%= f.fields_for 'targets', target, index: '' do |target_f| %>
|
||||
<%= target_f.hidden_field :id %>
|
||||
<%= target_f.hidden_field :_destroy %>
|
||||
<em class="info"><%= t ".choose_quantity" %></em>
|
||||
<% target.thresholds.each_with_index do |thr, index| %>
|
||||
<%= target_f.fields_for 'thresholds_attributes', thr, index: '' do |threshold_f| %>
|
||||
<%= threshold_f.hidden_field :id %>
|
||||
<% if index == 0 %>
|
||||
<%= threshold_f.select :quantity_id, quantity_options,
|
||||
{include_blank: true, required: true, label: :field_target},
|
||||
onchange: "showQuantityPath(event);" %>
|
||||
<%= target_f.select :condition, condition_options, required: true,
|
||||
label: '' %>
|
||||
<% end %>
|
||||
<%= threshold_f.number_field :value, {size: 8, step: :any, label: ''} %>
|
||||
<% if index == 0 %>
|
||||
<%= threshold_f.select :unit_id, unit_options, {label: ''} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= link_to t(".button_delete_target"), '#', class: 'icon icon-del',
|
||||
style: (@targets.many? ? "" : "display:none"),
|
||||
onclick: "deleteTarget(); return false;" %>
|
||||
<p class="target">
|
||||
<%= goal_f.fields_for :targets, @targets, child_index: '' do |target_f| %>
|
||||
<%= target_f.hidden_field :_destroy %>
|
||||
<em class="info"><%= t ".choose_quantity" %></em>
|
||||
<%= target_f.select :quantity_id, quantity_options,
|
||||
{include_blank: true, required: true, label: :field_target},
|
||||
onchange: "showQuantityPath(event);" %>
|
||||
|
||||
<%= target_f.fields_for :thresholds do |threshold_f| %>
|
||||
<%= render partial: 'thresholds/form', locals: {threshold_f: threshold_f} %>
|
||||
<% end %>
|
||||
</p>
|
||||
<% last_quantity = target_f.object.thresholds.last.quantity %>
|
||||
<% unless last_quantity.leaf? %>
|
||||
<%= target_f.fields_for 'thresholds_attributes', Threshold.new do |threshold_f| %>
|
||||
<%= render partial: 'thresholds/form',
|
||||
locals: {threshold_f: threshold_f, parent: last_quantity} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to t(".button_delete_target"), '#', class: 'icon icon-del',
|
||||
style: (@targets.many? ? "" : "display:none"),
|
||||
onclick: "deleteTarget(); return false;" %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<%= link_to t(".button_new_target"), '#', class: 'icon icon-add',
|
||||
onclick: 'newTarget(); return false;' %>
|
||||
@@ -50,10 +47,11 @@
|
||||
|
||||
<%= javascript_tag do %>
|
||||
function showQuantityPath(event) {
|
||||
$(event.target).prevAll('em').text($('option:selected', event.target).attr('data-path'));
|
||||
$(event.target).prevAll('em').text($('option:selected', event.target)
|
||||
.attr('data-path'));
|
||||
}
|
||||
$(document).ajaxComplete(function() {
|
||||
$('select[id$=__quantity_id]').trigger(jQuery.Event('change'));
|
||||
$('p.target select:first-child[id$=__quantity_id]').trigger(jQuery.Event('change'));
|
||||
})
|
||||
|
||||
function newTarget() {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<h2><%= t ".heading_new_target" %></h2>
|
||||
|
||||
<%= labelled_form_for @targets,
|
||||
<%= labelled_form_for @goal,
|
||||
url: project_targets_path(@project, @view_params),
|
||||
remote: true,
|
||||
html: {id: 'new-target-form', name: 'new-target-form'} do |f| %>
|
||||
html: {id: 'new-target-form', name: 'new-target-form'} do |goal_f| %>
|
||||
|
||||
<%= render partial: 'targets/form', locals: {f: f} %>
|
||||
<%= render partial: 'targets/form', locals: {goal_f: goal_f} %>
|
||||
|
||||
<div class="tabular">
|
||||
<p>
|
||||
|
||||
5
app/views/targets/subthresholds.js.erb
Normal file
5
app/views/targets/subthresholds.js.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<% if @threshold %>
|
||||
$('#targets').html('<%= j render partial: 'targets/index' %>');
|
||||
<% else %>
|
||||
$(event.target).empty();
|
||||
<% end %>
|
||||
15
app/views/thresholds/_form.html.erb
Normal file
15
app/views/thresholds/_form.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<% threshold_q = threshold_f.object.quantity %>
|
||||
<% parent_id = defined?(parent) ? parent.id : threshold_q.parent_id %>
|
||||
<%= threshold_f.collection_select :quantity_id,
|
||||
@project.quantities.target.children_of(parent_id),
|
||||
:id, :name,
|
||||
{prompt: parent_id.nil? ? false : '.', required: true, no_label: true},
|
||||
{autocomplete: 'off', data: {remote: true,
|
||||
url: subthresholds_quantity_path(@project)}} %>
|
||||
|
||||
<% unless threshold_q.nil? %>
|
||||
<%= threshold_f.hidden_field :_destroy %>
|
||||
<%= threshold_f.number_field :value, {size: 8, step: :any, no_label: true} %>
|
||||
<%= threshold_f.collection_select :unit_id, @project.units, :id, :shortname,
|
||||
{no_label: true} %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user