Added custom fields to track number or % values. #1348

This commit is contained in:
Eric Davis
2008-06-19 17:23:39 -07:00
parent ab67d20fcf
commit 3dea68522e
2 changed files with 15 additions and 5 deletions
+12 -2
View File
@@ -3,10 +3,10 @@ module DeliverablesHelper
# Helper to generate a form used to calculate the total budget while editing
# a Deliverable
# 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(: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(:span,
0,
@@ -17,6 +17,16 @@ module DeliverablesHelper
))
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
def paragraph_with_data(label, data)
+3 -3
View File
@@ -64,9 +64,9 @@
</td>
</tr>
<%= field_with_budget_observer_and_totals(f, :overhead) %>
<%= field_with_budget_observer_and_totals(f, :materials) %>
<%= field_with_budget_observer_and_totals(f, :profit) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :overhead, :overhead_percent) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :materials, :materials_percent) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :profit, :profit_percent) %>
<tr class="total-budget">
<td><label>Total Budget:</label></td>