diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b63f1071b..f976918d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -126,7 +126,7 @@ module ApplicationHelper # Options: # * :text - Link text (default to attachment filename) # * :download - Force download (default: false) - def link_to_attachment(attachment, options={}) + def link_to_short_attachment(attachment, options={}) text = h(truncate(options.delete(:text) || attachment.filename, length: 25, omission: '...')) route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path html_options = options.slice!(:only_path) @@ -134,6 +134,18 @@ module ApplicationHelper link_to text, url, html_options end + # Generates a link to an attachment. + # Options: + # * :text - Link text (default to attachment filename) + # * :download - Force download (default: false) + def link_to_attachment(attachment, options={}) + text = options.delete(:text) || attachment.filename + route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path + html_options = options.slice!(:only_path) + url = send(route_method, attachment, attachment.filename, options) + link_to text, url, html_options + end + def link_to_attachment_img(attachment, options={}) text = options.delete(:text) || attachment.filename route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path diff --git a/app/views/attachments/_app_link.html.erb b/app/views/attachments/_app_link.html.erb index 6934b76e1..263f51dc8 100644 --- a/app/views/attachments/_app_link.html.erb +++ b/app/views/attachments/_app_link.html.erb @@ -3,13 +3,15 @@ <% if attachments.count > 1 && attachment != attachments.first%>
                 <% end %> - <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> - <%= h(" - #{attachment.description}") unless attachment.description.blank? %> + + <%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% end -%> diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 2b12b21d1..de43dce4c 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -2,7 +2,7 @@ <% for attachment in attachments %>

- <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), diff --git a/app/views/homework_attach/_app_link.html.erb b/app/views/homework_attach/_app_link.html.erb index 48f116ce6..3aba96d27 100644 --- a/app/views/homework_attach/_app_link.html.erb +++ b/app/views/homework_attach/_app_link.html.erb @@ -2,12 +2,14 @@ <% if attachments.count > 1 && attachment != attachments.first%>
                 <% end %> - <%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> + <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <% if attachment.is_text? %> <%= link_to image_tag('magnifier.png'), :controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename %> <% end %> - <%= h(" - #{attachment.description}") unless attachment.description.blank? %> + + <%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %> + (<%= number_to_human_size attachment.filesize %>) <% end -%> diff --git a/app/views/stores/index.html.erb b/app/views/stores/index.html.erb index 47ea32b91..5df6ecca8 100644 --- a/app/views/stores/index.html.erb +++ b/app/views/stores/index.html.erb @@ -1,68 +1,71 @@ <% content_for :top_field do%> - <%= render 'search_bar' %> + <%= render 'search_bar' %> <% end %> -

- <% @attach_array.each do |k|%> -
-

- <%= @str_arr.shift %> -

+
+<% @attach_array.each do |k|%> +
+

+ <%= @str_arr.shift %> +

-
-
-
<%=l(:label_attachment)%>
-
<%=l(:field_downloads)%>
-
<%=l(:button_download)%>
-
-
+
+
+
<%=l(:label_attachment)%>
+
<%=l(:field_downloads)%>
+
<%=l(:button_download)%>
+
+
-
- <% k.each do |c1|%> -
-
- <%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %> -
-
- <%= c1.downloads %> -
-
- <%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%> -
-
- <% end -%> -
+
+ <% k.each do |c1|%> +
+
+ <%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %> +
+
+ <%= c1.downloads %> +
+
+ <%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%> +
+
+ <% end -%> +
-
- <% end; reset_cycle %> +
+<% end; reset_cycle %>
\ No newline at end of file