X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fcustomer-table.html;h=090623ff90d0844ca5b5dac29280d46cfd05ca46;hb=b6260b4f39cf34b9e0e5b8560ef88c8881ba0766;hp=b49bf0290069fb58afc9754038e69a95b0ab3c3e;hpb=05364e1a107233d35792a76bf6d23d00dd5611cf;p=freeside.git diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html index b49bf0290..090623ff9 100644 --- a/httemplate/elements/customer-table.html +++ b/httemplate/elements/customer-table.html @@ -41,6 +41,8 @@ Example: - - - - - - - - - -% foreach my $header ( @{$opt{header}} ) { - -% } - -% my $row = 0; -% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { - - - - - - - - - - - + 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); + } -% 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++; -% } - -% } + 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(); + } - - -% 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++; + function <% $opt{prefix} %>deleteRow() { + var thisrownum = this.getAttribute('rownum'); +% if ( $opt{delete_row_callback} ) { + // callback + <% $opt{delete_row_callback} %>(thisrownum,'<% $opt{prefix} %>'); % } - - -
Inv #Cust #StatusCustomerBalance<% $header %>
- " - 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 )], - ) -%> - - -% unless ($cgi->param('error')) { - <% $opt{prefix} %>addRow(); + + + + + + + + +% 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};