overlib include
[freeside.git] / httemplate / elements / progress-init.html
1 <% include('/elements/xmlhttp.html',
2               'method' => 'POST',
3               'url'    => $action,
4               'subs'   => [ 'start_job' ],
5               'key'    => $key,
6            )
7 %>
8
9 <% include('/elements/init_overlib.html') %>
10
11 <SCRIPT TYPE="text/javascript">
12
13 function <%$key%>process () {
14
15   //alert('<%$key%>process for form <%$formname%>');
16
17   if ( document.<%$formname%>.submit.disabled == false ) {
18     document.<%$formname%>.submit.disabled=true;
19   }
20
21   overlib( 'Submitting job to server...', WIDTH, 444, HEIGHT, 168, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
22
23   var Hash = new Array();
24   var x = 0;
25   var fieldName;
26   for (var i = 0; i<document.<%$formname%>.elements.length; i++) {
27     field  = document.<%$formname%>.elements[i];
28     if ( <% join(' || ', map { "(field.name.indexOf('$_') > -1)" } @$fields ) %>
29        )
30     {
31         if ( field.type == 'select-multiple' ) {
32           //alert('select-multiple ' + field.name);
33           for (var j=0; j < field.options.length; j++) {
34             if ( field.options[j].selected ) {
35               //alert(field.name + ' => ' + field.options[j].value);
36               Hash[x++] = field.name;
37               Hash[x++] = field.options[j].value;
38             }
39           }
40         } else if (    ( field.type != 'radio'  && field.type != 'checkbox' )
41                     || ( ( field.type == 'radio' || field.type == 'checkbox' )
42                          && document.<%$formname%>.elements[i].checked
43                        )
44                   )
45         {
46           Hash[x++] = field.name;
47           Hash[x++] = field.value;
48         }
49     }
50   }
51
52   // jsrsPOST = true;
53   // jsrsExecute( '<% $action %>', <%$key%>myCallback, 'start_job', Hash );
54
55   //alert('start_job( ' + Hash + ', <%$key%>myCallback )' );
56   //alert('start_job()' );
57   <%$key%>start_job( Hash, <%$key%>myCallback );
58
59 }
60
61 function <%$key%>myCallback( jobnum ) {
62
63   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 );
64
65 }
66
67 </SCRIPT>
68
69 <%init>
70
71 my( $formname, $fields, $action, $url_or_message, $key ) = @_;
72 $key = '' unless defined $key;
73
74 my $url_or_message_link;
75 if ( ref($url_or_message) ) { #its a message or something
76   $url_or_message_link =
77     'message='. uri_escape( $url_or_message->{'message'} )
78 } else {
79   $url_or_message_link = "url=$url_or_message";
80 }
81
82 #stupid safari is caching the "location" of popup iframs, and submitting them
83 #instead of displaying them.  this should prevent that.
84 my $popup_name = 'popup-'.time. "-$$-". rand() * 2**32;
85
86 </%init>