Skip to content

Commit

Permalink
Fixes to deal with empty channels
Browse files Browse the repository at this point in the history
  • Loading branch information
gabceb committed Mar 21, 2013
1 parent c3cd3c4 commit 189e765
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 13 additions & 4 deletions app/assets/javascripts/backbone/helpers/channels.js.coffee
Expand Up @@ -20,14 +20,17 @@ class Kandan.Helpers.Channels

@scrollToLatestMessage: (channelId)->
if channelId
theScrollArea = $('#channels-'+channelId)
theScrollArea = @channelPane(channelId)
theScrollArea.scrollTop(theScrollArea.prop('scrollHeight'))
else
$('.channels-pane').scrollTop($('.channels-pane').prop('scrollHeight'))

@currentScrollPosition: (channelId)->
$('channels-pane').scrollTop()

@channelPane: (channelId)->
$("#channels-#{channelId}")

@channelActivitiesEl: (channelId)->
$("#channel-activities-#{channelId}")

Expand Down Expand Up @@ -92,12 +95,12 @@ class Kandan.Helpers.Channels


@channelExists: (channelId)->
return true if $("#channels-#{channelId}").length > 0
return true if @channelPane(channelId).length > 0
false


@createChannelArea: (channel)->
channelArea = "#channels-#{channel.get('id')}"
channelArea = @channelPane(channel.get('id'))
totalTabs = $("#kandan").tabs("length")
$createTab = $("#create_channel").parents("li").detach()
$("#kandan").tabs("add", channelArea, "#{channel.get("name")}", totalTabs)
Expand Down Expand Up @@ -161,12 +164,18 @@ class Kandan.Helpers.Channels


@setPaginationState: (channelId, moreActivities, oldest)->
@channelPaginationEl(channelId).data("oldest", oldest)
console.log "pagination element", moreActivities, @channelPaginationEl(channelId)
if moreActivities == true
# Only set pagination data if there are more activities. Otherwise is useless
@channelPaginationEl(channelId).data("oldest", oldest.get("id"))

@channelPaginationEl(channelId).show()
else
@channelPaginationEl(channelId).hide()

# If there are no more messages we will unbind the scroll event
@channelPane(channelId).unbind("scroll")



@setPaginationData: (channelId)->
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/backbone/views/channel_pane.js.coffee
Expand Up @@ -55,12 +55,14 @@ class Kandan.Views.ChannelPane extends Backbone.View
activityView = new Kandan.Views.ShowActivity({activity: activity, silence_mentions: true})
$container.find(".channel-activities").prepend(activityView.render().el)

$container.scrollTop($current_top_element.offset().top)
if $current_top_element.length != 0
$container.scrollTop($current_top_element.offset().top)

Kandan.Helpers.Channels.setPaginationState(
collection.channelId,
collection.moreActivities,
_.last(collection.models).get("id")
_.last(collection.models),
$container
)

@loading_new_messages = false
Expand Down

0 comments on commit 189e765

Please sign in to comment.