2015-04-29 17:50:35 +08:00
|
|
|
<script type="text/javascript">
|
|
|
|
document.addEventListener('DOMContentLoaded',function(){
|
|
|
|
var img = document.getElementsByName('issue_attachment_picture');
|
2015-04-30 10:47:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
function getImgNaturalStyle(img, callback) {
|
|
|
|
var nWidth, nHeight;
|
|
|
|
if (typeof img.naturalWidth == "undefined"|| img.naturalWidth == 0) {
|
2015-04-29 17:50:35 +08:00
|
|
|
var image = new Image();
|
|
|
|
image.src = img.src;
|
2015-04-30 10:47:34 +08:00
|
|
|
if (image.complete) {
|
|
|
|
callback(image);
|
|
|
|
} else {
|
|
|
|
image.onload = function () {
|
|
|
|
callback(image);
|
|
|
|
image.onload = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-04-29 17:50:35 +08:00
|
|
|
}
|
2015-04-30 10:47:34 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (img.complete) {
|
|
|
|
nWidth = img.naturalWidth;
|
|
|
|
nHeight = img.naturalHeight;
|
|
|
|
} else {
|
|
|
|
img.onload = function () {
|
|
|
|
nWidth = img.naturalWidth;
|
|
|
|
nHeight = img.naturalHeight;
|
|
|
|
image.onload = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
return [nWidth, nHeight];
|
2015-04-29 17:50:35 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 10:47:34 +08:00
|
|
|
|
|
|
|
function UpdateImageInformation(image) {
|
|
|
|
return [image.width,image.height];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-29 17:50:35 +08:00
|
|
|
for(i=0;i<img.length;i++)
|
|
|
|
{
|
2015-04-30 10:47:34 +08:00
|
|
|
imgNatural = getImgNaturalStyle(img[i],UpdateImageInformation);
|
2015-04-29 17:50:35 +08:00
|
|
|
var width = imgNatural[0];
|
|
|
|
var height = imgNatural[1];
|
|
|
|
if (width<100)
|
|
|
|
{
|
|
|
|
img[i].width = width;
|
|
|
|
}
|
|
|
|
if (height<73) {
|
|
|
|
img[i].height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-30 10:47:34 +08:00
|
|
|
|
|
|
|
|
2015-04-29 17:50:35 +08:00
|
|
|
</script>
|
2015-04-30 10:47:34 +08:00
|
|
|
|
2015-04-07 12:48:47 +08:00
|
|
|
<div class="attachments" style="font-weight:normal;">
|
|
|
|
<% is_float ||= false %>
|
|
|
|
<% for attachment in attachments %>
|
|
|
|
<p style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
|
|
|
|
<%if is_float%>
|
|
|
|
<div style="max-width:55%;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;float: left;">
|
|
|
|
<% end%>
|
2015-04-17 07:45:37 +08:00
|
|
|
<span title="<%= attachment.filename %>" id = "attachment_">
|
2015-04-07 12:48:47 +08:00
|
|
|
<% if options[:length] %>
|
|
|
|
<%= link_to_short_attachment attachment, :class => ' link_file_board', :download => true,:length => options[:length] -%>
|
|
|
|
<% else %>
|
|
|
|
<%= link_to_short_attachment attachment, :class => ' link_file_board', :download => true -%>
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<%if is_float%>
|
|
|
|
</div>
|
|
|
|
<% end%>
|
|
|
|
|
|
|
|
<% if attachment.is_text? %>
|
|
|
|
<%= link_to image_tag('magnifier.png'),
|
|
|
|
:controller => 'attachments',
|
|
|
|
:action => 'show',
|
|
|
|
:id => attachment,
|
|
|
|
:filename => attachment.filename%>
|
|
|
|
<% end %>
|
|
|
|
<span title="<%= attachment.description%>">
|
|
|
|
<%= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %>
|
|
|
|
</span>
|
|
|
|
<span class="size">(
|
|
|
|
<%= number_to_human_size attachment.filesize %>)
|
|
|
|
</span>
|
|
|
|
<% if options[:deletable] %>
|
|
|
|
<% if attachment.container_type == 'HomeworkAttach' %>
|
|
|
|
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id},
|
|
|
|
:data => {:confirm => l(:text_are_you_sure)},
|
|
|
|
:method => :delete,
|
|
|
|
:class => 'delete delete-homework-icon',
|
|
|
|
:remote => true,
|
|
|
|
:title => l(:button_delete) %>
|
|
|
|
<% else %>
|
|
|
|
<%= link_to image_tag('delete.png'), attachment_path(attachment),
|
|
|
|
:data => {:confirm => l(:text_are_you_sure)},
|
|
|
|
:method => :delete,
|
|
|
|
:class => 'delete',
|
|
|
|
#:remote => true,
|
|
|
|
#:id => "attachments_" + attachment.id.to_s,
|
|
|
|
:title => l(:button_delete) %>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
<% if options[:wrap] %>
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
<% end %>
|
|
|
|
<% if options[:author] %>
|
|
|
|
<span class="author" title="<%= attachment.author%>">
|
2015-04-17 10:13:47 +08:00
|
|
|
<%= link_to h(truncate(attachment.author.name, length: 10, omission: '...')),user_path(attachment.author),:class => "c_orange" %>,
|
2015-04-07 12:48:47 +08:00
|
|
|
<%= format_time(attachment.created_on) %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
</p>
|
|
|
|
<% end %>
|
2015-04-17 14:14:13 +08:00
|
|
|
<div class="thumbnails">
|
2015-04-07 12:48:47 +08:00
|
|
|
<% if defined?(thumbnails) && thumbnails %>
|
|
|
|
<% images = attachments.select(&:thumbnailable?) %>
|
|
|
|
<% if images.any? %>
|
|
|
|
<% images.each do |attachment| %>
|
2015-04-22 16:49:07 +08:00
|
|
|
<div class="pro_pic fl " width="100" height="73"><%= thumbnail_issue_tag(attachment) %></div>
|
2015-04-07 12:48:47 +08:00
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
2015-04-17 14:14:13 +08:00
|
|
|
</div>
|
2015-04-07 12:48:47 +08:00
|
|
|
</div>
|