combine ticket notification scrips, #15353
[freeside.git] / httemplate / elements / progress-init.html
index 1c96a54..2ec248e 100644 (file)
@@ -1,17 +1,51 @@
-%
-%  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'} )
-%  } else {
-%    $url_or_message_link = "url=$url_or_message";
-%  }
-%
+<%doc>
+Example:
+In misc/something.html:
 
+  <FORM NAME="MyForm">
+  <INPUT TYPE="hidden" NAME="recordnum" VALUE="42">
+  <INPUT TYPE="hidden" NAME="what_to_do" VALUE="delete">
+  <% include( '/elements/progress-init.html',
+             'MyForm', 
+             [ 'recordnum', 'what_to_do' ],
+             $p.'misc/process_something.html',
+             { url => $p.'where_to_go_next.html' },
+         #or { message => 'Finished!' },
+         #or { url => $p.'where_to_go.html',
+               message => 'Finished' },
+         # which displays the message, then waits for confirmation before 
+         # redirecting to the URL.
+         #or { popup_url => $p.'popup_contents.html' }
+         # which loads that URL into the popup after completion
+         ) %>
+  </FORM>
+  <SCRIPT TYPE="text/javascript>process();</SCRIPT>
 
+In misc/process_something.html:
+
+<%init>
+my $server = FS::UI::Web::JSRPC->new('FS::something::process_whatever', $cgi);
+</%init>
+<% $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';
+}
+
+</%doc>
 <% include('/elements/xmlhttp.html',
               'method' => 'POST',
               'url'    => $action,
               'key'    => $key,
            )
 %>
-<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
-<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
+
+% if (!$noinit) { 
+<& /elements/init_overlib.html &>
+%   $noinit = 1;
+% }
+
 <SCRIPT TYPE="text/javascript">
-function OLiframeContent(src, width, height, name) {
-  return ('<iframe src="'+src+'" width="'+width+'" height="'+height+'"'
-   +(name?' name="'+name+'" id="'+name+'"':'')+' scrolling="auto">'
-   +'<div>[iframe not supported]</div></iframe>');
-}
 
 function <%$key%>process () {
 
@@ -78,8 +111,34 @@ function <%$key%>process () {
 
 function <%$key%>myCallback( jobnum ) {
 
-  overlib( OLiframeContent('<%$p%>elements/progress-popup.html?jobnum=' + jobnum + ';<%$url_or_message_link%>;formname=<%$formname%>' , 444, 168, 'progress_popup'), CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
+  overlib( OLiframeContent('<%$p%>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 );
 
 }
 
 </SCRIPT>
+
+<%once>
+my $noinit = 0;
+</%once>
+<%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;
+
+</%init>