X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fprogress-init.html;h=2ec248e322c01545e29f644d06c8943989dba79a;hb=b431ece7b4a71aa5771f44393da582692f668817;hp=7edb831c570d59be47d13e5c22c0b448e9ecbac5;hpb=d6047391feb3236374e16fd73240d9821d77fe06;p=freeside.git diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html index 7edb831c5..2ec248e32 100644 --- a/httemplate/elements/progress-init.html +++ b/httemplate/elements/progress-init.html @@ -1,45 +1,144 @@ -<% 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 () { + +<% include('/elements/xmlhttp.html', + 'method' => 'POST', + 'url' => $action, + 'subs' => [ 'start_job' ], + 'key' => $key, + ) +%> - document.OneTrueForm.submit.disabled=true; +% if (!$noinit) { +<& /elements/init_overlib.html &> +% $noinit = 1; +% } - overlib( 'Submitting job to server...', WIDTH, 420, HEIGHT, 128, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 ); + + +<%once> +my $noinit = 0; + +<%init> + +my( $formname, $fields, $action, $url_or_message, $key ) = @_; +$key = '' unless defined $key; + +my $url_or_message_link; +if ( ref($url_or_message) ) { #its a message or something + $url_or_message_link = 'message='. uri_escape( $url_or_message->{'message'} ); + $url_or_message_link .= ';url='. uri_escape( $url_or_message->{'url'} ) + if $url_or_message->{'url'}; + $url_or_message_link = 'popup_url=' .uri_escape( $url_or_message->{'popup_url'} ) + if $url_or_message->{'popup_url'}; + +} else { + $url_or_message_link = "url=$url_or_message"; +} + +#stupid safari is caching the "location" of popup iframs, and submitting them +#instead of displaying them. this should prevent that. +my $popup_name = 'popup-'.time. "-$$-". rand() * 2**32; + +