5 include( '/elements/customer-table.html',
8 'header' => [ '#', 'Item' ],
11 sub { my ($row,$param) = @_;
12 $param->{"column$row"};
15 'sizes' => [], # sizes ignored for immutable
16 'types' => ['immutable', ''], # immutable or ''/text
17 'param' => { column0 => 1 }, # preset column of row 0 to 1
22 <SCRIPT TYPE="text/javascript">
24 function clearhint_custnum() {
26 if ( this.value == 'Not found' || this.value == 'Multiple' ) {
28 this.style.color = '#000000';
33 function clearhint_customer() {
35 this.style.color = '#000000';
37 if ( this.value == '(last name or company)' || this.value == 'Not found' )
42 function <% $opt{prefix} %>search_custnum() {
44 this.style.color = '#000000'
46 var custnum_obj = this;
47 var searchrow = this.getAttribute('rownum');
48 var custnum = this.value;
50 if ( custnum == 'searching...' || custnum == 'Not found' || custnum == '' )
53 if ( this.getAttribute('magic') == 'nosearch' ) {
54 this.setAttribute('magic', '');
58 if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
59 <% $opt{prefix} %>addRow();
61 var customer = document.getElementById('customer'+searchrow);
62 customer.value = 'searching...';
63 customer.disabled = true;
64 customer.style.color = '#000000';
65 customer.style.backgroundColor = '#dddddd';
67 var customer_select = document.getElementById('cust_select'+searchrow);
69 customer.style.display = '';
70 customer_select.style.display = 'none';
72 function search_custnum_update(name) {
74 var name = eval('(' + name + ')' );
76 customer.disabled = false;
77 customer.style.backgroundColor = '#ffffff';
79 if ( name.length > 0 ) {
80 customer.value = name;
81 customer.setAttribute('magic', 'nosearch');
83 customer.value = 'Not found';
84 customer.style.color = '#ff0000';
85 custnum_obj.style.color = '#ff0000';
91 custnum_search( custnum, search_custnum_update );
95 function <% $opt{prefix} %>search_customer() {
97 var customer_obj = this;
98 var searchrow = this.getAttribute('rownum');
99 var customer = this.value;
101 if ( customer == 'searching...' || customer == 'Not found' || customer == '' )
104 if ( this.getAttribute('magic') == 'nosearch' ) {
105 this.setAttribute('magic', '');
109 if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
110 <% $opt{prefix} %>addRow();
113 var custnum_obj = document.getElementById('custnum'+searchrow);
114 custnum_obj.value = 'searching...';
115 custnum_obj.disabled = true;
116 custnum_obj.style.color = '#000000';
117 custnum_obj.style.backgroundColor = '#dddddd';
119 var customer_select = document.getElementById('cust_select'+searchrow);
121 function search_customer_update(customers) {
123 var customerArray = eval('(' + customers + ')');
125 custnum_obj.disabled = false;
126 custnum_obj.style.backgroundColor = '#ffffff';
128 if ( customerArray.length == 0 ) {
130 custnum_obj.value = 'Not found';
131 custnum_obj.style.color = '#ff0000';
132 customer_obj.style.color = '#ff0000';
134 customer_obj.style.display = '';
135 customer_select.style.display = 'none';
138 } else if ( customerArray.length == 1 ) {
140 custnum_obj.value = customerArray[0][0];
141 customer_obj.value = customerArray[0][1];
143 customer_obj.style.display = '';
144 customer_select.style.display = 'none';
149 custnum_obj.value = 'Multiple'; // or something
150 custnum_obj.style.color = '#ff0000';
152 //blank the current list
153 for ( var i = customer_select.length; i >= 0; i-- )
154 customer_select.options[i] = null;
156 opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
158 //add the multiple customers
159 for ( var s = 0; s < customerArray.length; s++ )
160 opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000');
162 opt(customer_select, 'cancel', '(Edit search string)', '#000000');
164 customer_obj.style.display = 'none';
166 customer_select.style.display = '';
172 smart_search( customer, search_customer_update );
176 function select_customer() {
178 var custnum = this.options[this.selectedIndex].value;
179 var customer = this.options[this.selectedIndex].text;
181 var searchrow = this.getAttribute('rownum');
182 var custnum_obj = document.getElementById('custnum'+searchrow);
183 var customer_obj = document.getElementById('customer'+searchrow);
185 if ( custnum == '' ) {
187 } else if ( custnum == 'cancel' ) {
189 custnum_obj.value = '';
190 custnum_obj.style.color = '#000000';
192 this.style.display = 'none';
193 customer_obj.style.display = '';
194 customer_obj.focus();
198 custnum_obj.value = custnum;
199 custnum_obj.style.color = '#000000';
201 customer_obj.value = customer;
202 customer_obj.style.color = '#000000';
204 this.style.display = 'none';
205 customer_obj.style.display = '';
211 function opt(what,value,text,color) {
212 var optionName = new Option(text, value, false, false);
213 optionName.style.color = color;
214 var length = what.length;
215 what.options[length] = optionName;
220 <TABLE ID="<% $opt{prefix} %>OneTrueTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
225 % foreach my $header ( @{$opt{header}} ) {
226 <TH><% $header %></TH>
230 % for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) {
235 <INPUT TYPE="text" NAME="custnum<% $row %>" ID="custnum<% $row %>" SIZE=8 MAXLENGTH=12 VALUE="<% $param->{"custnum$row"} %>" rownum="<% $row %>">
236 <SCRIPT TYPE="text/javascript">
237 var custnum_input<% $row %> = document.getElementById("custnum<% $row %>");
238 custnum_input<% $row %>.onfocus = clearhint_custnum;
239 custnum_input<% $row %>.onchange = <% $opt{prefix} %>search_custnum;
244 <INPUT TYPE="text" NAME="customer<% $row %>" ID="customer<% $row %>" SIZE=64 VALUE="<% $param->{"customer$row"} %>" rownum="<% $row %>">
245 <SCRIPT TYPE="text/javascript">
246 var customer_input<% $row %> = document.getElementById("customer<% $row %>");
247 customer_input<% $row %>.onfocus = clearhint_customer;
248 customer_input<% $row %>.onclick = clearhint_customer;
249 customer_input<% $row %>.onchange = <% $opt{prefix} %>search_customer;
251 <SELECT NAME="cust_select<% $row %>" ID="cust_select<% $row %>" rownum="<% $row %>" STYLE="color:#ff0000; display:none">
253 <SCRIPT TYPE="text/javascript">
254 var customer_select<% $row %> = document.getElementById("cust_select<% $row %>");
255 customer_select<% $row %>.onchange = select_customer;
260 % foreach my $field ( @{$opt{fields}} ) {
262 % if ( ref($field) eq 'CODE' ) {
263 % $value = &{$field}($row,$param);
265 % $value = $param->{"$field$row"};
267 % my $name = (ref($field) eq 'CODE') ? "column${col}_$row" : "$field$row";
268 % my $size = $sizes->[$col] || 10;
270 % if (! $types->[$col] || $types->[$col] eq 'text') {
271 <INPUT TYPE="text" NAME="<% $name %>" SIZE="<% $size %>" VALUE="<% $value %>" >
272 % } elsif ($types->[$col] eq 'immutable') {
274 <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $value %>" >
276 Cannot represent unknown type: <% $types->[$col] %>
288 <% include('/elements/xmlhttp.html',
289 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
290 'subs' => [qw( custnum_search smart_search )],
294 <SCRIPT TYPE="text/javascript">
296 var <% $opt{prefix} %>rownum = <% $row %>;
298 function <% $opt{prefix} %>addRow() {
300 var table = document.getElementById('<% $opt{prefix} %>OneTrueTable');
301 var tablebody = table.getElementsByTagName('tbody').item(0);
303 var row = document.createElement('TR');
305 var custnum_cell = document.createElement('TD');
307 var custnum_input = document.createElement('INPUT');
308 custnum_input.setAttribute('name', 'custnum'+<% $opt{prefix} %>rownum);
309 custnum_input.setAttribute('id', 'custnum'+<% $opt{prefix} %>rownum);
310 custnum_input.setAttribute('size', 8);
311 custnum_input.setAttribute('maxlength', 12);
312 custnum_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
313 custnum_input.onfocus = clearhint_custnum;
314 custnum_input.onchange = <% $opt{prefix} %>search_custnum;
315 custnum_cell.appendChild(custnum_input);
317 row.appendChild(custnum_cell);
319 var customer_cell = document.createElement('TD');
321 var customer_input = document.createElement('INPUT');
322 customer_input.setAttribute('name', 'customer'+<% $opt{prefix} %>rownum);
323 customer_input.setAttribute('id', 'customer'+<% $opt{prefix} %>rownum);
324 customer_input.setAttribute('size', 64);
325 customer_input.setAttribute('value', '(last name or company)' );
326 customer_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
327 customer_input.onfocus = clearhint_customer;
328 customer_input.onclick = clearhint_customer;
329 customer_input.onchange = <% $opt{prefix} %>search_customer;
330 customer_cell.appendChild(customer_input);
332 var customer_select = document.createElement('SELECT');
333 customer_select.setAttribute('name', 'cust_select'+<% $opt{prefix} %>rownum);
334 customer_select.setAttribute('id', 'cust_select'+<% $opt{prefix} %>rownum);
335 customer_select.setAttribute('rownum', <% $opt{prefix} %>rownum);
336 customer_select.style.color = '#ff0000';
337 customer_select.style.display = 'none';
338 customer_select.onchange = select_customer;
339 customer_cell.appendChild(customer_select);
341 row.appendChild(customer_cell);
344 % foreach my $field ( @{$opt{fields}} ) {
345 var my_cell = document.createElement('TD');
347 % if ($types->[$col] eq 'immutable') {
349 % if ( ref($field) eq 'CODE' ) {
350 % $value = &{$field}($row,$param);
352 % $value = $param->{"$field$row"};
354 var my_text = document.createTextNode('<% $value %>');
355 my_cell.appendChild(my_text);
358 var my_input = document.createElement('INPUT');
359 my_input.setAttribute('name', '<% $field %>'+<% $opt{prefix} %>rownum);
360 my_input.setAttribute('size', <% $sizes->[$col] || 10 %>);
361 % if ($types->[$col] eq 'immutable') {
362 my_input.setAttribute('type', 'hidden');
364 my_cell.appendChild(my_input);
366 row.appendChild(my_cell);
371 tablebody.appendChild(row);
373 <% $opt{prefix} %>rownum++;
377 % unless ($cgi->param('error')) {
378 <% $opt{prefix} %>addRow();
386 $opt{prefix} = '' unless defined $opt{prefix};
387 $opt{prefix} .= '_' if $opt{prefix};
389 my $types = $opt{'types'} ? [ @{$opt{'types'}} ] : [];
390 my $sizes = $opt{'sizes'} ? [ @{$opt{'sizes'}} ] : [];
392 my $param = $opt{param};
393 $param = $cgi->Vars if $cgi->param('error');