fix legacy link (fallout from RT#22596)
[freeside.git] / httemplate / elements / customer-table.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/customer-table.html',
6
7              ###
8              # required
9              ###
10
11              #listrefs...
12              'header'        => [ '#', 'Item' ],
13              'fields'        => [
14                                   'column',
15                                   sub { my ($row,$param) = @_;
16                                         $param->{"column$row"};
17                                       },
18                                 ],
19
20              ###
21              # optional
22              ###
23
24              'name_singular' => 'customer', #label
25              'custnum_update_callback' => 'name_of_js_callback' #passed a rownum
26
27              #listrefs
28              'types'         => ['immutable', ''], # immutable or ''/text
29              'align'         => [ 'c', 'l', 'r', '' ],
30              'size'          => [],                # sizes ignored for immutable
31              'color'         => [],
32              'footer'        => ['string', '_TOTAL'], # strings or the special
33                                                       #value _TOTAL
34              'footer_align'  => [ 'c', 'l', 'r', '' ],
35
36              'param'         => { column0 => 1 },  # preset column of row 0 to 1
37
38          )
39
40 </%doc>
41
42 <SCRIPT TYPE="text/javascript">
43
44   function clearhint_invnum() {
45
46     if ( this.value == 'Not found' || this.value == 'Multiple' ) {
47       this.value = '';
48       this.style.color = '#000000';
49     }
50
51   }
52
53   function clearhint_custnum() {
54
55     if ( this.value == 'Not found' || this.value == 'Multiple' ) {
56       this.value = '';
57       this.style.color = '#000000';
58     }
59
60   }
61
62   function clearhint_customer() {
63
64     this.style.color = '#000000';
65
66     if ( this.value == '(last name or company)' || this.value == 'Not found' )
67       this.value = '';
68
69   }
70
71   function update_customer(searchrow, customerArray) {
72       
73       var custnum_obj = document.getElementById('custnum'+searchrow);
74       var customer = document.getElementById('customer'+searchrow);
75       var customer_select = document.getElementById('cust_select'+searchrow);
76
77       custnum_obj.disabled = false;
78       custnum_obj.style.backgroundColor = '#ffffff';
79       customer.disabled = false;
80       customer.style.backgroundColor = '#ffffff';
81
82       if ( customerArray.length == 0 ) {
83
84           custnum_obj.value = 'Not found';
85           customer.value = 'Not found';
86           custnum_obj.style.color = '#ff0000';
87           customer.style.color = '#ff0000';
88
89           customer.style.display = '';
90           customer_select.style.display = 'none';
91           return false;
92
93       } else if ( customerArray.length == 5 ) {
94
95           custnum_obj.value = customerArray[0];
96           custnum_obj.style.color = '#000000';
97           customer.value = customerArray[1];
98
99           update_balance_text(searchrow, customerArray[2]);
100           update_status_text( searchrow, customerArray[3]);
101           update_status_color(searchrow, '#'+customerArray[4]);
102
103           customer.style.display = '';
104           customer_select.style.display = 'none';
105           return true;
106       }
107   }
108
109   function <% $opt{prefix} %>search_invnum() {
110
111     this.style.color = '#000000'
112
113     var invnum_obj = this;
114     var searchrow = this.getAttribute('rownum');
115     var invnum = this.value;
116
117     if ( invnum == 'searching...' || invnum == 'Not found' || invnum == '' )
118       return;
119
120     if ( this.getAttribute('magic') == 'nosearch' ) {
121       this.setAttribute('magic', '');
122       return;
123     }
124
125     if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
126       <% $opt{prefix} %>addRow();
127     }
128     var customer = document.getElementById('customer'+searchrow);
129     customer.value = 'searching...';
130     customer.disabled = true;
131     customer.style.color = '#000000';
132     customer.style.backgroundColor = '#dddddd';
133
134     var customer_select = document.getElementById('cust_select'+searchrow);
135
136     customer.style.display = '';
137     customer_select.style.display = 'none';
138     
139     var custnum_obj = document.getElementById('custnum'+searchrow);
140     update_balance_text(searchrow, '');
141     update_status_text(searchrow, '');
142     update_status_color(searchrow, '#000000');
143
144     function search_invnum_update(customers) {
145       
146       var customerArray = eval('(' + customers + ')');
147       update_customer(searchrow, customerArray);
148
149 % if ( $opt{invnum_update_callback} ) {
150         <% $opt{invnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
151 % }
152
153     }
154
155     invnum_search( invnum, search_invnum_update );
156
157   }
158
159   function <% $opt{prefix} %>search_custnum() {
160
161     this.style.color = '#000000'
162
163     var custnum_obj = this;
164     var searchrow = this.getAttribute('rownum');
165     var custnum = this.value;
166
167     if ( custnum == 'searching...' || custnum == 'Not found' || custnum == '' )
168       return;
169
170     if ( this.getAttribute('magic') == 'nosearch' ) {
171       this.setAttribute('magic', '');
172       return;
173     }
174
175     if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
176       <% $opt{prefix} %>addRow();
177     }
178
179     var customer_obj = document.getElementById('customer'+searchrow);
180     customer_obj.value = 'searching...';
181     customer_obj.disabled = true;
182     customer_obj.style.color = '#000000';
183     customer_obj.style.backgroundColor = '#dddddd';
184
185     var customer_select = document.getElementById('cust_select'+searchrow);
186
187     customer_obj.style.display = '';
188     customer_select.style.display = 'none';
189
190     var invnum = document.getElementById('invnum'+searchrow);
191     invnum.value = '';
192
193     update_balance_text(searchrow, '');
194     update_status_text( searchrow, '');
195     update_status_color(searchrow, '#000000');    
196
197     function search_custnum_update(customers) {
198
199       var customerArrayArray = eval('(' + customers + ')') || [];
200
201       if ( customerArrayArray.length == 0 ) {
202
203         update_customer(searchrow, []);
204
205       } else if ( customerArrayArray.length == 1 ) {
206
207         update_customer(searchrow, customerArrayArray[0]);
208 % if ( $opt{custnum_update_callback} ) {
209           <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
210 % }
211
212       } else {
213
214         custnum_obj.value = 'Multiple'; // or something
215         custnum_obj.style.color = '#ff0000';
216
217         //blank the current list
218         customer_select.options.length = 0;
219
220         opt(customer_select, '', 'Multiple customers match "' + custnum + '" - select one', '#ff0000');
221         //add the multiple customers
222         for ( var s = 0; s < customerArrayArray.length; s++ ) {
223           opt(customer_select,
224               JSON.stringify(customerArrayArray[s]),
225               customerArrayArray[s][1],
226               '#000000');
227         }
228
229         opt(customer_select, 'cancel', '(Edit search string)', '#000000');
230
231         customer_obj.style.display = 'none';
232
233         customer_select.style.display = '';
234
235       }
236
237     }
238
239     custnum_search(custnum, search_custnum_update );
240
241   }
242
243   function <% $opt{prefix} %>search_customer() {
244
245     var customer_obj = this;
246     var searchrow = this.getAttribute('rownum');
247     var customer = this.value;
248
249     if ( customer == 'searching...' || customer == 'Not found' || customer == '' )
250       return;
251
252     if ( this.getAttribute('magic') == 'nosearch' ) {
253       this.setAttribute('magic', '');
254       return;
255     }
256
257     if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) {
258       <% $opt{prefix} %>addRow();
259     }
260     
261     var invnum = document.getElementById('invnum'+searchrow);
262     invnum.value = '';
263
264     var custnum_obj = document.getElementById('custnum'+searchrow);
265     custnum_obj.value = 'searching...';
266     custnum_obj.disabled = true;
267     custnum_obj.style.color = '#000000';
268     custnum_obj.style.backgroundColor = '#dddddd';
269
270     var customer_select = document.getElementById('cust_select'+searchrow);
271     
272     function search_customer_update(customers) {
273
274       var customerArrayArray = eval('(' + customers + ')') || [ [] ];
275
276       custnum_obj.disabled = false;
277       custnum_obj.style.backgroundColor = '#ffffff';
278
279       if ( customerArrayArray.length == 0 ) {
280
281         update_customer(searchrow, []);
282
283       } else if ( customerArrayArray.length == 1 ) {
284
285         update_customer(searchrow, customerArrayArray[0]);
286 % if ( $opt{custnum_update_callback} ) {
287         <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
288 % }
289
290       } else {
291
292         custnum_obj.value = 'Multiple'; // or something
293         custnum_obj.style.color = '#ff0000';
294
295         //blank the current list
296         customer_select.options.length = 0;
297
298         opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
299         //add the multiple customers
300         for ( var s = 0; s < customerArrayArray.length; s++ ) {
301           opt(customer_select,
302               JSON.stringify(customerArrayArray[s]),
303               customerArrayArray[s][1],
304               '#000000');
305         }
306
307         opt(customer_select, 'cancel', '(Edit search string)', '#000000');
308
309         customer_obj.style.display = 'none';
310
311         customer_select.style.display = '';
312
313       }
314
315     }
316
317     smart_search( customer, search_customer_update );
318
319   }
320
321   function select_customer() {
322
323     var custnum_balance_status = this.options[this.selectedIndex].value;
324     var customer = this.options[this.selectedIndex].text;
325
326     var searchrow = this.getAttribute('rownum');
327     var custnum_obj = document.getElementById('custnum'+searchrow);
328     var customer_obj = document.getElementById('customer'+searchrow);
329     var balance_obj = document.getElementById('balance'+searchrow);
330     var status_obj = document.getElementById('status'+searchrow);
331
332     if ( custnum_balance_status == '' ) {
333
334     } else if ( custnum_balance_status == 'cancel' ) {
335
336       custnum_obj.value = '';
337       custnum_obj.style.color = '#000000';
338
339       this.style.display = 'none';
340       customer_obj.style.display = '';
341       customer_obj.focus();
342
343     } else {
344     
345       update_customer(searchrow, JSON.parse(custnum_balance_status));
346
347 % if ( $opt{custnum_update_callback} ) {
348       <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>')
349 % }
350
351     }
352
353   }
354
355   function opt(what,value,text,color) {
356     var optionName = new Option(text, value, false, false);
357     optionName.style.color = color;
358     var length = what.length;
359     what.options[length] = optionName;
360   }
361
362   function update_status_text(rownum, newval) {
363     document.getElementById('status'+rownum).value = newval;
364     document.getElementById('status'+rownum+'_text').innerHTML = newval;
365   }
366
367   function update_status_color(rownum, newval) {
368     document.getElementById('statuscolor'+rownum).value = newval;
369     document.getElementById('status'+rownum+'_text').style.color = newval;
370   }
371
372   function update_balance_text(rownum, newval) {
373     document.getElementById('balance'+rownum).value = newval;
374     document.getElementById('balance'+rownum+'_text').innerHTML = newval;
375   }
376
377
378
379 </SCRIPT>
380
381 <TABLE ID="<% $opt{prefix} %>OneTrueTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
382
383 <TR>
384   <TH>Inv #</TH>
385   <TH>Cust #</TH>
386   <TH>Status</TH>
387   <TH>Customer</TH>
388   <TH>Balance</TH>
389 % foreach my $header ( @{$opt{header}} ) {
390     <TH><% $header %></TH>
391 % }
392 </TR>
393 % my $row = 0;
394 % for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { 
395
396     <TR>
397       <TD>
398         <INPUT TYPE      = "text"
399                NAME      = "invnum<% $row %>"
400                ID        = "invnum<% $row %>"
401                SIZE      = 8
402                MAXLENGTH = 12
403                STYLE     = "text-align:right;"
404                VALUE     = "<% $param->{"invnum$row"} %>"
405                rownum    = "<% $row %>"
406         >
407         <SCRIPT TYPE="text/javascript">
408           var invnum_input<% $row %> = document.getElementById("invnum<% $row %>");
409           invnum_input<% $row %>.onfocus = clearhint_invnum;
410           invnum_input<% $row %>.onchange = <% $opt{prefix} %>search_invnum;
411         </SCRIPT>
412       </TD>
413
414       <TD>
415         <INPUT TYPE      = "text"
416                NAME      = "custnum<% $row %>"
417                ID        = "custnum<% $row %>"
418                SIZE      = 8
419                MAXLENGTH = 12
420                STYLE     = "text-align:right;"
421                VALUE     = "<% $param->{"custnum$row"} %>"
422                rownum    = "<% $row %>"
423         >
424         <SCRIPT TYPE="text/javascript">
425           var custnum_input<% $row %> = document.getElementById("custnum<% $row %>");
426           custnum_input<% $row %>.onfocus = clearhint_custnum;
427           custnum_input<% $row %>.onchange = <% $opt{prefix} %>search_custnum;
428         </SCRIPT>
429       </TD>
430       
431       <TD STYLE="text-align: center">
432         <SPAN
433                ID        = "status<% $row %>_text"
434                rownum    = "<% $row %>"
435                STYLE     = "font-weight: bold;
436                             color: <%$param->{"statuscolor$row"} || '#000000'%>"
437
438         ><% $param->{"status$row"} %></SPAN>
439         <INPUT TYPE      = "hidden"
440                NAME      = "status<% $row %>"
441                ID        = "status<% $row %>"
442                VALUE     = "<% $param->{"status$row"} %>"
443                rownum    = "<% $row %>"
444         >
445         <INPUT TYPE      = "hidden"
446                NAME      = "statuscolor<% $row %>"
447                ID        = "statuscolor<% $row %>"
448                VALUE     = "<% $param->{"statuscolor$row"} %>"
449                rownum    = "<% $row %>"
450         >
451       </TD>
452
453       <TD>
454         <INPUT TYPE="text" NAME="customer<% $row %>" ID="customer<% $row %>" SIZE=64 VALUE="<% $param->{"customer$row"} %>" rownum="<% $row %>">
455           <SCRIPT TYPE="text/javascript">
456             var customer_input<% $row %> = document.getElementById("customer<% $row %>");
457             customer_input<% $row %>.onfocus = clearhint_customer;
458             customer_input<% $row %>.onclick = clearhint_customer;
459             customer_input<% $row %>.onchange = <% $opt{prefix} %>search_customer;
460           </SCRIPT>
461         <SELECT NAME="cust_select<% $row %>" ID="cust_select<% $row %>" rownum="<% $row %>" STYLE="color:#ff0000; display:none">
462         </SELECT>
463           <SCRIPT TYPE="text/javascript">
464             var customer_select<% $row %> = document.getElementById("cust_select<% $row %>");
465             customer_select<% $row %>.onchange = select_customer;
466           </SCRIPT>
467       </TD>
468
469       <TD STYLE="text-align:right">
470         <% $money_char %>
471         <SPAN 
472                ID        = "balance<% $row %>_text"
473                rownum    = "<% $row %>"
474         ><% $param->{"balance$row"} %></SPAN>
475         &nbsp;
476         <INPUT TYPE      = "hidden"
477                NAME      = "balance<% $row %>"
478                ID        = "balance<% $row %>"
479                VALUE     = "<% $param->{"balance$row"} %>"
480                rownum    = "<% $row %>"
481         >
482       </TD>
483
484 %   my $col = 0;
485 %   foreach my $field ( @{$opt{fields}} ) {
486 %     my $value;
487 %     if ( ref($field) eq 'CODE' ) {
488 %       $value = &{$field}($row,$param);
489 %     } else {
490 %       $value = $param->{"$field$row"}; 
491 %     }
492 %     my $name  = (ref($field) eq 'CODE') ? "column${col}_$row" : "$field$row";
493 %     my $align = $align{ $opt{align}->[$col] || 'l' };
494 %     my $size  = $sizes->[$col]  || 10;
495 %     my $color = $opt{color}->[$col];
496 %     my $font = $color ? qq(<FONT COLOR="$color">) : '';
497 %     my $onchange = '';
498 %     if ( $opt{footer}->[$col] eq '_TOTAL' ) {
499 %       $total[$col] += $value;
500 %       $onchange = $opt{prefix}. "calc_total$col();";
501 %       $onchange = qq(onchange="$onchange" onkeyup="$onchange");
502 %     }
503       <TD ALIGN="<% $align %>">
504 %     if (! $types->[$col] || $types->[$col] eq 'text') {
505         <INPUT TYPE  = "text"
506                NAME  = "<% $name %>"
507                ID    = "<% $name %>"
508                SIZE  = "<% $size %>"
509                STYLE = "text-align: <% $align %>;"
510                VALUE = "<% $value %>"
511                <% $onchange %>
512         >
513 %     } elsif ($types->[$col] eq 'immutable') {
514         <% $font %><% $value %><% $font ? '</FONT>' : '' %>
515         <INPUT TYPE="hidden" ID="<% $name %>" NAME="<% $name %>" VALUE="<% $value %>" >
516 %     } else {
517         Cannot represent unknown type: <% $types->[$col] %>
518 %     }
519       </TD>
520 %     $col++;
521 %   }
522     </TR>
523 % } 
524
525 <TR>
526   <TH COLSPAN=5 ID="<% $opt{'prefix'} %>_TOTAL_TOTAL">
527     Total <% $row ? $row-1 : 0 %>
528     <% PL($opt{name_singular} || 'customer', ( $row ? $row-1 : 0 ) ) %>
529   </TH>
530 % my $col = 0;
531 % foreach my $footer ( @{$opt{footer}} ) {
532 %   my $align = $align{ $opt{'footer_align'}->[$col] || 'c' };
533 %   if ($footer eq '_TOTAL' ) {
534 %     my $id = $opt{'fields'}->[$col];
535 %     $id = ref($id) ? "column${col}_TOTAL" : "${id}_TOTAL";
536       <TH ALIGN="<% $align %>" ID="<% $id %>">&nbsp;<% sprintf('%.2f', $total[$col] ) %></TH>
537 %   } else {
538       <TH ALIGN="<% $align %>"><% $footer %></TH>
539 %   }
540 %   $col++;
541 % }
542 </TR>
543
544 </TABLE>
545
546 <SCRIPT TYPE="text/javascript">
547 % my $col = 0;
548 % foreach my $footer ( @{$opt{footer}} ) {
549 %   if ($footer eq '_TOTAL' ) {
550 %     my $name = $opt{fields}->[$col];
551 %     $name = ref($name) ? "column$col" : $name;
552       var <% $opt{prefix}.$name %>_CACHE = new Array ();
553       var <% $opt{prefix} %>th_el = document.getElementById("<%$name%>_TOTAL");
554       function <% $opt{prefix} %>calc_total<% $col %>() {
555         var row = 0;
556         var total = 0;
557         for ( var row = 0;
558               
559               ( <% $opt{prefix}.$name%>_CACHE[row] =
560                                         <% $opt{prefix}.$name%>_CACHE[row]
561                                      || document.getElementById("<%$name%>"+row)
562               ) != null;
563               
564               row++
565             )
566         {
567           var value = <%$name%>_CACHE[row].value;
568           value = parseFloat(value);
569           if ( ! isNaN(value) ) {
570             total = total + value;
571           }
572         }
573         <% $opt{prefix} %>th_el.innerHTML = '&nbsp;' + total.toFixed(2);
574
575       }
576 %   }
577 %   $col++;
578 % }
579 </SCRIPT>
580
581 <% include('/elements/xmlhttp.html',
582               'url'  => $p. 'misc/xmlhttp-cust_main-search.cgi',
583               'subs' => [qw( custnum_search smart_search invnum_search )],
584            )
585 %>
586
587 <SCRIPT TYPE="text/javascript">
588
589   var <% $opt{prefix} %>total_el =
590     document.getElementById("<% $opt{'prefix'} %>_TOTAL_TOTAL");
591
592   var <% $opt{prefix} %>rownum = <% $row %>;
593
594   function <% $opt{prefix} %>addRow() {
595
596     var table = document.getElementById('<% $opt{prefix} %>OneTrueTable');
597     var tablebody = table.getElementsByTagName('tbody').item(0);
598
599     var row = table.insertRow(rownum+1);
600     
601     var invnum_cell = document.createElement('TD');
602
603       var invnum_input = document.createElement('INPUT');
604       invnum_input.setAttribute('name', 'invnum'+<% $opt{prefix} %>rownum);
605       invnum_input.setAttribute('id',   'invnum'+<% $opt{prefix} %>rownum);
606       invnum_input.style.textAlign = 'right';
607       invnum_input.setAttribute('size', 8);
608       invnum_input.setAttribute('maxlength', 12);
609       invnum_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
610       invnum_input.onfocus = clearhint_invnum;
611       invnum_input.onchange = <% $opt{prefix} %>search_invnum;
612       invnum_cell.appendChild(invnum_input);
613
614     row.appendChild(invnum_cell);
615
616     var custnum_cell = document.createElement('TD');
617
618       var custnum_input = document.createElement('INPUT');
619       custnum_input.setAttribute('name', 'custnum'+<% $opt{prefix} %>rownum);
620       custnum_input.setAttribute('id',   'custnum'+<% $opt{prefix} %>rownum);
621       custnum_input.style.textAlign = 'right';
622       custnum_input.setAttribute('size', 8);
623       custnum_input.setAttribute('maxlength', 12);
624       custnum_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
625       custnum_input.onfocus = clearhint_custnum;
626       custnum_input.onchange = <% $opt{prefix} %>search_custnum;
627       custnum_cell.appendChild(custnum_input);
628
629     row.appendChild(custnum_cell);
630     
631     var status_cell = document.createElement('TD');
632       status_cell.style.textAlign = 'center';
633         
634       var status_span = document.createElement('SPAN');
635       status_span.setAttribute('id', 'status'+<% $opt{prefix} %>rownum+'_text');
636       status_span.style.fontWeight = 'bold';
637       status_span.setAttribute('rownum', <% $opt{prefix} %>rownum);
638       status_cell.appendChild(status_span);
639         
640       var status_input = document.createElement('INPUT');
641       status_input.setAttribute('type', 'hidden');
642       status_input.setAttribute('name', 'status'+<% $opt{prefix} %>rownum);
643       status_input.setAttribute('id',   'status'+<% $opt{prefix} %>rownum);
644       status_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
645       status_cell.appendChild(status_input);
646
647       var statuscolor_input = document.createElement('INPUT');
648       statuscolor_input.setAttribute('type', 'hidden');
649       statuscolor_input.setAttribute('name', 'statuscolor'+<% $opt{prefix} %>rownum);
650       statuscolor_input.setAttribute('id',   'statuscolor'+<% $opt{prefix} %>rownum);
651       statuscolor_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
652       status_cell.appendChild(statuscolor_input);
653
654     row.appendChild(status_cell);
655
656     var customer_cell = document.createElement('TD');
657
658       var customer_input = document.createElement('INPUT');
659       customer_input.setAttribute('name', 'customer'+<% $opt{prefix} %>rownum);
660       customer_input.setAttribute('id',   'customer'+<% $opt{prefix} %>rownum);
661       customer_input.setAttribute('size', 64);
662       customer_input.setAttribute('value', '(last name or company)' );
663       customer_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
664       customer_input.onfocus = clearhint_customer;
665       customer_input.onclick = clearhint_customer;
666       customer_input.onchange = <% $opt{prefix} %>search_customer;
667       customer_cell.appendChild(customer_input);
668
669       var customer_select = document.createElement('SELECT');
670       customer_select.setAttribute('name', 'cust_select'+<% $opt{prefix} %>rownum);
671       customer_select.setAttribute('id',   'cust_select'+<% $opt{prefix} %>rownum);
672       customer_select.setAttribute('rownum', <% $opt{prefix} %>rownum);
673       customer_select.style.color = '#ff0000';
674       customer_select.style.display = 'none';
675       customer_select.onchange = select_customer;
676       customer_cell.appendChild(customer_select);
677
678     row.appendChild(customer_cell);
679     
680     var balance_cell = document.createElement('TD');
681
682       balance_cell.style.textAlign = 'right';
683       balance_cell.appendChild(document.createTextNode('<%$money_char%>'));
684
685       var balance_span = document.createElement('SPAN');
686       balance_span.setAttribute('id', 'balance'+<% $opt{prefix} %>rownum+'_text');
687       balance_span.setAttribute('rownum', <% $opt{prefix} %>rownum);
688       balance_cell.appendChild(balance_span);
689
690       balance_cell.appendChild(
691         document.createTextNode(String.fromCharCode(160)) //&nbsp;
692       );
693
694       var balance_input = document.createElement('INPUT');
695       balance_input.setAttribute('type', 'hidden');
696       balance_input.setAttribute('name', 'balance'+<% $opt{prefix} %>rownum);
697       balance_input.setAttribute('id',   'balance'+<% $opt{prefix} %>rownum);
698       balance_input.setAttribute('rownum', <% $opt{prefix} %>rownum);
699       balance_cell.appendChild(balance_input);
700
701     row.appendChild(balance_cell);
702
703 %   my $col = 0;
704 %   foreach my $field ( @{$opt{fields}} ) {
705
706       var my_cell = document.createElement('TD');
707       my_cell.setAttribute('align', '<% $align{ $opt{align}->[$col] || 'l' } %>');
708
709 %     if ($types->[$col] eq 'immutable') {
710 %       my $value;
711 %       if ( ref($field) eq 'CODE' ) {
712 %         $value = &{$field}($row,$param);
713 %       } else {
714 %         $value = $param->{"$field$row"}; 
715 %       }
716         var my_text = document.createTextNode('<% $value %>');
717         my_cell.appendChild(my_text);
718 %     }
719
720 %     my $name  = (ref($field) eq 'CODE') ? "column${col}_" : $field;
721       var my_input = document.createElement('INPUT');
722       my_input.setAttribute('name', '<% $name %>'+<% $opt{prefix} %>rownum);
723       my_input.setAttribute('id',   '<% $name %>'+<% $opt{prefix} %>rownum);
724       my_input.style.textAlign = '<% $align{ $opt{align}->[$col] || 'l' } %>';
725       my_input.setAttribute('size', <% $sizes->[$col] || 10 %>);
726 %     if ($types->[$col] eq 'immutable') {
727         my_input.setAttribute('type', 'hidden');
728 %     }
729 %     if ( $opt{footer}->[$col] eq '_TOTAL' ) {
730         my_input.onchange   = <% $opt{prefix} %>calc_total<%$col%>;
731         my_input.onkeyup    = <% $opt{prefix} %>calc_total<%$col%>;
732 %     }
733       my_cell.appendChild(my_input);
734
735     row.appendChild(my_cell);
736
737 %     $col++;
738 %   }
739
740     //update the total # of rows display
741     if ( <% $opt{prefix} %>rownum == 1 ) {
742       <% $opt{prefix} %>total_el.innerHTML =
743         'Total '
744           + <% $opt{prefix} %>rownum
745           + ' <% $opt{name_singular} || 'customer' %>';
746     } else {
747       <% $opt{prefix} %>total_el.innerHTML =
748         'Total '
749           + <% $opt{prefix} %>rownum
750           + ' <% PL($opt{name_singular} || 'customer') %>';
751     }
752
753     <% $opt{prefix} %>rownum++;
754
755   }
756
757 % unless ($cgi->param('error')) {
758   <% $opt{prefix} %>addRow();
759 % }
760 </SCRIPT>
761
762 <%init>
763
764 my(%opt) = @_;
765 my $conf = new FS::Conf;
766
767 $opt{prefix} = '' unless defined $opt{prefix};
768 $opt{prefix} .= '_' if $opt{prefix};
769
770 my $types = $opt{'type'} ? [ @{$opt{'type'}} ] : [];
771 my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : [];
772
773 my $param = $opt{param};
774 $param = $cgi->Vars if $cgi->param('error');
775
776 $opt{$_} ||= [] foreach qw(align color footer footer_align);
777
778 my @total = map 0, @{$opt{footer}};
779
780 my %align = (
781   'l' => 'left',
782   'r' => 'right',
783   'c' => 'center',
784 );
785
786 my $money_char = $conf->config('money_char') || '$';
787 </%init>