diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-14 08:33:53 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-14 08:33:53 +0000 |
commit | 2f5c17a0f6eac2f50e61053e06672a1e83d4f598 (patch) | |
tree | d2be24de5e56327265ced2b87ff37439185d0f87 /app/helpers | |
parent | c3e8d1d5124635a7ca49eec195a855d5d14dab77 (diff) | |
download | redmine-2f5c17a0f6eac2f50e61053e06672a1e83d4f598.tar.gz redmine-2f5c17a0f6eac2f50e61053e06672a1e83d4f598.zip |
Optimization: load attachments when needed.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3581 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ff877f18f..5663cc6d6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -414,13 +414,11 @@ module ApplicationHelper only_path = options.delete(:only_path) == false ? false : true # when using an image link, try to use an attachment, if possible - attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) - - if attachments - attachments = attachments.sort_by(&:created_on).reverse + if options[:attachments] || (obj && obj.respond_to?(:attachments)) + attachments = nil text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| filename, ext, alt, alttext = $1.downcase, $2, $3, $4 - + attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse # search for the picture in attachments if found = attachments.detect { |att| att.filename.downcase == filename } image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found @@ -592,6 +590,7 @@ module ApplicationHelper :class => (prefix == 'export' ? 'source download' : 'source') end when 'attachment' + attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) if attachments && attachment = attachments.detect {|a| a.filename == name } link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment' |