[#6574] Allow adding and removing Fixed Budgets
This commit is contained in:
@@ -13,7 +13,7 @@ class Deliverable < ActiveRecord::Base
|
||||
|
||||
accepts_nested_attributes_for :labor_budgets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :overhead_budgets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :fixed_budgets
|
||||
accepts_nested_attributes_for :fixed_budgets, :allow_destroy => true
|
||||
|
||||
# Validations
|
||||
validates_presence_of :title
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="fixed-budget-template">
|
||||
<% form.fields_for :fixed_budgets, resource.fixed_budgets.new(:id => 0) do |fixed_budget| %>
|
||||
<%= render :partial => 'fixed_budget_form', :locals => {:fixed_budget => fixed_budget} %>
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<% form.inputs :name => label, :class => "deliverable-finances #{fieldset_class}" do %>
|
||||
|
||||
<li style="display:none;" id='retainer-finances-message'>
|
||||
@@ -44,6 +50,7 @@
|
||||
|
||||
<% form.fields_for :fixed_budgets, fixed_budgets.sort_by(&:id) do |fixed_budget| %>
|
||||
<%= render :partial => 'fixed_budget_form', :locals => {:fixed_budget => fixed_budget} %>
|
||||
<%= wikitoolbar_for "fixed-description#{fixed_budget.object.object_id}" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<div class="fixed-budget-form">
|
||||
<%= fixed_budget.hidden_field(:id) unless fixed_budget.object.new_record? %>
|
||||
<%= fixed_budget.hidden_field(:year) %>
|
||||
<%= fixed_budget.hidden_field(:month) %>
|
||||
|
||||
@@ -22,6 +24,10 @@
|
||||
|
||||
<p class="inline-hints" style="display:none;"><%= fixed_budget.label(:description, l(:field_description), :for => "fixed-description#{fixed_budget.object.object_id}")%></p>
|
||||
<%= fixed_budget.text_area(:description, :class => 'wiki-edit', :rows => '5', :id => "fixed-description#{fixed_budget.object.object_id}") %>
|
||||
<%= wikitoolbar_for "fixed-description#{fixed_budget.object.object_id}" %>
|
||||
|
||||
<p><%= release(3, "Green Add button for multiple records") %></p>
|
||||
<p class="inline-hints add-fixed">
|
||||
<%= fixed_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), 'addNewDeliverableFixedItem()', :class => 'add icon icon-add', :style => 'display:none;') %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -83,29 +83,43 @@ jQuery(function($) {
|
||||
} else {
|
||||
overheadLinks.hide().last().show();
|
||||
}
|
||||
var fixedLinks = $('#deliverable-fixed .fixed-budget-form .add-fixed a.add')
|
||||
if (fixedLinks.length == 0) {
|
||||
// No link, add a blank form
|
||||
addNewDeliverableFixedItem();
|
||||
} else {
|
||||
fixedLinks.hide().last().show();
|
||||
}
|
||||
},
|
||||
|
||||
addNewDeliverableLaborItem = function() {
|
||||
addNewDeliverableFinance('#labor-budget-template',
|
||||
'#deliverable-labor tbody',
|
||||
$("tr.labor-budget-form").size(),
|
||||
'labor-budget-form');
|
||||
'<tr class="labor-budget-form">');
|
||||
},
|
||||
|
||||
addNewDeliverableOverheadItem = function() {
|
||||
addNewDeliverableFinance('#overhead-budget-template',
|
||||
'#deliverable-overhead tbody',
|
||||
$("tr.overhead-budget-form").size(),
|
||||
'overhead-budget-form');
|
||||
'<tr class="overhead-budget-form">');
|
||||
},
|
||||
|
||||
addNewDeliverableFinance = function(templateSelector, appendTemplateTo, countOfExisting, rowClass) {
|
||||
addNewDeliverableFixedItem = function() {
|
||||
addNewDeliverableFinance('#fixed-budget-template',
|
||||
'#deliverable-fixed.fixed-item-form',
|
||||
$("div.fixed-budget-form").size(),
|
||||
'<div class="fixed-budget-form">');
|
||||
},
|
||||
|
||||
addNewDeliverableFinance = function(templateSelector, appendTemplateTo, countOfExisting, wrapperElement) {
|
||||
var t = $(templateSelector).tmpl({});
|
||||
if (t.length > 0) {
|
||||
var recordLocation = countOfExisting + 1; // increments the Rails [n] placeholder
|
||||
var newContent = t.html().replace(/\[0\]/g, "[" + recordLocation + "]");
|
||||
|
||||
$("<tr class='" + rowClass + "'>" + newContent + '</tr>').appendTo(appendTemplateTo);
|
||||
$(wrapperElement).html(newContent).appendTo(appendTemplateTo);
|
||||
showDeliverableAddButtons();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -522,3 +522,5 @@ input.financial{
|
||||
#edit_contract_1 li#contract_billable_rate_input div{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
div.fixed-budget-form {padding: 5px 0;}
|
||||
|
||||
Reference in New Issue
Block a user