summaryrefslogtreecommitdiff
path: root/httemplate/elements/progress-init.html
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/elements/progress-init.html')
-rw-r--r--httemplate/elements/progress-init.html129
1 files changed, 129 insertions, 0 deletions
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
new file mode 100644
index 0000000..8b8da66
--- /dev/null
+++ b/httemplate/elements/progress-init.html
@@ -0,0 +1,129 @@
+<%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!' },
+ ) %>
+ </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,
+ 'subs' => [ 'start_job' ],
+ 'key' => $key,
+ )
+%>
+
+<% include('/elements/init_overlib.html') %>
+
+<SCRIPT TYPE="text/javascript">
+
+function <%$key%>process () {
+
+ //alert('<%$key%>process for form <%$formname%>');
+
+ if ( document.<%$formname%>.submit.disabled == false ) {
+ document.<%$formname%>.submit.disabled=true;
+ }
+
+ overlib( 'Submitting job to server...', WIDTH, 444, HEIGHT, 168, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
+
+ var Hash = new Array();
+ var x = 0;
+ var fieldName;
+ for (var i = 0; i<document.<%$formname%>.elements.length; i++) {
+ field = document.<%$formname%>.elements[i];
+ if ( <% join(' || ', map { "(field.name.indexOf('$_') > -1)" } @$fields ) %>
+ )
+ {
+ if ( field.type == 'select-multiple' ) {
+ //alert('select-multiple ' + field.name);
+ for (var j=0; j < field.options.length; j++) {
+ if ( field.options[j].selected ) {
+ //alert(field.name + ' => ' + field.options[j].value);
+ Hash[x++] = field.name;
+ Hash[x++] = field.options[j].value;
+ }
+ }
+ } else if ( ( field.type != 'radio' && field.type != 'checkbox' )
+ || ( ( field.type == 'radio' || field.type == 'checkbox' )
+ && document.<%$formname%>.elements[i].checked
+ )
+ )
+ {
+ Hash[x++] = field.name;
+ Hash[x++] = field.value;
+ }
+ }
+ }
+
+ // jsrsPOST = true;
+ // jsrsExecute( '<% $action %>', <%$key%>myCallback, 'start_job', Hash );
+
+ //alert('start_job( ' + Hash + ', <%$key%>myCallback )' );
+ //alert('start_job()' );
+ <%$key%>start_job( Hash, <%$key%>myCallback );
+
+}
+
+function <%$key%>myCallback( jobnum ) {
+
+ 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>
+
+<%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'};
+} 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>