2016-03-30 16:57:19 -04:00
|
|
|
User = require 'models/User'
|
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
|
|
|
|
|
|
module.exports = class Users extends CocoCollection
|
|
|
|
model: User
|
|
|
|
url: '/db/user'
|
|
|
|
|
2016-03-30 19:20:37 -04:00
|
|
|
fetchForClassroom: (classroom, options={}) ->
|
2016-04-07 17:55:42 -04:00
|
|
|
if options.removeDeleted
|
|
|
|
delete options.removeDeleted
|
|
|
|
@listenTo @, 'sync', @removeDeletedUsers
|
2016-03-30 19:20:37 -04:00
|
|
|
classroomID = classroom.id or classroom
|
|
|
|
limit = 10
|
|
|
|
skip = 0
|
|
|
|
size = _.size(classroom.get('members'))
|
|
|
|
options.url = "/db/classroom/#{classroomID}/members"
|
|
|
|
options.data ?= {}
|
|
|
|
options.data.memberLimit = limit
|
|
|
|
options.remove = false
|
|
|
|
jqxhrs = []
|
|
|
|
while skip < size
|
|
|
|
options = _.cloneDeep(options)
|
|
|
|
options.data.memberSkip = skip
|
|
|
|
jqxhrs.push(@fetch(options))
|
|
|
|
skip += limit
|
|
|
|
return jqxhrs
|
2016-04-07 17:55:42 -04:00
|
|
|
|
|
|
|
removeDeletedUsers: ->
|
|
|
|
@remove @filter (user) ->
|
|
|
|
user.get('deleted')
|
|
|
|
true
|