Skip to content

Commit

Permalink
Merge branch 'ui_work'
Browse files Browse the repository at this point in the history
  • Loading branch information
HashNuke committed Mar 30, 2012
2 parents 231daf1 + 3ef9119 commit 6001c75
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
Binary file added app/assets/images/audio_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/file_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/img_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/video_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions app/assets/javascripts/backbone/plugins/attachments.js.coffee
Expand Up @@ -3,6 +3,8 @@ class Kandan.Plugins.Attachments
@widget_title: "Media"
@plugin_namespace: "Kandan.Plugins.Attachments"

@options:
maxFileNameLength: 20

@templates:
no_files: _.template '''
Expand Down Expand Up @@ -34,8 +36,19 @@ class Kandan.Plugins.Attachments
@csrf_token: ->
$('meta[name=csrf-token]').attr('content')

@truncateName: (fileName)->
return "#{fileName.substring(0, @options.maxFileNameLength)}..." if fileName.length > @options.maxFileNameLength
fileName

@fileIcon: (fileName)->
fileExtension = fileName.split(".").pop()
return "/assets/img_icon.png" if fileExtension.match(/(png|jpeg|gif)/i)
return "/assets/video_icon.png" if fileExtension.match(/(mp3|wav)/i)
return "/assets/audio_icon.png" if fileExtension.match(/(mov|mpg|mpeg|mp4)/i)
return "/assets/file_icon.png"

@file_item_template: _.template '''
<div class="file_item"><a href="<%= url %>"><%= file_name %></a></div>
<div class="file_item"><img src="<%= iconUrl %>"><a href="<%= url %>"><%= fileName %></a></div>
'''

# TODO this part is very bad for APIs! shoudnt be exposing a backbone collection in a plugin.
Expand All @@ -58,8 +71,9 @@ class Kandan.Plugins.Attachments
$file_list = $("<div class='file_list'></div>")
for model in collection.models
$file_list.append(@file_item_template({
file_name: model.get('file_file_name'),
fileName: @truncateName(model.get('file_file_name')),
url: model.get('url')
iconUrl: @fileIcon(model.get('file_file_name'))
}))
else
$file_list = @templates.no_files()
Expand Down
8 changes: 7 additions & 1 deletion app/assets/stylesheets/plugins/_attachments.scss
Expand Up @@ -10,8 +10,14 @@
.file_item {
clear: both;
float: left;
line-height: 25px;
line-height: 30px;
color: #585D5F;

img {
width: 14px;
margin-right: 10px;
}

a {
text-decoration: none;
font-weight: bold;
Expand Down

0 comments on commit 6001c75

Please sign in to comment.