X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fcustomer-table.html;h=090623ff90d0844ca5b5dac29280d46cfd05ca46;hb=1115b9089e9d9ecf104bc61bb22e84f5233aa44b;hp=83abad0103773028aeecb5945c5b4646585d6d3c;hpb=1660ec858b01a46737682e4db86d151bf4550455;p=freeside.git diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html index 83abad010..090623ff9 100644 --- a/httemplate/elements/customer-table.html +++ b/httemplate/elements/customer-table.html @@ -128,8 +128,8 @@ Example: return; } - if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) { - <% $opt{prefix} %>addRow(); + if ( document.getElementById('row'+searchrow).emptyrow ) { + <% $opt{prefix} %>newEmptyRow(searchrow); } var customer = document.getElementById('customer'+searchrow); customer.value = 'searching...'; @@ -179,8 +179,8 @@ Example: return; } - if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) { - <% $opt{prefix} %>addRow(); + if ( document.getElementById('row'+searchrow).emptyrow ) { + <% $opt{prefix} %>newEmptyRow(searchrow); } var customer_obj = document.getElementById('customer'+searchrow); @@ -262,8 +262,8 @@ Example: return; } - if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) { - <% $opt{prefix} %>addRow(); + if ( document.getElementById('row'+searchrow).emptyrow ) { + <% $opt{prefix} %>newEmptyRow(searchrow); } var invnum = document.getElementById('invnum'+searchrow); @@ -385,253 +385,101 @@ Example: } function update_num_open(rownum, newval) { + document.getElementById('num_open'+rownum).value = newval; num_open_invoices[rownum] = newval; } + function <% $opt{prefix} %>updateTotalRow () { + if ( <% $opt{prefix} %>totalrows == 1 ) { + <% $opt{prefix} %>total_el.innerHTML = + 'Total ' + + <% $opt{prefix} %>totalrows + + ' <% $opt{name_singular} || 'customer' %>'; + } else { + <% $opt{prefix} %>total_el.innerHTML = + 'Total ' + + <% $opt{prefix} %>totalrows + + ' <% PL($opt{name_singular} || 'customer') %>'; + } + } - + var <% $opt{prefix} %>total_el, <% $opt{prefix} %>rownum, <% $opt{prefix} %>totalrows, <% $opt{prefix} %>allrows; + + function <% $opt{prefix} %>addDeleteButton (searchrow) { + var td_delete = document.getElementById('delete'+searchrow); + var button_delete = document.createElement('INPUT'); + button_delete.setAttribute('rownum', searchrow); + button_delete.setAttribute('type', 'button'); + button_delete.setAttribute('value', 'X'); + button_delete.onclick = <% $opt{prefix} %>deleteRow; + button_delete.style.color = '#ff0000'; + button_delete.style.fontWeight = 'bold'; + button_delete.style.paddingLeft = '2px'; + button_delete.style.paddingRight = '2px'; + td_delete.appendChild(button_delete); + } - + function <% $opt{prefix} %>newEmptyRow (searchrow) { + // add delete button to current row + <% $opt{prefix} %>addDeleteButton(searchrow); + // mark current row as non-empty + var oldemptyrow = document.getElementById('row'+searchrow); + oldemptyrow.emptyrow = false; + // update totalrows + <% $opt{prefix} %>totalrows++ + <% $opt{prefix} %>updateTotalRow(); + // add a new empty row + <% $opt{prefix} %>addRow(); + } - - - - - - -% foreach my $header ( @{$opt{header}} ) { - + function <% $opt{prefix} %>deleteRow() { + var thisrownum = this.getAttribute('rownum'); +% if ( $opt{delete_row_callback} ) { + // callback + <% $opt{delete_row_callback} %>(thisrownum,'<% $opt{prefix} %>'); % } - -% my $row = 0; -% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { - - - - - - - - - - - - -% my $col = 0; -% foreach my $field ( @{$opt{fields}} ) { -% my $value; -% if ( ref($field) eq 'CODE' ) { -% $value = &{$field}($row,$param); -% } else { -% $value = $param->{"$field$row"}; -% } -% my $name = (ref($field) eq 'CODE') ? "column${col}_$row" : "$field$row"; -% my $align = $align{ $opt{align}->[$col] || 'l' }; -% my $size = $sizes->[$col] || 10; -% my $color = $opt{color}->[$col]; -% my $font = $color ? qq() : ''; -% my $onchange = ''; -% if ( $opt{onchange}->[$col] ) { -% $onchange = 'onchange="'.$opt{onchange}->[$col].'"'; -% } -% elsif ( $opt{footer}->[$col] eq '_TOTAL' ) { -% $total[$col] += $value; -% $onchange = $opt{prefix}. "calc_total$col();"; -% $onchange = qq(onchange="$onchange" onkeyup="$onchange"); -% } - -% $col++; -% } - -% } - - - -% my $col = 0; -% foreach my $footer ( @{$opt{footer}} ) { -% my $align = $align{ $opt{'footer_align'}->[$col] || 'c' }; -% if ($footer eq '_TOTAL' ) { -% my $id = $opt{'fields'}->[$col]; -% $id = ref($id) ? "column${col}_TOTAL" : "${id}_TOTAL"; - -% } else { - -% } -% $col++; -% } - - -
Inv #Cust #StatusCustomerBalance<% $header %>
- " - rownum = "<% $row %>" - > - - - " - rownum = "<% $row %>" - > - " - rownum = "<% $row %>" - > - - - " - - ><% $param->{"status$row"} %> - " - rownum = "<% $row %>" - > - " - rownum = "<% $row %>" - > - - " rownum="<% $row %>"> - - - - - <% $money_char %> - <% $param->{"balance$row"} %> -   - " - rownum = "<% $row %>" - > - -% my $type = $types->[$col] || 'text'; -% if ($type eq 'text' or $type eq 'checkbox') { - - > -% } elsif ($types->[$col] eq 'immutable') { - <% $font %><% $value %><% $font ? '' : '' %> - -% } else { - Cannot represent unknown type: <% $types->[$col] %> -% } -
- Total <% $row ? $row-1 : 0 %> - <% PL($opt{name_singular} || 'customer', ( $row ? $row-1 : 0 ) ) %> -  <% sprintf('%.2f', $total[$col] ) %><% $footer %>
- - - -<% include('/elements/xmlhttp.html', - 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', - 'subs' => [qw( custnum_search smart_search invnum_search )], - ) -%> - - + + + + + + + + + +% foreach my $header ( @{$opt{header}} ) { + +% } + + +% my @rownums = sort { $a <=> $b } map /^custnum(\d+)$/, keys %$param; + + +% my $col = 0; +% foreach my $footer ( @{$opt{footer}} ) { +% my $align = $align{ $opt{'footer_align'}->[$col] || 'c' }; +% if ($footer eq '_TOTAL' ) { +% my $id = $opt{'fields'}->[$col]; +% $id = ref($id) ? "column${col}_TOTAL" : "${id}_TOTAL"; + +% } else { + +% } +% $col++; +% } + + +
Inv #Cust #StatusCustomerBalance<% $header %>
+ Total <% @rownums || 0 %> + <% PL($opt{name_singular} || 'customer', ( @rownums || 0 ) ) %> +  <% sprintf('%.2f', $total[$col] ) %><% $footer %>
+ + +<% include('/elements/xmlhttp.html', + 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', + 'subs' => [qw( custnum_search smart_search invnum_search )], + ) +%> + <%init> my(%opt) = @_; my $conf = new FS::Conf; +## caution when using prefix, it isn't consistently applied to tag id/name $opt{prefix} = '' unless defined $opt{prefix}; $opt{prefix} .= '_' if $opt{prefix};