[#6574] Allow creating and deleting multiple overhead budgets
This commit is contained in:
@@ -12,7 +12,7 @@ class Deliverable < ActiveRecord::Base
|
||||
has_many :issues, :dependent => :nullify
|
||||
|
||||
accepts_nested_attributes_for :labor_budgets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :overhead_budgets
|
||||
accepts_nested_attributes_for :overhead_budgets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :fixed_budgets
|
||||
|
||||
# Validations
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="overhead-budget-template">
|
||||
<% form.fields_for :overhead_budgets, resource.overhead_budgets.new(:id => 0) do |overhead_budget| %>
|
||||
<%= render :partial => 'overhead_budget_form', :locals => {:overhead_budget => overhead_budget} %>
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<% form.inputs :name => label, :class => "deliverable-finances #{fieldset_class}" do %>
|
||||
|
||||
<li style="display:none;" id='retainer-finances-message'>
|
||||
@@ -27,8 +33,8 @@
|
||||
<tbody>
|
||||
<% form.fields_for :overhead_budgets, overhead_budgets.sort_by(&:id) do |overhead_budget| %>
|
||||
<%= render :partial => 'overhead_budget_form', :locals => {:overhead_budget => overhead_budget} %>
|
||||
</tbody>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<tr>
|
||||
<tr class="overhead-budget-form">
|
||||
<td>
|
||||
<%= overhead_budget.hidden_field(:year) %>
|
||||
<%= overhead_budget.hidden_field(:month) %>
|
||||
@@ -14,7 +14,9 @@
|
||||
<p class="inline-hints"><%= overhead_budget.label(:budget, l(:text_dollar_sign)) %></p>
|
||||
<%= overhead_budget.text_field(:budget, :value => format_deliverable_value_fields(overhead_budget.object.budget), :class => 'financial') %>
|
||||
</td>
|
||||
<td>
|
||||
<%= release(3, "Green Add button for multiple records") %>
|
||||
<td class="add-overhead">
|
||||
<%= overhead_budget.hidden_field "_destroy", :class=> "delete-flag" %>
|
||||
<%= link_to_function(l(:button_delete), 'deleteDeliverableFinance(this)', :class => 'delete icon icon-del') %>
|
||||
<%= link_to_function(l(:button_add), 'addNewDeliverableOverheadItem()', :class => 'add icon icon-add', :style => 'display:none;') %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -68,13 +68,20 @@ jQuery(function($) {
|
||||
}
|
||||
},
|
||||
|
||||
showDeliverableAddButton = function() {
|
||||
var addLinks = $('table.deliverable_finance_table .add-labor a.add')
|
||||
if (addLinks.length == 0) {
|
||||
showDeliverableAddButtons = function() {
|
||||
var laborLinks = $('table.deliverable_finance_table .add-labor a.add')
|
||||
if (laborLinks.length == 0) {
|
||||
// No link, add a blank form
|
||||
addNewDeliverableLaborItem();
|
||||
} else {
|
||||
addLinks.hide().last().show();
|
||||
laborLinks.hide().last().show();
|
||||
}
|
||||
var overheadLinks = $('table.deliverable_finance_table .add-overhead a.add')
|
||||
if (overheadLinks.length == 0) {
|
||||
// No link, add a blank form
|
||||
addNewDeliverableOverheadItem();
|
||||
} else {
|
||||
overheadLinks.hide().last().show();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -85,6 +92,13 @@ jQuery(function($) {
|
||||
'labor-budget-form');
|
||||
},
|
||||
|
||||
addNewDeliverableOverheadItem = function() {
|
||||
addNewDeliverableFinance('#overhead-budget-template',
|
||||
'#deliverable-overhead tbody',
|
||||
$("tr.overhead-budget-form").size(),
|
||||
'overhead-budget-form');
|
||||
},
|
||||
|
||||
addNewDeliverableFinance = function(templateSelector, appendTemplateTo, countOfExisting, rowClass) {
|
||||
var t = $(templateSelector).tmpl({});
|
||||
if (t.length > 0) {
|
||||
@@ -92,7 +106,7 @@ jQuery(function($) {
|
||||
var newContent = t.html().replace(/\[0\]/g, "[" + recordLocation + "]");
|
||||
|
||||
$("<tr class='" + rowClass + "'>" + newContent + '</tr>').appendTo(appendTemplateTo);
|
||||
showDeliverableAddButton();
|
||||
showDeliverableAddButtons();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -111,11 +125,11 @@ jQuery(function($) {
|
||||
parent(). // <td>
|
||||
parent().hide()
|
||||
); // <tr>
|
||||
showDeliverableAddButton();
|
||||
showDeliverableAddButtons();
|
||||
}
|
||||
},
|
||||
|
||||
showDeliverableAddButton();
|
||||
showDeliverableAddButtons();
|
||||
toggleSpecificDeliverableFields($('form.deliverable'));
|
||||
|
||||
$('select#deliverable_type').change(function() {
|
||||
|
||||
@@ -426,6 +426,7 @@ class DeliverablesEditTest < ActionController::IntegrationTest
|
||||
# * overhead hidden month
|
||||
# * overhead hours
|
||||
# * overhead amount
|
||||
# * overhead deleted (hidden)
|
||||
# * fixed hidden year
|
||||
# * fixed hidden month
|
||||
# * fixed title
|
||||
@@ -435,7 +436,7 @@ class DeliverablesEditTest < ActionController::IntegrationTest
|
||||
# * fixed paid hidden field
|
||||
# * total (hidden)
|
||||
assert_select ".date-2010-01" do
|
||||
assert_select "input", :count => 17
|
||||
assert_select "input", :count => 18
|
||||
assert_select "textarea.wiki-edit", :count => 1 # Fixed description
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user