Skip to content

Commit

Permalink
customers pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
zuohaisu committed Jun 23, 2014
1 parent eba74e0 commit d857c15
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 5 additions & 2 deletions both/controllers/staffs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Staffs.chat = AppController.extend({
findOption: function(){
Session.set('customersLimit', 15)
return {limit: Session.get('customersLimit')}
},
waitOn: function() {
currentUserId = Meteor.userId();

return [
Meteor.subscribe('staffs'),
Meteor.subscribe('customers'),
Meteor.subscribe('customers', this.findOption()),
Meteor.subscribe('messages', Session.get('customerSelected'))
];
}
Expand Down
15 changes: 14 additions & 1 deletion client/pages/staffs/chat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Template.chat.helpers

lastUpdateTime: ->
Session.get('lastUpdateTime')

messages: ->
db.messages.find()

Expand Down Expand Up @@ -79,6 +79,19 @@ Template.chat.events
layoutDone()
toBottom()

# Load More events
'click .load-more': (e) ->
e.preventDefault

increment = 15
if Session.get('customersLimit')
limit = Session.get('customersLimit')
Session.set('customersLimit', (limit += increment))
Meteor.subscribe('customers', limit: Session.get('customersLimit'))
else
Session.set('customersLimit', increment)
this

Template.chat.rendered = ->
Session.set('customerSelected', '')
layoutDone()
Expand Down
4 changes: 2 additions & 2 deletions server/publications/customers.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Meteor.publish 'customers', ->
db.customers.find()
Meteor.publish 'customers', (options)->
db.customers.find {}, options

0 comments on commit d857c15

Please sign in to comment.