Skip to content

Commit

Permalink
ChannelDetailsList: limit to 8 by default, load_more(all), @showing_all
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jan 25, 2012
1 parent 3670863 commit 25e154d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/templates/channel/details/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = design (view) ->
@$h3 ->
@text "#{view.title} "
@$span class: 'count', ->
@hide()
view.bind 'show:all', @show

update_count = =>
@text view.model.length
update_count()
Expand Down Expand Up @@ -52,12 +55,10 @@ module.exports = design (view) ->
img.remove()
# Iterates through node.subscriptions in "followers" case,
# and over user.channels in "following" case:
view.model.forEach (user) ->
add_follower user
view.model.bind 'add', (user) ->
view.bind 'add', (user) ->
add_follower user
update_count()
view.model.bind 'remove', (user) ->
view.bind 'remove', (user) ->
rm_follower user.get('id')
update_count()

Expand Down
6 changes: 3 additions & 3 deletions src/views/channel/details/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class exports.ChannelDetailsView extends BaseView
parent: this
load_more: @load_more_following

load_more_followers: =>
load_more_followers: (all) =>
node = @model.nodes.get_or_create id: 'posts'
nodeid = node.get 'nodeid'
if node.can_load_more_subscribers()
app.handler.data.get_more_node_subscriptions nodeid, (err) =>
unless err
if all and not err
@load_more_followers()

load_more_following: =>
load_more_following: (all) =>
unless app.users.get(@model.get 'id').subscriptions_synced
app.handler.data.get_user_subscriptions @model.get('id')

Expand Down
51 changes: 50 additions & 1 deletion src/views/channel/details/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,58 @@ class exports.ChannelDetailsList extends BaseView
initialize: ({@title, @load_more}) ->
super

@showing_all = no
@showing_count = 0
@showing_users = {}

@ready =>
@add_all()
@model.bind 'add', @add_user
@model.bind 'remove', @remove_user

if @model.length < 8
@load_more(false)

add_user: (user) =>
user_id = user.get('id')
console.warn "add_user", user_id, "count", @showing_count, @showing_all, @showing_users[user_id], not @showing_all and @showing_count < 8
show = =>
@trigger 'add', user
@showing_count++
@showing_users[user_id] = yes

unless @showing_users[user_id]
# Is not already shown
if @showing_all
# Expanded by "show all"
show()
else if not @showing_all and @showing_count < 8
show()

remove_user: (user) =>
user_id = user.get('id')
if @showing_users[user_id]
@trigger 'remove', user
delete @showing_users[user_id]
@showing_count--

# Fill spot that is left
@add_one()

add_one: =>
hidden = @model.filter (user1) ->
not @showing_users[user1.get('id')]
if not @showing_all and hidden?[0]?
@add_user hidden[0]

add_all: =>
@model.each @add_user

events:
'click .showAll': 'showAll'

showAll: EventHandler ->
@showing_all = yes
@add_all()
@trigger 'show:all'
@load_more()
@load_more(true)

0 comments on commit 25e154d

Please sign in to comment.