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