X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Felements%2Fprogress-init.html;h=de3c6b761393cbb397b75043a2d9eb9c923ebb75;hp=7edb831c570d59be47d13e5c22c0b448e9ecbac5;hb=ac3296dc4d9c1c7ff3646df6496a4f49d9e07b9b;hpb=d6047391feb3236374e16fd73240d9821d77fe06 diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html index 7edb831c5..de3c6b761 100644 --- a/httemplate/elements/progress-init.html +++ b/httemplate/elements/progress-init.html @@ -1,45 +1,184 @@ -<% my( $formname, $fields, $action, $success_url ) = @_; %> +<%doc> +Example: +In misc/something.html: - - - + +In misc/process_something.html: + +<%init> +my $server = FS::UI::Web::JSRPC->new('FS::something::process_whatever', $cgi); + +<% $server->process %> + +In FS/something.pm: + +sub process_whatever { #class method + my $job = shift; + my $param = thaw(base64_decode(shift)); + # param = { 'recordnum' => 42, 'what_to_do' => delete } + # make use of this as you like + do_phase1; + $job->update_statustext(20); + do_phase2; + $job->update_statustext(40); + do_phase3; + $job->update_statustext(60); + # etc. + return 'this value will be ignored'; } -function process () { +Internal notes: + +This component creates two JS functions: process(), which starts the +submission process, and start_job(), which starts the job on the +server side. + +process() does the following: +- disable the form submit button +- for all form fields named in "fields", collect their values into an array +- declare a callback function "myCallback" +- pass the array and callback to start_job() - document.OneTrueForm.submit.disabled=true; +start_job() is an xmlhttp standard function that turns the array of values +into a JSON string, posts it to the location given in $action, receives a +job number back, and then invokes the callback with the job number as an +argument. Normally, the post target script will use FS::UI::Web::JSRPC to insert +a queue job (with the form field values as arguments), and return its +job number. - overlib( 'Submitting job to server...', WIDTH, 420, HEIGHT, 128, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 ); +myCallback() opens an Overlib popup containing progress-popup.html, with +the job number, form name, and destination options (url, message, popup_url, +error_url) as URL parameters. This popup will poll the server for the status +of the job, display a progress bar, and on completion, either redirect to +'url' or 'popup_url', display 'message' in the popup window, or (on failure) +display the job statustext as an error message. If 'error_url' is specified, +the "Close" button in the popup will then redirect the user to that location. + +<% include('/elements/xmlhttp.html', + 'method' => 'POST', + 'url' => $action, + 'subs' => [ 'start_job' ], + 'key' => $key, + ) +%> + +<& /elements/init_overlib.html &> + + + +<%init> + +my( $formname, $fields, $action, $url_or_message, $key ) = @_; +$key = '' unless defined $key; + +my %dest_info; +if ( ref($url_or_message) ) { #its a message or something + %dest_info = map { $_ => $url_or_message->{$_} } + grep { $url_or_message->{$_} } + qw( message url popup_url error_url reload_with_error ); +} else { + # it can also just be a url + %dest_info = ( 'url' => $url_or_message ); +} + +my $progress_url = URI->new($fsurl.'misc/progress-popup.html'); +$progress_url->query_form( + 'jobnum' => '_JOBNUM_', + 'formname' => $formname, + %dest_info, +); + +my $all_fields = 0; +my %copy_fields; +if (grep '/^ALL$/', @$fields) { + $all_fields = 1; +} else { + %copy_fields = map { $_ => 1 } @$fields; +} + +#stupid safari is caching the "location" of popup iframs, and submitting them +#instead of displaying them. this should prevent that. +my $popup_name = 'popup-'.random_id(); + +