3 In misc/something.html:
6 <INPUT TYPE="hidden" NAME="recordnum" VALUE="42">
7 <INPUT TYPE="hidden" NAME="what_to_do" VALUE="delete">
8 <% include( '/elements/progress-init.html',
10 [ 'recordnum', 'what_to_do' ],
11 $p.'misc/process_something.html',
12 { url => $p.'where_to_go_next.html' },
13 #or { message => 'Finished!' },
14 #or { url => $p.'where_to_go.html',
15 message => 'Finished' },
16 # which displays the message, then waits for confirmation before
17 # redirecting to the URL.
18 #or { popup_url => $p.'popup_contents.html' }
19 # which loads that URL into the popup after completion
22 <SCRIPT TYPE="text/javascript>process();</SCRIPT>
24 In misc/process_something.html:
27 my $server = FS::UI::Web::JSRPC->new('FS::something::process_whatever', $cgi);
29 <% $server->process %>
33 sub process_whatever { #class method
35 my $param = thaw(base64_decode(shift));
36 # param = { 'recordnum' => 42, 'what_to_do' => delete }
37 # make use of this as you like
39 $job->update_statustext(20);
41 $job->update_statustext(40);
43 $job->update_statustext(60);
45 return 'this value will be ignored';
49 <% include('/elements/xmlhttp.html',
52 'subs' => [ 'start_job' ],
57 <& /elements/init_overlib.html &>
59 <SCRIPT TYPE="text/javascript">
61 function <%$key%>process () {
63 //alert('<%$key%>process for form <%$formname%>');
65 if ( document.<%$formname%>.submit.disabled == false ) {
66 document.<%$formname%>.submit.disabled=true;
69 overlib( 'Submitting job to server...', WIDTH, 444, HEIGHT, 168, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
71 var Hash = new Array();
74 for (var i = 0; i<document.<%$formname%>.elements.length; i++) {
75 field = document.<%$formname%>.elements[i];
76 if ( <% join(' || ', map { "(field.name.indexOf('$_') > -1)" } @$fields ) %>
79 if ( field.type == 'select-multiple' ) {
80 //alert('select-multiple ' + field.name);
81 for (var j=0; j < field.options.length; j++) {
82 if ( field.options[j].selected ) {
83 //alert(field.name + ' => ' + field.options[j].value);
84 Hash[x++] = field.name;
85 Hash[x++] = field.options[j].value;
88 } else if ( ( field.type != 'radio' && field.type != 'checkbox' )
89 || ( ( field.type == 'radio' || field.type == 'checkbox' )
90 && document.<%$formname%>.elements[i].checked
94 Hash[x++] = field.name;
95 Hash[x++] = field.value;
101 // jsrsExecute( '<% $action %>', <%$key%>myCallback, 'start_job', Hash );
103 //alert('start_job( ' + Hash + ', <%$key%>myCallback )' );
104 //alert('start_job()' );
105 <%$key%>start_job( Hash, <%$key%>myCallback );
109 function <%$key%>myCallback( jobnum ) {
111 overlib( OLiframeContent('<%$fsurl%>elements/progress-popup.html?jobnum=' + jobnum + ';<%$url_or_message_link%>;formname=<%$formname%>' , 444, 168, '<% $popup_name %>'), CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
119 my( $formname, $fields, $action, $url_or_message, $key ) = @_;
120 $key = '' unless defined $key;
122 my $url_or_message_link;
123 if ( ref($url_or_message) ) { #its a message or something
124 $url_or_message_link = 'message='. uri_escape( $url_or_message->{'message'} );
125 $url_or_message_link .= ';url='. uri_escape( $url_or_message->{'url'} )
126 if $url_or_message->{'url'};
127 $url_or_message_link = 'popup_url=' .uri_escape( $url_or_message->{'popup_url'} )
128 if $url_or_message->{'popup_url'};
131 $url_or_message_link = "url=$url_or_message";
134 #stupid safari is caching the "location" of popup iframs, and submitting them
135 #instead of displaying them. this should prevent that.
136 my $popup_name = 'popup-'.time. "-$$-". rand() * 2**32;