1
1
class Kandan.Views.ListActivities extends Backbone.View
2
2
tagName : ' div'
3
- # className: 'activities'
4
-
5
- events : {
6
- " click .pagination" : " load_more_activities"
7
- }
3
+ className : ' channel-activities'
8
4
9
5
render : ()->
10
6
@channel = @options .channel
11
- $activities_list = $ ( " <div class='channel-activities'></div> " ).attr (' id' , " channel-activities-#{ @channel .get (' id' )} " )
7
+ $ ( @el ).attr (' id' , " channel-activities-#{ @channel .get (' id' )} " )
12
8
oldest = 0
13
9
14
10
if @channel .activities
15
11
console .log " channel has activities"
16
12
for activity in @channel .activities .models
17
- activity_view = new Kandan.Views.ShowActivity ({activity : activity, state : Kandan .Helpers .Activities .HISTORY_STATE })
18
- $activities_list .append (activity_view .render ().el )
19
- oldest = @channel .activities .toJSON ()[0 ].id if @channel .activities .toJSON ()[0 ]
20
-
21
- $pagination = $ (" <div class='pagination'>previous messages</div>" )
13
+ activityView = new Kandan.Views.ShowActivity ({activity : activity, state : Kandan .Helpers .Activities .HISTORY_STATE })
14
+ $ (@el ).append (activityView .render ().el )
22
15
23
- $pagination .data (' oldest' , oldest)
24
- $ (@el ).append ($pagination)
25
- $ (@el ).find (" .pagination" ).hide () if @channel .more_activities != true
26
- $ (@el ).append ($activities_list)
27
- $ (@el ).attr (' id' , " channels-#{ @channel .get (' id' )} " )
28
- $ (@el ).data (' channel_id' , @channel .get (' id' ))
16
+ $ (@el ).prev ().hide () if @channel .more_activities != true
29
17
@
30
18
31
- load_more_activities : ()->
32
- oldest = $ (@el ).find (" .pagination" ).data (' oldest' )
33
- activities = new Kandan.Collections.Activities ([], {channel_id : @channel .get (' id' )})
34
- activities .fetch ({
35
- data : { oldest : oldest },
36
- success : (collection )=>
37
- _ .each collection .models .reverse (), (activity )=>
38
- activity_view = new Kandan.Views.ShowActivity ({activity : activity})
39
- $ (@el ).find (" .channel-activities" ).prepend (activity_view .render ().el )
40
- Kandan .Helpers .Channels .set_pagination_state (
41
- collection .channel_id ,
42
- collection .more_activities ,
43
- _ .last (collection .models ).get (' id' )
44
- )
45
- })
0 commit comments