Added toggle for the fixed cost, #1135

This commit is contained in:
Eric Davis
2008-05-21 09:26:22 -07:00
parent 8548d46637
commit bdec36e7ea
2 changed files with 24 additions and 2 deletions

View File

@@ -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

View File

@@ -21,16 +21,23 @@
<label for="deliverable_type">Fixed Cost</label>
<%= check_box(:deliverable, :type, {}, FixedDeliverable.name, HourlyDeliverable.name) %>
</p>
<%= observe_field('deliverable_type', :function => "new Budget.changeType();") %>
<p><%= f.text_field :cost_per_hour, :size => 7 %></p>
<p class="budget-hourly"><%= f.text_field :cost_per_hour, :size => 7 %></p>
<%= observe_field('deliverable_cost_per_hour', :function => "new Budget.updateAmounts();") %>
<p>
<p class="budget-hourly">
<%= f.text_field :total_hours, :size => 7 %>
<%= content_tag(:span, 0, :class => "budget-calculation", :id => 'variableCost') %>
</p>
<%= observe_field('deliverable_total_hours', :function => "new Budget.updateAmounts();") %>
<p class="budget-fixed" style="display:none;">
<%= f.text_field :fixed_cost, :size => 7 %>
<%= content_tag(:span, 0, :class => "budget-calculation", :id => 'fixedCost') %>
</p>
<%= 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) {