diff options
-rw-r--r-- | app/controllers/request_controller.rb | 1 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 34 | ||||
-rw-r--r-- | public/stylesheets/main.css | 11 |
3 files changed, 44 insertions, 2 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 0664093c3..b2f6e8631 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -599,6 +599,7 @@ class RequestController < ApplicationController view_html_prefix = render_to_string :partial => "request/view_html_prefix" html.sub!("<prefix-here>", view_html_prefix) + html.sub!("<attachment-url-here>", CGI.escape(@attachment_url)) @incoming_message.html_mask_stuff!(html) diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 9d0d5bea3..e69b80645 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -308,6 +308,23 @@ class FOIAttachment end end + # Whether this type can be shown in the Google Docs Viewer. + # PDF, PowerPoint and TIFF are listed on https://docs.google.com/viewer + # .doc and .docx were added later http://gmailblog.blogspot.com/2010/06/view-doc-attachments-right-in-your.html + def has_google_docs_viewer? + if self.content_type == 'application/vnd.ms-word': + return true + elsif self.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + return true + elsif self.content_type == 'application/pdf' + return true + elsif self.content_type == 'image/tiff' + return true + elsif self.content_type == 'application/vnd.ms-powerpoint' + return true + end + end + # Whether this type has a "View as HTML" def has_body_as_html? if self.content_type == 'text/plain' @@ -321,6 +338,11 @@ class FOIAttachment elsif self.content_type == 'application/rtf' return true end + # We use the same "View as HTML" link to embed the Google Doc Viewer + # (when it can't do a conversion locally) + if self.has_google_docs_viewer? + return true + end return false end @@ -382,6 +404,8 @@ class FOIAttachment IO.popen("/usr/bin/unrtf --html " + tempfile.path + "", "r") do |child| html = child.read() end + elsif self.has_google_docs_viewer? + html = '' # force error and using Google docs viewer else raise "No HTML conversion available for type " + self.content_type end @@ -402,7 +426,15 @@ class FOIAttachment body_without_tags = body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "") contains_images = html.match(/<img/mi) ? true : false if !$?.success? || html.size == 0 || (body_without_tags.size == 0 && !contains_images) - return "<html><head></head><body><p>Sorry, we were unable to convert this file to HTML. Please use the download link at the top right.</p></body></html>", wrapper_id + ret = "<html><head></head><body>"; + if self.has_google_docs_viewer? + wrapper_id = "wrapper_google_embed" + ret = ret + "<iframe src='http://docs.google.com/viewer?url=<attachment-url-here>&embedded=true' width='100%' height='100%' style='border: none;'></iframe>"; + else + ret = ret + "<p>Sorry, we were unable to convert this file to HTML. Please use the download link at the top right.</p>" + end + ret = ret + "</body></html>" + return ret, wrapper_id end return html, wrapper_id diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 0f8f414b1..a6a0f3409 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -244,6 +244,15 @@ body text-align: left; overflow: visible; } +#wrapper_google_embed { + position: relative; + clear: both; + width: 100%; + height: 90%; + margin: 0 0 0 0; + text-align: left; + overflow: visible; +} #view_html_content table { border-collapse: collapse; margin-bottom: 1em; @@ -863,7 +872,7 @@ a img.attachment_image { background-color: #E7E7E7; border-bottom: 1px solid #5f5f5f; padding: 0.5em 1em 0.5em 1em; - height: 34px; + height: 6%; } .view_html_logo { float: left; |