diff --git a/app/helpers/deliverables_helper.rb b/app/helpers/deliverables_helper.rb new file mode 100644 index 0000000..e19afd9 --- /dev/null +++ b/app/helpers/deliverables_helper.rb @@ -0,0 +1,12 @@ +module DeliverablesHelper + def field_with_budget_observer_and_totals(form, field) + content_tag(:p, + form.text_field(field, :size => 7) + + content_tag(:span, + 0, + :class => "budget-calculation", + :id => 'deliverable_' + field.to_s + '_subtotal' + ) + ) + observe_field('deliverable_' + field.to_s, :function => "updateSubtotal('deliverable_#{field.to_s}'); updateBudget('deliverable_budget');") + end +end diff --git a/app/views/deliverables/_form.html.erb b/app/views/deliverables/_form.html.erb index f4d9b1d..a0e233f 100644 --- a/app/views/deliverables/_form.html.erb +++ b/app/views/deliverables/_form.html.erb @@ -19,16 +19,19 @@
TODO: Fixed cost
+<%= f.text_field :cost_per_hour, :size => 7 %>
- <%= observe_field('deliverable_cost_per_hour', :function => "updateBudget('deliverable_budget');") %> -<%= f.text_field :total_hours, :size => 7 %>
- <%= observe_field('deliverable_total_hours', :function => "updateBudget('deliverable_budget');") %> -<%= f.text_field :overhead, :size => 7 %>
- <%= observe_field('deliverable_overhead', :function => "updateBudget('deliverable_budget');") %> -<%= f.text_field :materials, :size => 7 %>
- <%= observe_field('deliverable_materials', :function => "updateBudget('deliverable_budget');") %> -<%= f.text_field :profit, :size => 7 %>
- <%= observe_field('deliverable_profit', :function => "updateBudget('deliverable_budget');") %> + <%= observe_field('deliverable_cost_per_hour', :function => "updateBaseSubtotal(); updateBudget('deliverable_budget');") %> + ++ <%= f.text_field :total_hours, :size => 7 %> + <%= content_tag(:span, 0, :class => "budget-calculation", :id => 'deliverable_base_subtotal') %> +
+ <%= observe_field('deliverable_total_hours', :function => "updateBaseSubtotal(); updateBudget('deliverable_budget');") %> + + <%= field_with_budget_observer_and_totals(f, :overhead) %> + <%= field_with_budget_observer_and_totals(f, :materials) %> + <%= field_with_budget_observer_and_totals(f, :profit) %><%= f.text_field :budget, :size => 7, :disabled => true %>