Added the ability to pass a default value into the field_with_budget_observer_and_totals so the system defaults will appear correctly. #1351

This commit is contained in:
Eric Davis
2008-06-20 11:54:44 -07:00
parent 3dea68522e
commit e5822befb0
2 changed files with 8 additions and 7 deletions
+5 -4
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, object, field, percent_field)
def field_with_budget_observer_and_totals(form, object, field, percent_field, default_value='')
content_tag(:tr,
content_tag(:td, "<label for='deliverable_#{field.to_s}'>#{l_field(field, 'field_')}</label>") +
content_tag(:td, number_or_percent_field(object, field, percent_field, :size => 7)) +
content_tag(:td, number_or_percent_field(object, field, percent_field, default_value, :size => 7)) +
content_tag(:td,
content_tag(:span,
0,
@@ -18,14 +18,15 @@ module DeliverablesHelper
end
def number_or_percent_field(object, number_field, percent_field, options)
def number_or_percent_field(object, number_field, percent_field, default_value, 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)
value = object.read_attribute(number_field) || default_value || ''
return text_field(:deliverable, number_field, options.merge({ :value => value}))
end
# Helper to generate a consistant HTML format for displaying basic data
+3 -3
View File
@@ -64,9 +64,9 @@
</td>
</tr>
<%= 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) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :overhead, :overhead_percent, @settings[:budget_non_billable_overhead]) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :materials, :materials_percent, @settings[:budget_materials]) %>
<%= field_with_budget_observer_and_totals(f, @deliverable, :profit, :profit_percent, @settings[:budget_profit]) %>
<tr class="total-budget">
<td><label>Total Budget:</label></td>