Added custom fields to track number or % values. #1348
This commit is contained in:
@@ -3,10 +3,10 @@ module DeliverablesHelper
|
|||||||
# Helper to generate a form used to calculate the total budget while editing
|
# Helper to generate a form used to calculate the total budget while editing
|
||||||
# a Deliverable
|
# a Deliverable
|
||||||
# TODO Later: Refactor since observers are not used anymore
|
# TODO Later: Refactor since observers are not used anymore
|
||||||
def field_with_budget_observer_and_totals(form, field)
|
def field_with_budget_observer_and_totals(form, object, field, percent_field)
|
||||||
content_tag(:tr,
|
content_tag(:tr,
|
||||||
content_tag(:td, "<label for='deliverable_#{field.to_s}'>#{l_field(field, 'field_')}</label>") +
|
content_tag(:td, "<label for='deliverable_#{field.to_s}'>#{l_field(field, 'field_')}</label>") +
|
||||||
content_tag(:td, text_field(:deliverable, field, :size => 7)) +
|
content_tag(:td, number_or_percent_field(object, field, percent_field, :size => 7)) +
|
||||||
content_tag(:td,
|
content_tag(:td,
|
||||||
content_tag(:span,
|
content_tag(:span,
|
||||||
0,
|
0,
|
||||||
@@ -17,6 +17,16 @@ module DeliverablesHelper
|
|||||||
))
|
))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def number_or_percent_field(object, number_field, percent_field, options)
|
||||||
|
# Build a text_field by hand named after the number field but with the percent_field and % as the value
|
||||||
|
return text_field_tag('deliverable_' + number_field.to_s,
|
||||||
|
object.read_attribute(percent_field).to_s + "%",
|
||||||
|
options.merge({ :name => "deliverable[#{number_field.to_s}]"})) unless object.read_attribute(percent_field).blank?
|
||||||
|
|
||||||
|
# Number and fallback with no values
|
||||||
|
return text_field(:deliverable, number_field, options)
|
||||||
|
end
|
||||||
|
|
||||||
# Helper to generate a consistant HTML format for displaying basic data
|
# Helper to generate a consistant HTML format for displaying basic data
|
||||||
def paragraph_with_data(label, data)
|
def paragraph_with_data(label, data)
|
||||||
|
|||||||
@@ -64,9 +64,9 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<%= field_with_budget_observer_and_totals(f, :overhead) %>
|
<%= field_with_budget_observer_and_totals(f, @deliverable, :overhead, :overhead_percent) %>
|
||||||
<%= field_with_budget_observer_and_totals(f, :materials) %>
|
<%= field_with_budget_observer_and_totals(f, @deliverable, :materials, :materials_percent) %>
|
||||||
<%= field_with_budget_observer_and_totals(f, :profit) %>
|
<%= field_with_budget_observer_and_totals(f, @deliverable, :profit, :profit_percent) %>
|
||||||
|
|
||||||
<tr class="total-budget">
|
<tr class="total-budget">
|
||||||
<td><label>Total Budget:</label></td>
|
<td><label>Total Budget:</label></td>
|
||||||
|
|||||||
Reference in New Issue
Block a user