[#6574] Extract method from addNewDeliverableLaborItem

This commit is contained in:
Eric Davis
2011-10-11 14:21:18 -07:00
parent ca84747cb9
commit ce6c89cfa7
2 changed files with 12 additions and 6 deletions
@@ -18,6 +18,6 @@
<td class="add-labor">
<%= labor_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), 'addNewDeliverableFinance("labor")', :class => 'add icon icon-add', :style => 'display:none;') %>
<%= link_to_function(l(:button_add), 'addNewDeliverableLaborItem()', :class => 'add icon icon-add', :style => 'display:none;') %>
</td>
</tr>
+11 -5
View File
@@ -72,20 +72,26 @@ jQuery(function($) {
var addLinks = $('table.deliverable_finance_table .add-labor a.add')
if (addLinks.length == 0) {
// No link, add a blank form
addNewDeliverableFinance("labor");
addNewDeliverableLaborItem();
} else {
addLinks.hide().last().show();
}
},
addNewDeliverableFinance = function(financeType) {
var t = $('#labor-budget-template').tmpl({});
addNewDeliverableLaborItem = function() {
addNewDeliverableFinance('#labor-budget-template',
'#deliverable-labor tbody',
$("tr.labor-budget-form").size(),
'labor-budget-form');
},
addNewDeliverableFinance = function(templateSelector, appendTemplateTo, countOfExisting, rowClass) {
var t = $(templateSelector).tmpl({});
if (t.length > 0) {
var countOfExisting = $("tr.labor-budget-form").size();
var recordLocation = countOfExisting + 1; // increments the Rails [n] placeholder
var newContent = t.html().replace(/\[0\]/g, "[" + recordLocation + "]");
$("<tr class='labor-budget-form'>" + newContent + '</tr>').appendTo('#deliverable-labor tbody');
$("<tr class='" + rowClass + "'>" + newContent + '</tr>').appendTo(appendTemplateTo);
showDeliverableAddButton();
}
},