default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / edit / elements / detail-table.html
1 <%doc>
2 Common code for editing invoice/quotation details/comments.
3
4 Expects to be the last element in a two-column table with specified id
5
6   <& /edit/elements/detail-table.html, 
7        id      => 'element_id', # required
8        details => \@details,    # plain text strings, existing details
9        label   => 'Comments',   # optional, shows on first row only
10        field   => 'comment',    # input field name/id, appended with rownum, default 'detail'
11   &>
12
13 </%doc>
14
15 <SCRIPT>
16 % unless ($detail_table_init) {
17 %   $detail_table_init = 1;
18
19   var detail_table_info = {};
20   detail_table_info.rownum = {};
21   detail_table_info.label  = {};
22   detail_table_info.field  = {};
23
24   function possiblyAddDetailRow(tableid,rownum) {
25     if (( detail_table_info.rownum[tableid] - rownum == 1 ) || !detail_table_info.rownum[tableid]) {
26       addDetailRow(tableid);
27     }
28   }
29
30   function addDetailRow(tableid,newtext) {
31
32     var table = document.getElementById(tableid);
33     var newrownum = detail_table_info.rownum[tableid];
34     var newfield  = detail_table_info.field[tableid] + newrownum;
35
36     var row = document.createElement('TR');
37
38     var empty_cell = document.createElement('TD');
39     if (!newrownum) {
40       empty_cell.innerHTML = detail_table_info.label[tableid];
41       empty_cell.style.textAlign = 'right';
42     }
43     row.appendChild(empty_cell);
44
45     var detail_cell = document.createElement('TD');
46
47     var detail_input = document.createElement('INPUT');
48     detail_input.setAttribute('name', newfield);
49     detail_input.setAttribute('id',   newfield);
50     detail_input.setAttribute('size', 60);
51     detail_input.setAttribute('maxLength', 65);
52     detail_input.onkeyup = function () { possiblyAddDetailRow(tableid,newrownum) };
53     detail_input.onchange = function () { possiblyAddDetailRow(tableid,newrownum) };
54     detail_input.value = newtext || '';
55     detail_cell.appendChild(detail_input);
56
57     row.appendChild(detail_cell);
58
59     table.appendChild(row);
60
61     detail_table_info.rownum[tableid]++;
62
63   }
64 % } # end init
65   detail_table_info.label['<% $id %>'] = '<% emt($label) %>';
66   detail_table_info.field['<% $id %>'] = '<% $field %>';
67   detail_table_info.rownum['<% $id %>'] = 0;
68 % foreach my $detail ( @details ) { 
69   addDetailRow('<% $id %>','<% $detail %>');
70 % } 
71 </SCRIPT>
72
73 <%shared>
74 my $detail_table_init = 0;
75 </%shared>
76 <%init>
77 my %opt = @_;
78
79 my @details = $opt{'details'} ? @{ $opt{'details'} } : ();
80 push(@details,'') if $details[$#details] || !@details;
81 my $id = $opt{'id'} or die "No id specified";
82 my $label = $opt{'label'} || '';
83 my $field = $opt{'field'} || 'detail';
84
85 </%init>