use a javascript layer instead of a browser popup (popup blockers), really generalize...
[freeside.git] / httemplate / edit / rate.cgi
index 83a89c4..ce56768 100644 (file)
@@ -1,12 +1,7 @@
-<!-- mason kludge -->
 <%
 
 my $rate;
-if ( $cgi->param('error') ) {
-  $rate = new FS::rate ( {
-    map { $_, scalar($cgi->param($_)) } fields('rate')
-  } );
-} elsif ( $cgi->keywords ) {
+if ( $cgi->keywords ) {
   my($query) = $cgi->keywords;
   $query =~ /^(\d+)$/;
   $rate = qsearchs( 'rate', { 'ratenum' => $1 } );
@@ -22,6 +17,13 @@ my %granularity = (
   '60' => 'minute',
 );
 
+my $nous = <<END;
+  WHERE 0 < ( SELECT COUNT(*) FROM rate_prefix
+               WHERE rate_region.regionnum = rate_prefix.regionnum
+                 AND countrycode != '1'
+            )
+END
+
 %>
 
 <%= header("$action Rate plan", menubar(
@@ -30,12 +32,14 @@ my %granularity = (
     ))
 %>
 
-<% if ( $cgi->param('error') ) { %>
-<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT><BR>
-<% } %>
-
-<FORM ACTION="<%=$p1%>process/rate.cgi" METHOD=POST>
-
+<%= include('/elements/progress-init.html',
+              'OneTrueForm',
+              [ 'rate', 'min_', 'sec_' ],
+              'process/rate.cgi',
+              $p.'browse/rate.cgi',
+           )
+%>
+<FORM NAME="OneTrueForm">
 <INPUT TYPE="hidden" NAME="ratenum" VALUE="<%= $rate->ratenum %>">
 
 Rate plan
@@ -52,12 +56,16 @@ Rate plan
 </TR>
 
 <% foreach my $rate_region (
-     qsearch('rate_region', {}, '', 'ORDER BY regionname' )
+     qsearch( 'rate_region',
+              {},
+              '',
+              "$nous ORDER BY regionname",
+            )
    ) {
      my $n = $rate_region->regionnum;
      my $rate_detail =
        $rate->dest_detail($rate_region)
-       || new FS::rate_region { 'min_included'    => 0,
+       || new FS::rate_detail { 'min_included'    => 0,
                                 'min_charge'      => 0,
                                 'sec_granularity' => '60'
                               };
@@ -84,9 +92,9 @@ Rate plan
 
 </TABLE>
 
-<BR><INPUT TYPE="submit" VALUE="<%= 
+<BR><INPUT NAME="submit" TYPE="button" VALUE="<%= 
   $rate->ratenum ? "Apply changes" : "Add rate plan"
-%>">
+%>" onClick="document.OneTrueForm.submit.disabled=true; process();">
 
     </FORM>
   </BODY>