From 7cef7c08ebab0374f8dced2f047b5a8bf281c44c Mon Sep 17 00:00:00 2001 From: Arne Georg Gleditsch Date: Fri, 6 Aug 2010 22:12:55 +0200 Subject: Add save button. --- lib/LXRng/Web.pm | 25 +++++++++++++++++++++++++ tmpl/header.tt2 | 10 +++++++++- webroot/.static/css/lxrng.css | 5 +++++ webroot/.static/js/lxrng-funcs.js | 6 ++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm index 2ae3fa4..20ff899 100644 --- a/lib/LXRng/Web.pm +++ b/lib/LXRng/Web.pm @@ -821,6 +821,28 @@ sub generate_pdf { } +# Generate raw file for download + +sub generate_raw { + my ($query, $context, $template, $path) = @_; + + my $ver = $context->release; + my $rep = $context->config->{'repository'}; + my $node = $rep->node($path, $ver); + + die "No such file" unless $node; + + my $handle = $node->handle(); + print($query->header(-type => 'application/octet-stram', + -content_disposition => + "attachment; filename=$path")); + my $buf = ''; + while (sysread($handle, $buf, 65536) > 0) { + print($buf); + } +} + + sub handle { my ($self, $query) = @_; @@ -843,6 +865,9 @@ sub handle { elsif ($context->path =~ /^[+ ]print=(.*)/) { generate_pdf($query, $context, $template, $1); } + elsif ($context->path =~ /^[+ ]save=(.*)/) { + generate_raw($query, $context, $template, $1); + } else { if ($context->path =~ /^[+ ](search|code|ident|file|text|ambig)(?:=(.*)|)/) diff --git a/tmpl/header.tt2 b/tmpl/header.tt2 index 5360b4f..5e6f12d 100644 --- a/tmpl/header.tt2 +++ b/tmpl/header.tt2 @@ -55,7 +55,7 @@ %][% elem.node | html %][% END %] - History + + +
+ +
+
diff --git a/webroot/.static/css/lxrng.css b/webroot/.static/css/lxrng.css index acc7d92..c5a46eb 100644 --- a/webroot/.static/css/lxrng.css +++ b/webroot/.static/css/lxrng.css @@ -213,6 +213,11 @@ button.print { background: #F0F0F0; } +button.save { + border: 0; + background: #F0F0F0; +} + table.directory td.name { width: 30ex; } diff --git a/webroot/.static/js/lxrng-funcs.js b/webroot/.static/js/lxrng-funcs.js index a612055..5da1ef9 100644 --- a/webroot/.static/js/lxrng-funcs.js +++ b/webroot/.static/js/lxrng-funcs.js @@ -284,15 +284,21 @@ function load_file_finalize(content) { var full_path = full_tree + '/' + pending_file.replace(/^\/?/, ''); var print = document.getElementById('lxr_print'); + var save = document.getElementById('lxr_save'); var dirlist = document.getElementById('content_dir'); if (dirlist) { print.style.display = 'none'; + save.style.display = 'none'; } else { var pform = document.getElementById('print_form'); pform.action = '../' + full_tree + '/+print=' + pending_file.replace(/^\/?/, ''); print.style.display = 'inline'; + var sform = document.getElementById('save_form'); + sform.action = '../' + full_tree + '/+save=' + + pending_file.replace(/^\/?/, ''); + save.style.display = 'inline'; } if (hash_check) { -- cgit v1.2.3