diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2010-08-06 22:12:55 +0200 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2010-08-06 22:12:55 +0200 |
commit | 7cef7c08ebab0374f8dced2f047b5a8bf281c44c (patch) | |
tree | 77e355106206b39d311fab3849239d41e918189b | |
parent | 1f63a948e0b2de15dba55610cd62f31f15e1167b (diff) |
Add save button.
-rw-r--r-- | lib/LXRng/Web.pm | 25 | ||||
-rw-r--r-- | tmpl/header.tt2 | 10 | ||||
-rw-r--r-- | webroot/.static/css/lxrng.css | 5 | ||||
-rw-r--r-- | webroot/.static/js/lxrng-funcs.js | 6 |
4 files changed, 45 insertions, 1 deletions
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 @@ %]<a href="[% elem.path | html %]">[% elem.node | html %]</a>[% END %] </span> - <img src="../.static/gfx/rolldown.png" alt="History"> + <!-- <img src="../.static/gfx/rolldown.png" alt="History"> --> <span id="lxr_print" [% IF is_ajax || node.name.match('/$') %]style="display: none;"[% END %]> <form action="+print=[% node.name | html %]" method="post" id="print_form"> @@ -64,6 +64,14 @@ </button> </form> </span> + <span id="lxr_save" + [% IF is_ajax || node.name.match('/$') %]style="display: none;"[% END %]> + <form action="+save=[% node.name | html %]" method="post" id="save_form"> + <button type="submit" class="save"> + <img src="../.static/gfx/save.png" alt="Save"> + </button> + </form> + </span> </span> <div class="lxr_menu"> 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) { |