Skip to content

Commit

Permalink
Adds a per-channel file list
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <[email protected]>
  • Loading branch information
HashNuke committed Mar 16, 2012
1 parent 91af3b6 commit bd32246
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class Kandan.Collections.Attachments extends Backbone.Collection
url: ()->
"/channels/#{@options.channel_id}/attachments"
"/channels/#{@channel_id}/attachments"

initialize: (models, options)->
@channel_id = options.channel_id
1 change: 1 addition & 0 deletions app/assets/javascripts/backbone/data/attachments.js.coffee
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
class Kandan.Data.Attachments
# TODO use this for the file list plugin
3 changes: 2 additions & 1 deletion app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ window.Kandan =
$(".container").html(chat_area.render().el)
chatbox = new Kandan.Views.Chatbox()
$(".container").append(chatbox.render().el)
$('#channels').tabs({select: ()->
$('#channels').tabs({select: (event, ui)->
console.log "channel changed to index", ui.index
Kandan.Data.Channels.run_callbacks('change')
})

Expand Down
25 changes: 20 additions & 5 deletions app/assets/javascripts/backbone/plugins/attachments.js.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Kandan.Plugins.Attachments

@widget_title: "Attachments"
@widget_name: "attachments"
@plugin_namespace: "Kandan.Plugins.Attachments"

@template: _.template('''
Expand All @@ -18,26 +19,40 @@ class Kandan.Plugins.Attachments
@csrf_param: ->
$('meta[name=csrf-param]').attr('content')


@csrf_token: ->
$('meta[name=csrf-token]').attr('content')

@file_item_template: _.template('''
<li><a href="<%= url %>"><%= file_name %></a></li>
''')

# TODO this part is very bad for APIs! shoudnt be exposing a backbone collection in a plugin.
@render: ($widget_el)->
console.log "current channel", @channel_id()
$upload_form = @template({
channel_id: @channel_id(),
csrf_param: @csrf_param(),
csrf_token: @csrf_token()
})
$widget_el.append($upload_form)
# $widget_el.append($file_list)
$widget_el.html($upload_form)

$file_list = $("<ul></ul>")
attachments = new Kandan.Collections.Attachments([], {channel_id: @channel_id()})
attachments.fetch({success: (collection)=>
for model in collection.models
$file_list.append(@file_item_template({
file_name: model.get('file_file_name'),
url: model.get('url')
}))
$widget_el.append($file_list)
})


@init: ()->
Kandan.Widgets.register "attachments", @plugin_namespace
Kandan.Widgets.register @widget_name, @plugin_namespace
Kandan.Data.Channels.register_callback "change", ()=>
console.log "channel changed"
#Kandan.Widgets.render(@widget_name)
Kandan.Widgets.render(@widget_name)


Kandan.Plugins.register "Kandan.Plugins.Attachments"

0 comments on commit bd32246

Please sign in to comment.