stricter otaker rules
[freeside.git] / httemplate / view / cust_main / quick-charge.html
index 0b51586..06ffd75 100644 (file)
@@ -1,32 +1,73 @@
-<%
-  my( $cust_main ) = @_;
-  my $conf = new FS::Conf;
-%>
-
-<FORM ACTION="<%=$p%>edit/process/quick-charge.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $cust_main->custnum %>">
-Description:<INPUT TYPE="text" NAME="pkg">
-&nbsp;Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>
-&nbsp;<% 
-  
-  #false laziness w/ edit/part_pkg.cgi
-  if ( $conf->exists('enable_taxclasses') ) {
-    print '<SELECT NAME="taxclass">';
-    my $sth = dbh->prepare('SELECT DISTINCT taxclass FROM cust_main_county')
-      or die dbh->errstr;
-    $sth->execute or die $sth->errstr;
-    foreach my $taxclass ( map $_->[0], @{$sth->fetchall_arrayref} ) {
-      print qq!<OPTION VALUE="$taxclass"!;
-      #print ' SELECTED' if $taxclass eq $hashref->{taxclass};
-      print qq!>$taxclass</OPTION>!;
+<SCRIPT TYPE="text/javascript">
+
+function enable_quick_charge () {
+  //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+  if (    document.QuickChargeForm.amount.value
+       && document.QuickChargeForm.pkg.value    ) {
+    document.QuickChargeForm.submit.disabled = false;
+  } else {
+    document.QuickChargeForm.submit.disabled = true;
+  }
+}
+
+function enable_quick_charge_desc () {
+  //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+  if (  document.QuickChargeForm.amount.value ) {
+    document.QuickChargeForm.submit.disabled = false;
+  } else {
+    document.QuickChargeForm.submit.disabled = true;
+  }
+}
+
+function enable_quick_charge_amount () {
+  //alert('enable_quick_charge ' + document.QuickChargeForm.amount.value + ' - ' + document.QuickChargeForm.pkg.value );
+  if ( document.QuickChargeForm.pkg.value ) {
+    document.QuickChargeForm.submit.disabled = false;
+  } else {
+    document.QuickChargeForm.submit.disabled = true;
+  }
+}
+
+function validate_quick_charge () {
+  //alert('validate_quick_charge');
+  var pkg = document.QuickChargeForm.pkg.value;
+  var pkg_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/ ;
+  var amount = document.QuickChargeForm.amount.value;
+  var amount_regex = /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ;
+
+  if ( amount_regex.test(amount) && pkg_regex.test(pkg) ) {
+    return true;
+  } else if ( amount_regex.test(amount) ) {
+    if ( pkg ) {
+      alert('Illegal description - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
+    } else {
+      alert('Enter a description for the one-time charge');
     }
-    print '</SELECT>';
+    return false;
   } else {
-    print '<INPUT TYPE="hidden" NAME="taxclass" VALUE="">';
+    alert('Illegal amount - enter an amount to charge, for example, "5" or "43" or "21.46".');
+    return false;
   }
+}
+
+</SCRIPT>
+
+<FORM NAME="QuickChargeForm" ACTION="<%$p%>edit/process/quick-charge.cgi" METHOD="POST" onSubmit="return validate_quick_charge()">
+
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
+
+Description:<INPUT TYPE="text" NAME="pkg" onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_desc()">
+
+Amount:<INPUT TYPE="text" NAME="amount" SIZE=6 onChange="enable_quick_charge()" onKeyPress="enable_quick_charge_amount()">
+
+<% include('/elements/select-taxclass.html') %>
+
+<INPUT NAME="submit" TYPE="submit" VALUE="One-time charge" DISABLED>
 
-%>
-  
-<INPUT TYPE="submit" VALUE="One-time charge">
 </FORM>
 
+<%init>
+
+my( $cust_main ) = @_;
+
+</%init>