This commit was generated by cvs2svn to compensate for changes in r5562,
[freeside.git] / httemplate / edit / quick-charge.html
1 <% include("/elements/header-popup.html", 'One-time charge entry', '',
2             ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
3           )
4 %>
5 % if ( $cgi->param('error') ) { 
6
7   <FONT SIZE="+1" COLOR="#ff0000"><% $cgi->param('error') %></FONT><BR><BR>
8 % } 
9
10 <SCRIPT TYPE="text/javascript">
11
12 function enable_quick_charge () {
13   if (    document.QuickChargeForm.amount.value
14        && document.QuickChargeForm.pkg.value    ) {
15     document.QuickChargeForm.submit.disabled = false;
16   } else {
17     document.QuickChargeForm.submit.disabled = true;
18   }
19 }
20
21 function enable_quick_charge_desc () {
22   if (  document.QuickChargeForm.amount.value && document.QuickChargeForm.pkg.value ) {
23     document.QuickChargeForm.submit.disabled = false;
24   } else {
25     document.QuickChargeForm.submit.disabled = true;
26   }
27 }
28
29 function enable_quick_charge_amount () {
30   if ( document.QuickChargeForm.amount.value && document.QuickChargeForm.pkg.value ) {
31     document.QuickChargeForm.submit.disabled = false;
32   } else {
33     document.QuickChargeForm.submit.disabled = true;
34   }
35 }
36
37 function validate_quick_charge () {
38   var pkg = document.QuickChargeForm.pkg.value;
39   var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
40   var amount = document.QuickChargeForm.amount.value;
41   var amount_regex = /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ;
42   var rval = true;
43
44   if ( ! amount_regex.test(amount) ) {
45     alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
46     return false;
47   }
48   if ( String(pkg).length < 1 ) {
49     rval = false;
50   }
51   if ( ! pkg_regex.test(pkg) ) {
52     rval = false;
53   }
54   var i=0;
55   for (i=0; i < rownum; i++) {
56     if (! eval('pkg_regex.test(document.QuickChargeForm.description' + i + '.value)')){
57       rval = false;
58       break;
59     }
60   }
61   if (rval == true) {
62     return true;
63   }
64
65   if ( ! pkg ) {
66     alert('Enter a description for the one-time charge');
67     return false;
68   }
69
70   alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
71   return false;
72 }
73
74 </SCRIPT>
75
76
77
78 <FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();">
79
80 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cgi->param('custnum') %>">
81 <TABLE ID="QuickChargeTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
82
83 <TR>
84   <TD ALIGN="right">Amount:</TD>
85   <TD>
86     $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $cgi->param('amount') %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_amount()">
87   </TD>
88 <% include('/elements/tr-select-taxclass.html') %>
89 </TR>
90   <TD>Description:</TD>
91   <TD>
92     <INPUT TYPE="text" NAME="pkg" SIZE="60" MAXLENGTH="65" VALUE="<% $cgi->param('pkg') %>" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_desc()">
93   </TD>
94 </TR>
95 <TR>
96   <TD></TD>
97   <TD><FONT SIZE="-1">Optional additional description: </FONT></TD>
98 </TR>
99
100 % my $row = 0;
101 %   if ( $cgi->param('error') ) {
102 %     my $param = $cgi->Vars;
103 %
104 % for ( $row = 0; exists($param->{"description$row"}); $row++ ) { 
105
106     <TR>
107       <TD></TD>
108       <TD>
109         <INPUT TYPE="text" NAME="description<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $param->{"description$row"} %>" rownum="<% $row %>" onkeyup = "possiblyAddRow;" >
110       </TD>
111     </TR>
112 % } 
113 % } 
114
115
116 </TABLE>
117
118 <BR>
119 <INPUT TYPE="submit" NAME="submit" VALUE="Add one-time charge" <% $cgi->param('error') ? '' :' DISABLED' %>>
120
121 </FORM>
122
123
124 <SCRIPT TYPE="text/javascript">
125
126   var rownum = <% $row %>;
127
128   function possiblyAddRow() {
129     if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
130       addRow();
131     }
132   }
133
134   function addRow() {
135
136     var table = document.getElementById('QuickChargeTable');
137     var tablebody = table.getElementsByTagName('tbody').item(0);
138
139     var row = document.createElement('TR');
140
141     var empty_cell = document.createElement('TD');
142     row.appendChild(empty_cell);
143
144     var description_cell = document.createElement('TD');
145
146       var description_input = document.createElement('INPUT');
147       description_input.setAttribute('name', 'description'+rownum);
148       description_input.setAttribute('id',   'description'+rownum);
149       description_input.setAttribute('size', 60);
150       description_input.setAttribute('maxlength', 65);
151       description_input.setAttribute('rownum',   rownum);
152       description_input.onkeyup = possiblyAddRow;
153       description_cell.appendChild(description_input);
154
155     row.appendChild(description_cell);
156
157     tablebody.appendChild(row);
158
159     rownum++;
160
161   }
162
163 </SCRIPT>
164
165 </BODY>
166 </HTML>