Skip to content

Commit

Permalink
Simplifies identifying current channel
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 11, 2012
1 parent 2ed6093 commit 1b9fc13
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/backbone/helpers/channels.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Kandan.Helpers.Channels

@get_active_channel_id: ()->
$("#channels .ui-tabs-panel")
.eq($('#channels')
.tabs('option', 'selected'))
.data('channel_id')
24 changes: 6 additions & 18 deletions app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#= require_tree ./routers

window.Kandan =
Models: {}
Collections: {}
Views: {}
Routers: {}
Models: {}
Collections: {}
Views: {}
Routers: {}
Helpers: {}
Broadcasters: {}
init: ->
# Backbone.history.start({pushState: true})
channels = new Kandan.Collections.Channels()
channels.fetch({success: ()=>

Expand All @@ -21,16 +21,7 @@ window.Kandan =

chatbox = new Kandan.Views.Chatbox()
$('.container').append(chatbox.render().el)

# TODO move this to a helper
# can also be done by checking the active tab in the post event in the Chatbox view
$('#channels').tabs({
select: (event, ui)->
channel_id = $("#channels .ui-tabs-panel").eq("#{ui.index}").data('channel_id')
console.log "set channelID to", channel_id
# TODO move setting current channel ID to a seperate helper
$('.chatbox').data('active_channel_id', channel_id)
})
$('#channels').tabs()

# TODO move broadcast subscription to a helper
# TODO change this to use the broadcaster from the settings
Expand All @@ -39,9 +30,6 @@ window.Kandan =
for channel in channels.models
window.broadcaster.subscribe "/channels/#{channel.get('id')}"

# TODO move this to a helper
$('.chatbox').data('active_channel_id',
$("#channels .ui-tabs-panel").eq($('#channels').tabs('option', 'selected')).data('channel_id'))
})


Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/backbone/views/chatbox.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ class Kandan.Views.Chatbox extends Backbone.View

if event.keyCode== 13
$chatbox = $(".chatbox")

activity = new Kandan.Models.Activity({
'content': $chatbox.val(),
'action': 'message',
'channel_id': $chatbox.data('active_channel_id')
'channel_id': Kandan.Helpers.Channels.get_active_channel_id()
})

activity.save({success: ()->
activity.save({},{success: ()->
console.log "posted! enjoy your day"
})

Expand Down

0 comments on commit 1b9fc13

Please sign in to comment.