修复资源搜索,资源列表显示错误 #1262

链接解析方法不对
This commit is contained in:
sw 2014-09-17 15:04:41 +08:00
parent 1976aa9c72
commit 0a02fbf10e
5 changed files with 80 additions and 61 deletions

View File

@ -126,7 +126,7 @@ module ApplicationHelper
# Options: # Options:
# * :text - Link text (default to attachment filename) # * :text - Link text (default to attachment filename)
# * :download - Force download (default: false) # * :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: '...')) text = h(truncate(options.delete(:text) || attachment.filename, length: 25, omission: '...'))
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path) html_options = options.slice!(:only_path)
@ -134,6 +134,18 @@ module ApplicationHelper
link_to text, url, html_options link_to text, url, html_options
end 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={}) def link_to_attachment_img(attachment, options={})
text = options.delete(:text) || attachment.filename text = options.delete(:text) || attachment.filename
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path

View File

@ -3,13 +3,15 @@
<% if attachments.count > 1 && attachment != attachments.first%> <% if attachments.count > 1 && attachment != attachments.first%>
<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<% end %> <% 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? %> <% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'), <%= link_to image_tag('magnifier.png'),
:controller => 'attachments', :action => 'show', :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename %> :id => attachment, :filename => attachment.filename %>
<% end %> <% end %>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> <span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %>
</span>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span> <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% end -%> <% end -%>

View File

@ -2,7 +2,7 @@
<% for attachment in attachments %> <% for attachment in attachments %>
<p style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"> <p style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
<span title="<%= attachment.filename%>"> <span title="<%= attachment.filename%>">
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> <%= link_to_short_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
</span> </span>
<% if attachment.is_text? %> <% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'), <%= link_to image_tag('magnifier.png'),

View File

@ -2,12 +2,14 @@
<% if attachments.count > 1 && attachment != attachments.first%> <% if attachments.count > 1 && attachment != attachments.first%>
<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<% end %> <% 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? %> <% if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'), <%= link_to image_tag('magnifier.png'),
:controller => 'attachments', :action => 'show', :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename %> :id => attachment, :filename => attachment.filename %>
<% end %> <% end %>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> <span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %>
</span>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span> <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% end -%> <% end -%>

View File

@ -1,68 +1,71 @@
<% content_for :top_field do%> <% content_for :top_field do%>
<%= render 'search_bar' %> <%= render 'search_bar' %>
<% end %> <% end %>
<div class="resource_sum"> <div class="resource_sum" id="IE_resource_sum_css">
<% @attach_array.each do |k|%> <% @attach_array.each do |k|%>
<div class="line_block"> <div class="line_block" >
<p> <p>
<%= @str_arr.shift %> <%= @str_arr.shift %>
</p> </p>
<div class="table1"> <div class="table1">
<div class='table_row1'> <div class='table_row1'>
<div class='table_cell1 filename1' style='text-align: center;'><%=l(:label_attachment)%></div> <div class='table_cell1 filename1' style='text-align: center;'><%=l(:label_attachment)%></div>
<div class='table_cell1 filedown1'><%=l(:field_downloads)%></div> <div class='table_cell1 filedown1'><%=l(:field_downloads)%></div>
<div class='table_cell1 downicon1'><%=l(:button_download)%></div> <div class='table_cell1 downicon1'><%=l(:button_download)%></div>
</div> </div>
</div> </div>
<div class="table1"> <div class="table1">
<% k.each do |c1|%> <% k.each do |c1|%>
<div class="table_row1 <%= cycle 'odd', 'even' %>"> <div class="table_row1 <%= cycle 'odd', 'even' %>">
<div class="filename table_cell1 filename1" > <div class="filename table_cell1 filename1" >
<%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %> <%= link_to c1.filename, (attachFromUrl c1), {:title => c1.filename, :target => "_blank"} %>
</div> </div>
<div class="table_cell1 filedown1"> <div class="table_cell1 filedown1">
<%= c1.downloads %> <%= c1.downloads %>
</div> </div>
<div class="table_cell1 downicon1 filename download_icon" > <div class="table_cell1 downicon1 filename download_icon" >
<%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%> <%= link_to_attachment c1, {:download => true, :text => image_tag("/images/button/download.png", width: "22px", alt: l(:button_download)) }%>
</div> </div>
</div> </div>
<% end -%> <% end -%>
</div> </div>
</div> </div>
<% end; reset_cycle %> <% end; reset_cycle %>
</div> </div>
<script type='text/javascript'> <script type='text/javascript'>
function validate_required(field,alerttxt) function validate_required(field,alerttxt)
{
with (field)
{ {
with (field) if (value==null||value=="")
{ {alert(alerttxt);$.find('form').attr("data-submitted",'');return false}
if (value==null||value=="") else {return true}
{alert(alerttxt);$.find('form').attr("data-submitted",'');return false}
else {return true}
}
} }
}
function validate_form(thisform) { function validate_form(thisform) {
with (thisform) with (thisform)
{ {
if (validate_required(name,"name must be filled out!")==false) if (validate_required(name,"name must be filled out!")==false)
{name.focus();return false} {name.focus();return false}
}
} }
$(document).ready(function($) { }
$('.download_icon').find("a").attr("target", "_blank"); $(document).ready(function($) {
$('.download_icon').each(function(){ $('.download_icon').find("a").attr("target", "_blank");
$(this).mouseenter(function(event) { $('.download_icon').each(function(){
$(this).find('img').attr("src", "/images/button/download_focus.png") $(this).mouseenter(function(event) {
}); $(this).find('img').attr("src", "/images/button/download_focus.png")
$(this).mouseleave(function(event) { });
$(this).find('img').attr("src", "/images/button/download.png") $(this).mouseleave(function(event) {
}); $(this).find('img').attr("src", "/images/button/download.png")
}); });
}); });
if(navigator.appName=="Microsoft Internet Explorer"){
$("#IE_resource_sum_css").children(".line_block").css("width","45%");
}
});
</script> </script>