[#6574] Extract method from addNewDeliverableLaborItem

This commit is contained in:
Eric Davis committed 2011-10-11 14:21:18 -07:00
1 parent ca84747cb9
commit ce6c89cfa7
2 files changed
+12 -6

No files matched your search

@@ -18,6 +18,6 @@
<td class="add-labor"> <td class="add-labor">
<%= labor_budget.hidden_field "_destroy", :class=> "delete-flag" %> <%= 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_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> </td>
</tr> </tr>
+11 -5
View File
@@ -72,20 +72,26 @@ jQuery(function($) {
var addLinks = $('table.deliverable_finance_table .add-labor a.add') var addLinks = $('table.deliverable_finance_table .add-labor a.add')
if (addLinks.length == 0) { if (addLinks.length == 0) {
// No link, add a blank form // No link, add a blank form
addNewDeliverableFinance("labor"); addNewDeliverableLaborItem();
} else { } else {
addLinks.hide().last().show(); addLinks.hide().last().show();
} }
}, },
addNewDeliverableFinance = function(financeType) { addNewDeliverableLaborItem = function() {
var t = $('#labor-budget-template').tmpl({}); 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) { if (t.length > 0) {
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 class='labor-budget-form'>" + newContent + '</tr>').appendTo('#deliverable-labor tbody'); $("<tr class='" + rowClass + "'>" + newContent + '</tr>').appendTo(appendTemplateTo);
showDeliverableAddButton(); showDeliverableAddButton();
} }
}, },