combine ticket notification scrips, #15353
[freeside.git] / httemplate / elements / form-file_upload.html
1 <%doc>
2
3 Example:
4
5   <% include( '/elements/form-file_upload.html',
6
7                 'name'      => 'form_name',
8                 'action'    => 'process/target.cgi', #progress-init target
9                 'fields'    => [ 'other', 'form', 'fields' ],
10                 'num_files' => 1, #or more
11
12                 'url' => $url
13                 #AND/OR
14                 'message' => 'Message',
15
16                 #optional
17                 'key' => 'unique_key', #for using more than once on a page
18             )
19
20 % #... 
21
22 % # num_files=>1
23   include( '/elements/file-upload.html',
24              'field'    => 'element',
25              'label'    => 'Label',
26          )
27
28 % # OR
29
30 % # num_files=>2 # or more
31   include( '/elements/file-upload.html',
32              'field'    => [ 'element', 'element2', ], #etc.
33              'label'    => [ 'Label',   'Label2',   ], #etc.
34          )
35
36
37 %>
38
39 </%doc>
40
41 <% include( '/elements/progress-init.html',
42               $opt{name},
43               $opt{fields},
44               $opt{action},
45               $msg_or_url,
46               $opt{key},
47           )
48 %>
49
50 <SCRIPT>
51
52   function <% $opt{key} %>gotUploaded(success, message) {
53
54     var uploaded = document.getElementById('uploaded_files');
55     var a = uploaded.value.split(',');
56     if (success && uploaded.value.split(',').length == <% $opt{num_files} %>){
57       process(); 
58     }else{
59       var p = document.getElementById('uploadError');
60       p.innerHTML='<FONT SIZE="+1" COLOR="#ff0000">Error: '+message+'</FONT><BR><BR>';
61       p.style='display:visible';
62       return false;
63     }
64     
65   }
66
67 </SCRIPT>
68
69 <div style="display:none:" id="uploadError"></div>
70
71 <FORM NAME     = "<% $opt{name} %>"
72       ACTION   = "<% $fsurl %>misc/file-upload.html"
73       METHOD   = "POST"
74       ENCTYPE  = "multipart/form-data"
75       onSubmit = "<% $opt{onsubmit} %>return doUpload(this, <% $opt{key} %>gotUploaded)"
76 >
77
78 <%init>
79
80 #my( $formname, $fields, $action, $url_or_message, $key ) = @_;
81 my %opt = ref($_[0]) ? %{ $_[0] } : @_;
82
83 my $key = exists $opt{key} ? $opt{key} : '';
84
85 push @{ $opt{fields} }, 'uploaded_files';
86
87 my $msg_or_url = $opt{message}
88                    ? { 'message' => $opt{message},
89                        'url'     => $opt{url},
90                      }
91                    : $opt{url};
92
93 $opt{onsubmit} .= ';' if $opt{onsubmit} && $opt{onsubmit} !~ /;\s*$/;
94
95 </%init>