diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index b673771..d6ec691 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -9,6 +9,7 @@ class Deliverable < ActiveRecord::Base attr_accessor :profit attr_accessor :cost_per_hour attr_accessor :total_hours + attr_accessor :fixed_cost # TODO: mocked def score diff --git a/app/views/deliverables/_form.html.erb b/app/views/deliverables/_form.html.erb index 11dbded..d1387a6 100644 --- a/app/views/deliverables/_form.html.erb +++ b/app/views/deliverables/_form.html.erb @@ -21,16 +21,23 @@ <%= check_box(:deliverable, :type, {}, FixedDeliverable.name, HourlyDeliverable.name) %>

+ <%= observe_field('deliverable_type', :function => "new Budget.changeType();") %> -

<%= f.text_field :cost_per_hour, :size => 7 %>

+

<%= f.text_field :cost_per_hour, :size => 7 %>

<%= observe_field('deliverable_cost_per_hour', :function => "new Budget.updateAmounts();") %> -

+

<%= f.text_field :total_hours, :size => 7 %> <%= content_tag(:span, 0, :class => "budget-calculation", :id => 'variableCost') %>

<%= observe_field('deliverable_total_hours', :function => "new Budget.updateAmounts();") %> + + <%= observe_field('deliverable_fixed_cost', :function => "new Budget.updateAmounts();") %> + <%= field_with_budget_observer_and_totals(f, :overhead) %> <%= field_with_budget_observer_and_totals(f, :materials) %> <%= field_with_budget_observer_and_totals(f, :profit) %> @@ -122,6 +129,20 @@ Object.extend(BudgetModule.prototype, { } }, + changeType: function() { + if ($('deliverable_type').checked) { + // Fixed + $$('.budget-hourly').each(function(ele) { ele.hide(); }); + $$('.budget-fixed').each(function(ele) { ele.show(); }); + } else { + // Variable + $$('.budget-hourly').each(function(ele) { ele.show(); }); + $$('.budget-fixed').each(function(ele) { ele.hide(); }); + } + + Budget.updateAmounts(); + }, + // Rails-like number_to_currency currency formatting // http://snippets.dzone.com/posts/show/4646 number_to_currency: function (number, options) {