summaryrefslogtreecommitdiff
path: root/httemplate/elements
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/elements')
-rw-r--r--httemplate/elements/file-upload.html54
-rw-r--r--httemplate/elements/form-file_upload.html93
-rw-r--r--httemplate/elements/progress-init.html5
-rw-r--r--httemplate/elements/progress-popup.html19
4 files changed, 134 insertions, 37 deletions
diff --git a/httemplate/elements/file-upload.html b/httemplate/elements/file-upload.html
index 2859a676f..023bffb1e 100644
--- a/httemplate/elements/file-upload.html
+++ b/httemplate/elements/file-upload.html
@@ -1,10 +1,13 @@
-
-<script type="text/javascript">
+<SCRIPT TYPE="text/javascript">
function doUpload(form, callback) {
var name = 'form' + Math.floor(Math.random() * 99999); // perlize?
var d = document.createElement('DIV');
- d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+name+'" name="'+name+'" onload="uploadComplete(\''+name+'\')"></iframe>';
+ d.innerHTML = '<iframe style="display:none" src="about:blank" ' +
+ 'id="' + name + '" ' +
+ 'name="' + name + '" ' +
+ 'onload="uploadComplete(\'' + name + '\')">' +
+ '</iframe>';
document.body.appendChild(d);
var i = document.getElementById(name);
@@ -32,8 +35,8 @@
document.getElementById('r').innerHTML = d.body.innerHTML;
if (typeof(i.onComplete) == 'function') {
var p;
- if (p = d.body.innerHTML.indexOf("Freeside File Upload Successful ") >= 0) {
- var v = d.body.innerHTML.substr(p+33)
+ if (p = d.body.innerHTML.indexOf("File Upload Successful ") >= 0) {
+ var v = d.body.innerHTML.substr(p+24);
var u = document.getElementById('uploaded_files');
v = v.substr(0, v.indexOf(';'));
u.value = v;
@@ -44,37 +47,28 @@
}
}
-</script>
+</SCRIPT>
+
+<INPUT TYPE="hidden" NAME="uploaded_files" ID="uploaded_files" VALUE="" />
+
+<INPUT TYPE="hidden" NAME="upload_fields" VALUE="<% join(',', @field) %>" />
- <input type="hidden" name="uploaded_files" id="uploaded_files" value="" />
- <input type="hidden" name="upload_fields" value="<% join(',', @field) %>" />
% foreach (@field) {
- <tr>
- <th><% shift @label %></th>
- <td><input type="file" name="<% $_ %>" /></td>
- </tr>
+ <TR>
+ <TH><% shift @label %></TH>
+ <TD><INPUT TYPE="file" NAME="<% $_ %>" /></TD>
+ </TR>
% }
- <div style="display:<% $debug ? 'visible' : 'none' %>">Debugging: <pre id="r"></pre></div>
-
-<%init>
-my %param = @_;
-my $debug = $param{'debug'};
+<DIV STYLE="display:<% $param{debug} ? 'visible' : 'none' %>">
+ Debugging: <PRE ID="r"></PRE>
+</DIV>
-my $callback = $param{'callback'} || "''";
+<%init>
-my @label = ();
-if ( ref($param{'label'}) ) {
- push @label, @{$param{'label'}};
-}else{
- push @label, $param{'label'};
-}
+my %param = @_;
-my @field = ();
-if ( ref($param{'field'}) ) {
- push @field, @{$param{'field'}};
-}else{
- push @field, $param{'field'};
-}
+my @label = ref($param{'label'}) ? @{$param{'label'}} : ($param{'label'});
+my @field = ref($param{'field'}) ? @{$param{'field'}} : ($param{'field'});
</%init>
diff --git a/httemplate/elements/form-file_upload.html b/httemplate/elements/form-file_upload.html
new file mode 100644
index 000000000..f398ba42d
--- /dev/null
+++ b/httemplate/elements/form-file_upload.html
@@ -0,0 +1,93 @@
+<%doc>
+
+Example:
+
+ <% include( '/elements/form-file_upload.html',
+
+ 'name' => 'form_name',
+ 'action' => 'process/target.cgi', #progress-init target
+ 'fields' => [ 'other', 'form', 'fields' ],
+ 'num_files' => 1, #or more
+
+ 'url' => $url
+ #OR
+ 'message' => 'Message',
+
+ #optional
+ 'key' => 'unique_key', #for using more than once on a page
+ )
+
+% #...
+
+% # num_files=>1
+ include( '/elements/file-upload.html',
+ 'field' => 'element',
+ 'label' => 'Label',
+ )
+
+% # OR
+
+% # num_files=>2 # or more
+ include( '/elements/file-upload.html',
+ 'field' => [ 'element', 'element2', ], #etc.
+ 'label' => [ 'Label', 'Label2', ], #etc.
+ )
+
+
+%>
+
+</%doc>
+
+<% include( '/elements/progress-init.html',
+ $opt{name},
+ $opt{fields},
+ $opt{action},
+ $msg_or_url,
+ $opt{key},
+ )
+%>
+
+<SCRIPT>
+
+ function <% $opt{key} %>gotUploaded(success, message) {
+
+ var uploaded = document.getElementById('uploaded_files');
+ var a = uploaded.value.split(',');
+ if (uploaded.value.split(',').length == <% $opt{num_files} %>){
+ process();
+ }else{
+ var p = document.getElementById('uploadError');
+ p.innerHTML='<FONT SIZE="+1" COLOR="#ff0000">Error: '+message+'</FONT><BR><BR>';
+ p.style='display:visible';
+ return false;
+ }
+
+ }
+
+</SCRIPT>
+
+<div style="display:none:" id="uploadError"></div>
+
+<FORM NAME = "<% $opt{name} %>"
+ ACTION = "<% $fsurl %>misc/file-upload.html"
+ METHOD = "POST"
+ ENCTYPE = "multipart/form-data"
+ onSubmit = "return doUpload(this, <% $opt{key} %>gotUploaded)"
+>
+
+<%init>
+
+#my( $formname, $fields, $action, $url_or_message, $key ) = @_;
+my %opt = ref($_[0]) ? %{ $_[0] } : @_;
+
+my $key = exists $opt{key} ? $opt{key} : '';
+
+push @{ $opt{fields} }, 'uploaded_files';
+
+my $msg_or_url = $opt{message}
+ ? { 'message' => $opt{message},
+ 'url' => $opt{url},
+ }
+ : $opt{url};
+
+</%init>
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
index 2cde86f5b..194fc7480 100644
--- a/httemplate/elements/progress-init.html
+++ b/httemplate/elements/progress-init.html
@@ -73,8 +73,9 @@ $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 = '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";
}
diff --git a/httemplate/elements/progress-popup.html b/httemplate/elements/progress-popup.html
index cda704a12..0bd71ff4a 100644
--- a/httemplate/elements/progress-popup.html
+++ b/httemplate/elements/progress-popup.html
@@ -41,15 +41,24 @@ function updateStatus( status_statustext ) {
//jsrsExecute( '<%$p%>elements/jsrsServer.html', updateStatus, 'job_status', '<% $jobnum %>' );
job_status( '<% $jobnum %>', updateStatus );
} else if ( status.indexOf('complete') > -1 ) {
-% if ( $message ) {
+% if ( $message ) {
+%
+% my $onClick = $url
+% ? "window.top.location.href = \\'$url\\';"
+% : 'parent.nd(1);';
document.getElementById("progress_message").innerHTML = "<% $message %>";
document.getElementById("progress_bar").innerHTML = '';
- document.getElementById("progress_percent").innerHTML = '<INPUT TYPE="button" VALUE="OK" onClick="parent.nd(1);">';
+ document.getElementById("progress_percent").innerHTML =
+ '<INPUT TYPE="button" VALUE="OK" onClick="<% $onClick %>">';
document.getElementById("progress_jobnum").innerHTML = '';
- if ( parent.document.<%$formname%>.submit.disabled == true ) {
- parent.document.<%$formname%>.submit.disabled=false;
- }
+
+% unless ( $url ) {
+ if ( parent.document.<%$formname%>.submit.disabled == true ) {
+ parent.document.<%$formname%>.submit.disabled=false;
+ }
+% }
+
% } elsif ( $url ) {
window.top.location.href = '<% $url %>';