From 3bc7d019313160a918a55cca6ab530f58db3673d Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 11 Feb 2005 06:44:27 +0000 Subject: [PATCH] generalize progressbar code in preparation for using it wherever needed --- FS/FS/UI/Web.pm | 67 ++++++++++++++++++++++++++++++++++++++++ FS/FS/rate.pm | 24 ++++++++------ htetc/global.asa | 1 + htetc/handler.pl | 1 + httemplate/edit/process/rate.cgi | 5 ++- httemplate/edit/rate.cgi | 3 +- 6 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 FS/FS/UI/Web.pm diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm new file mode 100644 index 000000000..869203b0e --- /dev/null +++ b/FS/FS/UI/Web.pm @@ -0,0 +1,67 @@ +package FS::UI::Web; + +#use vars qw(@ISA); +#use FS::UI +#@ISA = qw( FS::UI ); + + +# begin JSRPC code... + +package FS::UI::Web::JSRPC; + +use vars qw(@ISA $DEBUG); +use Storable qw(nfreeze); +use MIME::Base64; +use JavaScript::RPC::Server::CGI; +use FS::UID; + +@ISA = qw( JavaScript::RPC::Server::CGI ); +$DEBUG = 1; + +sub new { + my $class = shift; + my $self = { + env => {}, + job => shift, + }; + + bless $self, $class; + + return $self; +} + +sub start_job { + my $self = shift; + + my %param = @_; + warn "FS::UI::Web::start_job\n". + join('', map " $_ => $param{$_}\n", keys %param ) + if $DEBUG; + + #progressbar prototype code... should be generalized + + #first get the CGI params shipped off to a job ASAP so an id can be returned + #to the caller + + #my $job = new FS::queue { 'job' => 'FS::rate::process' }; + my $job = new FS::queue { 'job' => $self->{'job'} }; + + #too slow to insert all the cgi params as individual args..,? + #my $error = $queue->insert('_JOB', $cgi->Vars); + + #my $bigstring = join(';', map { "$_=". scalar($cgi->param($_)) } $cgi->param ); +# my $bigstring = join(';', map { "$_=". $param{$_} } keys %param ); +# my $error = $job->insert('_JOB', $bigstring); + + #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n" + # if $DEBUG; + + my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) ); + + if ( $error ) { + $error; + } else { + $job->jobnum; + } + +} diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm index 7f625a6b1..7c6a70e8e 100644 --- a/FS/FS/rate.pm +++ b/FS/FS/rate.pm @@ -2,6 +2,8 @@ package FS::rate; use strict; use vars qw( @ISA $DEBUG ); +use Storable qw(thaw); +use Data::Dumper; use FS::Record qw( qsearch qsearchs dbh fields ); use FS::rate_detail; @@ -307,25 +309,29 @@ Experimental job-queue processor for web interface adds/edits =cut +use MIME::Base64; sub process { my $job = shift; #my %param = @_; - my $param = shift; - my %param = split(/[;=]/, $param); + #my $param = shift; + #my %param = split(/[;=]/, $param); - my $old = qsearchs('rate', { 'ratenum' => $param{'ratenum'} } ) - if $param{'ratenum'}; + my $param = thaw(decode_base64(shift)); + warn Dumper($param) if $DEBUG; + + my $old = qsearchs('rate', { 'ratenum' => $param->{'ratenum'} } ) + if $param->{'ratenum'}; my @rate_detail = map { my $regionnum = $_->regionnum; - if ( $param{"sec_granularity$regionnum"} ) { + if ( $param->{"sec_granularity$regionnum"} ) { new FS::rate_detail { 'dest_regionnum' => $regionnum, - map { $_ => $param{"$_$regionnum"} } + map { $_ => $param->{"$_$regionnum"} } qw( min_included min_charge sec_granularity ) }; @@ -343,13 +349,13 @@ sub process { } qsearch('rate_region', {} ); my $rate = new FS::rate { - map { $_ => $param{$_} } + map { $_ => $param->{$_} } fields('rate') }; my $error = ''; - if ( $param{'ratenum'} ) { - warn "$rate replacing $old ($param{'ratenum'})\n" if $DEBUG; + if ( $param->{'ratenum'} ) { + warn "$rate replacing $old (". $param->{'ratenum'}. ")\n" if $DEBUG; $error = $rate->replace( $old, 'rate_detail' => \@rate_detail, 'job' => $job, diff --git a/htetc/global.asa b/htetc/global.asa index 94a103081..482572a80 100644 --- a/htetc/global.asa +++ b/htetc/global.asa @@ -29,6 +29,7 @@ use FS::Record qw(qsearch qsearchs fields dbdef); use FS::Conf; use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot small_custview myexit http_header); +use FS::UI::Web; use FS::Msgcat qw(gettext geterror); use FS::Misc qw( send_email ); use FS::Report::Table::Monthly; diff --git a/htetc/handler.pl b/htetc/handler.pl index 557ec02ed..934b41967 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -112,6 +112,7 @@ sub handler use FS::Conf; use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot small_custview myexit http_header); + use FS::UI::Web; use FS::Msgcat qw(gettext geterror); use FS::Misc qw( send_email ); use FS::Report::Table::Monthly; diff --git a/httemplate/edit/process/rate.cgi b/httemplate/edit/process/rate.cgi index df7c4672e..031f8d14e 100755 --- a/httemplate/edit/process/rate.cgi +++ b/httemplate/edit/process/rate.cgi @@ -1,4 +1,7 @@ <% -my $server = new FS::rate::JSRPC; +#my $server = new FS::rate::JSRPC; +#$server->process; +my $server = new FS::UI::Web::JSRPC 'FS::rate::process'; +###wtf###$server->start_job; $server->process; %> diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi index 3443f81d4..4a0294033 100644 --- a/httemplate/edit/rate.cgi +++ b/httemplate/edit/rate.cgi @@ -55,7 +55,8 @@ function process () { } jsrsPOST = true; - jsrsExecute( 'process/rate.cgi', myCallback, 'process_rate', Hash ); + //jsrsExecute( 'process/rate.cgi', myCallback, 'process_rate', Hash ); + jsrsExecute( 'process/rate.cgi', myCallback, 'start_job', Hash ); function myCallback( jobnum ) { var progressWindow = window.open('../../misc/progress.html?jobnum=' + jobnum + ';url=<%=$p%>browse/rate.cgi', 'progressWindow', 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,width=420,height=128'); -- 2.11.0