[#6574] Allow removing labor budgets

This commit is contained in:
Eric Davis committed 2011-10-11 11:44:16 -07:00
1 parent 7d0abc641a
commit d633b32b30
3 files changed
+20 -5

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ class Deliverable < ActiveRecord::Base
has_many :fixed_budgets has_many :fixed_budgets
has_many :issues, :dependent => :nullify has_many :issues, :dependent => :nullify
accepts_nested_attributes_for :labor_budgets accepts_nested_attributes_for :labor_budgets, :allow_destroy => true
accepts_nested_attributes_for :overhead_budgets accepts_nested_attributes_for :overhead_budgets
accepts_nested_attributes_for :fixed_budgets accepts_nested_attributes_for :fixed_budgets
@@ -1,5 +1,6 @@
<tr> <tr class="labor-budget-form">
<td> <td>
<%= labor_budget.hidden_field(:id) unless labor_budget.object.new_record? %>
<%= labor_budget.hidden_field(:year) %> <%= labor_budget.hidden_field(:year) %>
<%= labor_budget.hidden_field(:month) %> <%= labor_budget.hidden_field(:month) %>
@@ -15,6 +16,8 @@
<%= labor_budget.text_field(:budget, :value => format_deliverable_value_fields(labor_budget.object.budget), :class => 'financial') %> <%= labor_budget.text_field(:budget, :value => format_deliverable_value_fields(labor_budget.object.budget), :class => 'financial') %>
</td> </td>
<td class="add-labor"> <td class="add-labor">
<%= labor_budget.hidden_field "_destroy", :class=> "delete-flag" %>
<%= link_to_function("Remove", 'deleteDeliverableFinance(this)', :class => 'delete icon icon-del') %>
<%= link_to_function("Add", 'addNewDeliverableFinance("labor")', :class => 'add icon icon-add', :style => 'display:none;') %> <%= link_to_function("Add", 'addNewDeliverableFinance("labor")', :class => 'add icon icon-add', :style => 'display:none;') %>
</td> </td>
</tr> </tr>
+15 -3
View File
@@ -69,16 +69,28 @@ jQuery(function($) {
}, },
showDeliverableAddButton = function() { showDeliverableAddButton = function() {
$('.add-labor a.add').hide().last().show(); $('table .add-labor a.add').hide().last().show();
}, },
addNewDeliverableFinance = function(financeType) { addNewDeliverableFinance = function(financeType) {
var t = $('#labor-budget-template').tmpl({}); var t = $('#labor-budget-template').tmpl({});
var countOfExisting = $("#deliverable-labor tbody tr").size(); var countOfExisting = $("tr.labor-budget-form").size();
var recordLocation = countOfExisting + 1; // increments the Rails [n] placeholder var recordLocation = countOfExisting + 1; // increments the Rails [n] placeholder
var newContent = t.html().replace(/\[0\]/g, "[" + recordLocation + "]"); var newContent = t.html().replace(/\[0\]/g, "[" + recordLocation + "]");
$("<tr>" + newContent + '</tr>').appendTo('#deliverable-labor tbody'); $("<tr class='labor-budget-form'>" + newContent + '</tr>').appendTo('#deliverable-labor tbody');
showDeliverableAddButton();
},
deleteDeliverableFinance = function(deleteLink) {
// Set the deleted flag for Rails and move it out of the row
$(deleteLink).parent().find('.delete-flag').val('1')
$(deleteLink).closest("form").
append(
$(deleteLink). // <a>
parent(). // <td>
parent().hide()
) // <tr>
showDeliverableAddButton(); showDeliverableAddButton();
}, },