codecombat/app/collections/Users.coffee
Scott Erickson f0fa88206d Add Enrollment start/end dates, remove self-serve
* Refactor several related endpoints and views
* Redesign EnrollmentView, add TeacherContactModal
* Add "Enrollment Status" tab to TeacherClassView
* Delete PurchaseCoursesView and related files
* Style-flatten RemoveStudentModal
* Fix error handling in ActivateLicensesModal
* TeacherCoursesView loads faster by only loading course campaigns, and not load prepaids
2016-05-24 14:07:28 -07:00

37 lines
1.1 KiB
CoffeeScript

User = require 'models/User'
CocoCollection = require 'collections/CocoCollection'
module.exports = class Users extends CocoCollection
model: User
url: '/db/user'
fetchForClassroom: (classroom, options={}) ->
if options.removeDeleted
delete options.removeDeleted
@listenTo @, 'sync', @removeDeletedUsers
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
removeDeletedUsers: ->
@remove @filter (user) ->
user.get('deleted')
true
search: (term) ->
return @slice() unless term
term = term.toLowerCase()
return @filter (user) ->
user.broadName().toLowerCase().indexOf(term) > -1 or (user.get('email') ? '').indexOf(term) > -1