X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Felements%2Fcustomer-table.html;h=25c26b584a926f33beabb20b997cdb6b30130a7b;hp=f00419f9c5e9563c9acb2928c2e6c35045437af5;hb=f7b5454b52807d21d563db95a5da3a6ed0bddb25;hpb=b8d03e480cf0798c30d6d8e9ec6cf53d8f419043 diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html index f00419f9c..25c26b584 100644 --- a/httemplate/elements/customer-table.html +++ b/httemplate/elements/customer-table.html @@ -22,9 +22,10 @@ Example: ### 'name_singular' => 'customer', #label + 'custnum_update_callback' => 'name_of_js_callback' #passed a rownum #listrefs - 'types' => ['immutable', ''], # immutable or ''/text + 'type' => ['immutable', ''], # immutable, checkbox, date or ''/text 'align' => [ 'c', 'l', 'r', '' ], 'size' => [], # sizes ignored for immutable 'color' => [], @@ -36,10 +37,52 @@ Example: ) - +Some incomplete notes for javascript programmers: + +On page load, existing rows are initialized by passing values to addRow +based on existing cgi values. An empty row (marked with the 'emptyrow' +attribute) is created by invoking addRow without values. After that, +to keep the non-empty row count (totalrows) accurate, use newEmptyRow to +create the next row. There should only be one empty row at a time. + +Global vars: +total_el - element for displaying total number of rows +totalrows - total number of non-empty rows +rownum - really more of a "next row" value, used by addRow +allrows - array of tr elements, one for each row + +Don't confuse the global rownum with the element attribute rownum +that is set as a reference point on some of the elements generated +by this script. They have different values. +Some of the functions: +updateTotalRow() - updates total_el based on value of totalrows +addDeleteButton(searchrow) - adds delete button to searchrow +newEmptyRow() - replaces old empty row +deleteRow() - removes the row specified by this.rownum +addRow(values) - adds a new row (marked as empty if values aren't specified) + +This mason element is currently only used by misc/batch-cust_pay.html, +and probably should be cleaned up more before being used by anything else. + + + + + + + function update_status_text(rownum, newval) { + document.getElementById('status'+rownum).value = newval; + document.getElementById('status'+rownum+'_text').innerHTML = newval; + } - + function update_status_color(rownum, newval) { + document.getElementById('statuscolor'+rownum).value = newval; + document.getElementById('status'+rownum+'_text').style.color = newval; + } - - - -% foreach my $header ( @{$opt{header}} ) { - -% } - -% my $row = 0; -% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { - - - - - - + function update_balance_text(rownum, newval) { + document.getElementById('balance'+rownum).value = newval; + document.getElementById('balance'+rownum+'_text').innerHTML = newval; + } -% 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{footer}->[$col] eq '_TOTAL' ) { -% $total[$col] += $value; -% $onchange = $opt{prefix}. "calc_total$col();"; -% $onchange = qq(onchange="$onchange" onkeyup="$onchange"); -% } - -% $col++; -% } + function update_num_open(rownum, newval) { + document.getElementById('num_open'+rownum).value = newval; + num_open_invoices[rownum] = newval; + } - -% } + // updates display of total rows based on value of totalrows + function updateTotalRow () { + if ( totalrows == 1 ) { + total_el.innerHTML = + 'Total ' + + totalrows + + ' <% $opt{name_singular} || 'customer' %>'; + } else { + total_el.innerHTML = + 'Total ' + + totalrows + + ' <% PL($opt{name_singular} || 'customer') %>'; + } + } - - -% 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++; -% } - + var total_el, rownum, totalrows, allrows; + + function 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 = 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); + } -
Cust #Customer<% $header %>
- " - rownum = "<% $row %>" - > - - - " rownum="<% $row %>"> - - - - -% if (! $types->[$col] || $types->[$col] eq 'text') { - - > -% } 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 %>
+ function newEmptyRow (searchrow) { + // add delete button to current row + addDeleteButton(searchrow); + // mark current row as non-empty + var oldemptyrow = document.getElementById('row'+searchrow); + oldemptyrow.emptyrow = false; + // update totalrows + totalrows++ + updateTotalRow(); + // add a new empty row + addRow(); + } - - -<% include('/elements/xmlhttp.html', - 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', - 'subs' => [qw( custnum_search smart_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; +my $date_format = $conf->config('date_format') || '%m/%d/%Y'; -$opt{prefix} = '' unless defined $opt{prefix}; -$opt{prefix} .= '_' if $opt{prefix}; - -my $types = $opt{'types'} ? [ @{$opt{'types'}} ] : []; +my $types = $opt{'type'} ? [ @{$opt{'type'}} ] : []; my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; my $param = $opt{param}; @@ -521,4 +844,5 @@ my %align = ( 'c' => 'center', ); +my $money_char = $conf->config('money_char') || '$';