Improved attachment preview api, introduced @canPreview().

This commit is contained in:
Martin Edenhofer 2018-02-20 12:40:14 +01:00
parent b0597ad04d
commit 327749c29b
3 changed files with 12 additions and 6 deletions

View file

@ -143,6 +143,7 @@ class App extends Spine.Controller
'image/jpg': 'file-image'
'image/png': 'file-image'
'image/svg': 'file-image'
'image/gif': 'file-image'
# documents
'application/pdf': 'file-pdf'
'application/msword': 'file-word' # .doc, .dot
@ -173,6 +174,11 @@ class App extends Spine.Controller
canDownload: (contentType) ->
contentType != 'text/html'
canPreview: (contentType) ->
return false if _.isEmpty(contentType)
return true if contentType.match(/image\/(png|jpg|jpeg|gif)/i)
false
@viewPrint: (object, attributeName, attributes, table) ->
if !attributes
attributes = {}

View file

@ -64,10 +64,10 @@
<a class="attachment attachment--preview" title="<%- attachment.preferences['Content-Type'] %>" target="_blank" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>?disposition=attachment" data-type="attachment"<% if @canDownload(attachment.preferences['Content-Type']): %> download<% end %>>
<div class="attachment-icon">
<% if attachment.preferences && attachment.preferences['Content-Type'] && @ContentTypeIcon(attachment.preferences['Content-Type']): %>
<% if attachment.preferences['Content-Type'].match(/image\/(png|jpg|jpeg)/i): %>
<img src="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>">
<% if @canPreview(attachment.preferences['Content-Type']): %>
<img src="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>">
<% else: %>
<%- @Icon( @ContentTypeIcon(attachment.preferences['Content-Type']) ) %>
<%- @Icon( @ContentTypeIcon(attachment.preferences['Content-Type']) ) %>
<% end %>
<% else: %>
<%- @Icon('file-unknown') %>

View file

@ -4,10 +4,10 @@
<a class="attachment attachment--preview" title="<%- attachment.preferences['Content-Type'] %>" target="_blank" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>?disposition=attachment" data-type="attachment"<% if @canDownload(attachment.preferences['Content-Type']): %> download<% end %>>
<div class="attachment-icon">
<% if attachment.preferences && attachment.preferences['Content-Type'] && @ContentTypeIcon(attachment.preferences['Content-Type']): %>
<% if attachment.preferences['Content-Type'].match(/image\/(png|jpg|jpeg)/i): %>
<img src="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>">
<% if @canPreview(attachment.preferences['Content-Type']): %>
<img src="<%= App.Config.get('api_path') %>/ticket_attachment/<%= @article.ticket_id %>/<%= @article.id %>/<%= attachment.id %>">
<% else: %>
<%- @Icon( @ContentTypeIcon(attachment.preferences['Content-Type']) ) %>
<%- @Icon( @ContentTypeIcon(attachment.preferences['Content-Type']) ) %>
<% end %>
<% else: %>
<%- @Icon('file-unknown') %>