This commit is contained in:
BoHung Chiu 2021-04-21 13:02:15 +08:00
parent 3c1c1d40da
commit 33272f9193
4 changed files with 40 additions and 4 deletions

View File

@ -393,7 +393,11 @@ class Admin::OlympiamanagementsController < OrbitAdminController
redirect_to :back
else
tmp_filename_data = @student.olympia_student_images.last.student_file.file.read
send_data(tmp_filename_data, type: 'image/jpg', disposition: 'attachment', filename: "#{@student.StudentName}.jpg")
file = @student.olympia_student_images.last.student_file.file.file.to_s
extname = File.extname(file) rescue ".jpg"
extname = ".jpg" if extname.blank?
mime_type = MIME::Types.type_for(file).first.content_type rescue "image/jpg"
send_data(tmp_filename_data, type: mime_type, disposition: 'attachment', filename: "#{@student.StudentName}#{extname}")
end
else
@student_data_list = OlympiaStudentDataField.where(:sign_up_setting_id=>@sign_up_setting_id)

View File

@ -4,7 +4,21 @@
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<% if(image_form.send(image_field_name).last.send(field_name).file.present? rescue false) %>
<div class="fileupload-new thumbnail pull-left">
<%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %>
<% file = image_form.send(image_field_name).last.send(field_name).to_s
extname = File.extname(file) rescue ".jpg"
extname = ".jpg" if extname.blank?
file_name = URI.decode(File.basename(file)) rescue File.basename(file)
%>
<% if extname.match(/(jpg|png|gif|bmp)/i) %>
<%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %>
<% elsif extname.match(/pdf/i) %>
<object data="<%=file%>" type="application/pdf" title="<%=file_name%>" height="120" width="120">
<a href="<%=file%>" title="<%=file_name%>"><%=file_name%></a>
<embed src="<%=file%>" title="<%=file_name%>" type="application/pdf" />
</object>
<% else %>
<a href="<%=file%>" title="<%=file_name%>"><%=file_name%></a>
<% end %>
</div>
<% end %>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>

View File

@ -22,7 +22,11 @@
<td><%= "#{field.StudentBirthYear}-#{field.StudentBirthMonth}-#{field.StudentBirthDay}" %></td>
<% elsif th_name == 'scan_file_of_certificate'%>
<% if !field.olympia_student_images.map{|image| image.student_file.file}.select { |file| file.present?}.empty? %>
<td><a href='<%="#{admin_olympiamanagements_download_scan_file_of_certificate_path}?student_id=#{field.id}" %>'><%= "#{field.StudentName}.jpg" %><img src="/assets/gif.gif" border="0" alt="<%= "#{field.StudentName}.jpg" %>"></a></td>
<% file = field.olympia_student_images.map{|image| image.student_file.file}.select { |file| file.present?}.last.file.to_s
extname = File.extname(file) rescue ".jpg"
extname = ".jpg" if extname.blank?
%>
<td><a href='<%="#{admin_olympiamanagements_download_scan_file_of_certificate_path}?student_id=#{field.id}" %>'><%= "#{field.StudentName}#{extname}" %><img src="/assets/gif.gif" border="0" alt="<%= "#{field.StudentName}#{extname}" %>"></a></td>
<% else %>
<td>&nbsp;</td>
<% end %>

View File

@ -4,7 +4,21 @@
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<% if(image_form.send(image_field_name).last.send(field_name).file.present? rescue false) %>
<div class="fileupload-new thumbnail pull-left">
<%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %>
<% file = image_form.send(image_field_name).last.send(field_name).to_s
extname = File.extname(file) rescue ".jpg"
extname = ".jpg" if extname.blank?
file_name = URI.decode(File.basename(file)) rescue File.basename(file)
%>
<% if extname.match(/(jpg|png|gif|bmp)/i) %>
<%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %>
<% elsif extname.match(/pdf/i) %>
<object data="<%=file%>" type="application/pdf" title="<%=file_name%>" height="120" width="120">
<a href="<%=file%>" title="<%=file_name%>"><%=file_name%></a>
<embed src="<%=file%>" title="<%=file_name%>" type="application/pdf" />
</object>
<% else %>
<a href="<%=file%>" title="<%=file_name%>"><%=file_name%></a>
<% end %>
</div>
<% end %>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>