X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fcustomer-table.html;h=090623ff90d0844ca5b5dac29280d46cfd05ca46;hb=b6260b4f39cf34b9e0e5b8560ef88c8881ba0766;hp=79443dc8b95ab147730587ad5691800902ea0a2e;hpb=15dbf6151b7e6e3b32e55fd6609725f650349460;p=freeside.git
diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html
index 79443dc8b..090623ff9 100644
--- a/httemplate/elements/customer-table.html
+++ b/httemplate/elements/customer-table.html
@@ -72,30 +72,33 @@ Example:
function update_customer(searchrow, customerArray) {
+ var display_custnum_obj = document.getElementById('display_custnum'+searchrow);
var custnum_obj = document.getElementById('custnum'+searchrow);
var customer = document.getElementById('customer'+searchrow);
var customer_select = document.getElementById('cust_select'+searchrow);
- custnum_obj.disabled = false;
- custnum_obj.style.backgroundColor = '#ffffff';
+ display_custnum_obj.disabled = false;
+ display_custnum_obj.style.backgroundColor = '#ffffff';
customer.disabled = false;
customer.style.backgroundColor = '#ffffff';
if ( customerArray.length == 0 ) {
- custnum_obj.value = 'Not found';
+ custnum_obj.value = '';
+ display_custnum_obj.value = 'Not found';
customer.value = 'Not found';
- custnum_obj.style.color = '#ff0000';
+ display_custnum_obj.style.color = '#ff0000';
customer.style.color = '#ff0000';
customer.style.display = '';
customer_select.style.display = 'none';
return false;
- } else if ( customerArray.length == 6 ) {
+ } else if ( customerArray.length >= 6 ) {
custnum_obj.value = customerArray[0];
- custnum_obj.style.color = '#000000';
+ display_custnum_obj.value = customerArray[6];
+ display_custnum_obj.style.color = '#000000';
customer.value = customerArray[1];
update_balance_text(searchrow, customerArray[2]);
@@ -125,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...';
@@ -139,7 +142,6 @@ Example:
customer.style.display = '';
customer_select.style.display = 'none';
- var custnum_obj = document.getElementById('custnum'+searchrow);
update_balance_text(searchrow, '');
update_status_text(searchrow, '');
update_status_color(searchrow, '#000000');
@@ -164,11 +166,12 @@ Example:
this.style.color = '#000000'
- var custnum_obj = this;
+ var display_custnum_obj = this;
var searchrow = this.getAttribute('rownum');
- var custnum = this.value;
+ var custnum_obj = document.getElementById('custnum'+searchrow);
+ var display_custnum = this.value;
- if ( custnum == 'searching...' || custnum == 'Not found' || custnum == '' )
+ if ( display_custnum == 'searching...' || display_custnum == 'Not found' || display_custnum == '' )
return;
if ( this.getAttribute('magic') == 'nosearch' ) {
@@ -176,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);
@@ -203,7 +206,11 @@ Example:
var customerArrayArray = eval('(' + customers + ')') || [];
- if ( customerArrayArray.length == 1 ) {
+ if ( customerArrayArray.length == 0 ) {
+
+ update_customer(searchrow, []);
+
+ } else if ( customerArrayArray.length == 1 ) {
update_customer(searchrow, customerArrayArray[0]);
% if ( $opt{custnum_update_callback} ) {
@@ -237,7 +244,7 @@ Example:
}
- custnum_search(custnum, search_custnum_update );
+ custnum_search(display_custnum, search_custnum_update );
}
@@ -255,14 +262,14 @@ 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);
invnum.value = '';
- var custnum_obj = document.getElementById('custnum'+searchrow);
+ var custnum_obj = document.getElementById('display_custnum'+searchrow);
custnum_obj.value = 'searching...';
custnum_obj.disabled = true;
custnum_obj.style.color = '#000000';
@@ -277,7 +284,11 @@ Example:
custnum_obj.disabled = false;
custnum_obj.style.backgroundColor = '#ffffff';
- if ( customerArrayArray.length == 1 ) {
+ if ( customerArrayArray.length == 0 ) {
+
+ update_customer(searchrow, []);
+
+ } else if ( customerArrayArray.length == 1 ) {
update_customer(searchrow, customerArrayArray[0]);
% if ( $opt{custnum_update_callback} ) {
@@ -321,6 +332,7 @@ Example:
var customer = this.options[this.selectedIndex].text;
var searchrow = this.getAttribute('rownum');
+ var display_custnum_obj = document.getElementById('display_custnum'+searchrow);
var custnum_obj = document.getElementById('custnum'+searchrow);
var customer_obj = document.getElementById('customer'+searchrow);
var balance_obj = document.getElementById('balance'+searchrow);
@@ -330,6 +342,7 @@ Example:
} else if ( custnum_balance_status == 'cancel' ) {
+ display_custnum_obj.value = '';
custnum_obj.value = '';
custnum_obj.style.color = '#000000';
@@ -372,247 +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') %>';
+ }
+ }
-
-
-
-
-
- Inv # |
- Cust # |
- Status |
- Customer |
- Balance |
-% foreach my $header ( @{$opt{header}} ) {
- <% $header %> |
-% }
-
-% my $row = 0;
-% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) {
-
-
-
- "
- rownum = "<% $row %>"
- >
-
- |
-
-
- "
- rownum = "<% $row %>"
- >
-
- |
-
-
- "
-
- ><% $param->{"status$row"} %>
- "
- rownum = "<% $row %>"
- >
- "
- rownum = "<% $row %>"
- >
- |
-
-
- " rownum="<% $row %>">
-
-
-
- |
-
-
- <% $money_char %>
- <% $param->{"balance$row"} %>
-
- "
- rownum = "<% $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");
-% }
-
-% 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] %>
-% }
- |
-% $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();
+ }
-
-
- Total <% $row ? $row-1 : 0 %>
- <% PL($opt{name_singular} || 'customer', ( $row ? $row-1 : 0 ) ) %>
- |
-% 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";
- <% sprintf('%.2f', $total[$col] ) %> |
-% } else {
- <% $footer %> |
-% }
-% $col++;
+ function <% $opt{prefix} %>deleteRow() {
+ var thisrownum = this.getAttribute('rownum');
+% if ( $opt{delete_row_callback} ) {
+ // callback
+ <% $opt{delete_row_callback} %>(thisrownum,'<% $opt{prefix} %>');
% }
-
-
-
-
-
-
-<% include('/elements/xmlhttp.html',
- 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
- 'subs' => [qw( custnum_search smart_search invnum_search )],
- )
-%>
-
-
+
+
+
+
+ Inv # |
+ Cust # |
+ Status |
+ Customer |
+ Balance |
+% foreach my $header ( @{$opt{header}} ) {
+ <% $header %> |
+% }
+
+
+% my @rownums = sort { $a <=> $b } map /^custnum(\d+)$/, keys %$param;
+
+
+ Total <% @rownums || 0 %>
+ <% PL($opt{name_singular} || 'customer', ( @rownums || 0 ) ) %>
+ |
+% 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";
+ <% sprintf('%.2f', $total[$col] ) %> |
+% } else {
+ <% $footer %> |
+% }
+% $col++;
+% }
+
+
+
+
+
+<% 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};