first part of ACL and re-skinning work and some other small stuff
[freeside.git] / FS / FS / UI / Web.pm
index 213a219..10ddbf3 100644 (file)
@@ -130,15 +130,15 @@ sub cust_fields {
 package FS::UI::Web::JSRPC;
 
 use strict;
-use vars qw(@ISA $DEBUG);
+use vars qw($DEBUG);
+use Carp;
 use Storable qw(nfreeze);
 use MIME::Base64;
-#use JavaScript::RPC::Server::CGI;
+use JSON;
 use FS::UID;
 use FS::Record qw(qsearchs);
 use FS::queue;
 
-#@ISA = qw( JavaScript::RPC::Server::CGI );
 $DEBUG = 0;
 
 sub new {
@@ -151,6 +151,8 @@ sub new {
 
         bless $self, $class;
 
+        croak "CGI object required as second argument" unless $self->{'cgi'};
+
         return $self;
 }
 
@@ -163,6 +165,9 @@ sub process {
   # XXX this should parse JSON foo and build a proper data structure
   my @args = $cgi->param('arg');
 
+  #work around konqueror bug!
+  @args = map { s/\x00$//; $_; } @args;
+
   my $sub = $cgi->param('sub'); #????
 
   warn "FS::UI::Web::JSRPC::process:\n".
@@ -179,6 +184,10 @@ sub process {
 
     $self->job_status(@args);
 
+  } else {
+
+    die "unknown sub $sub";
+
   }
 
 }
@@ -223,11 +232,19 @@ sub start_job {
   my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
 
   if ( $error ) {
+
+    warn "job not inserted: $error\n"
+      if $DEBUG;
+
     $error;  #this doesn't seem to be handled well,
              # will trigger "illegal jobnum" below?
              # (should never be an error inserting the job, though, only thing
              #  would be Pg f%*kage)
   } else {
+
+    warn "job inserted successfully with jobnum ". $job->jobnum. "\n"
+      if $DEBUG;
+
     $job->jobnum;
   }
   
@@ -248,30 +265,16 @@ sub job_status {
   my @return;
   if ( $job && $job->status ne 'failed' ) {
     @return = ( 'progress', $job->statustext );
-  } elsif ( !$job ) { #handle job gone case : job sucessful
+  } elsif ( !$job ) { #handle job gone case : job successful
                       # so close popup, redirect parent window...
     @return = ( 'complete' );
   } else {
     @return = ( 'error', $job ? $job->statustext : $jobnum );
   }
 
-  #join("\n",@return);
-
-  #XXX should use JSON!
-  @return = map {
-    s/\\/\\\\/g;
-    s/\n/\\n/g;
-    s/"/\"/g;
-    $_
-  } @return;
-  
-  '[ '. join(', ', map { qq("$_") } @return). " ]\n";
+  objToJson(\@return);
 
 }
 
-#sub get_new_query {
-#  FS::UID::cgi();
-#}
-
 1;