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:
1 parent
3dea68522e
commit
e5822befb0
2 files changed
+8
-7
No files matched your search
@@ -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, object, field, percent_field)
|
def field_with_budget_observer_and_totals(form, object, field, percent_field, default_value='')
|
||||||
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, 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(:td,
|
||||||
content_tag(:span,
|
content_tag(:span,
|
||||||
0,
|
0,
|
||||||
@@ -18,14 +18,15 @@ module DeliverablesHelper
|
|||||||
|
|
||||||
end
|
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
|
# 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,
|
return text_field_tag('deliverable_' + number_field.to_s,
|
||||||
object.read_attribute(percent_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?
|
options.merge({ :name => "deliverable[#{number_field.to_s}]"})) unless object.read_attribute(percent_field).blank?
|
||||||
|
|
||||||
# Number and fallback with no values
|
# 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
|
end
|
||||||
|
|
||||||
# Helper to generate a consistant HTML format for displaying basic data
|
# Helper to generate a consistant HTML format for displaying basic data
|
||||||
|
|||||||
@@ -64,9 +64,9 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<%= field_with_budget_observer_and_totals(f, @deliverable, :overhead, :overhead_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) %>
|
<%= 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) %>
|
<%= field_with_budget_observer_and_totals(f, @deliverable, :profit, :profit_percent, @settings[:budget_profit]) %>
|
||||||
|
|
||||||
<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