mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
ef0547f72a
In TeacherClassView, when a teacher assigns a paid course to any unenrolled student, the view automatically enrolls those students, rather than requiring the teacher to enroll those students manually first. Update copy throughout. Also add back (smaller) padding to progress dots in TeacherClassView.
43 lines
1.1 KiB
CoffeeScript
43 lines
1.1 KiB
CoffeeScript
CocoModel = require './CocoModel'
|
|
schema = require 'schemas/models/prepaid.schema'
|
|
|
|
module.exports = class Prepaid extends CocoModel
|
|
@className: "Prepaid"
|
|
urlRoot: '/db/prepaid'
|
|
|
|
openSpots: ->
|
|
return @get('maxRedeemers') - @get('redeemers')?.length if @get('redeemers')?
|
|
@get('maxRedeemers')
|
|
|
|
userHasRedeemed: (userID) ->
|
|
for redeemer in @get('redeemers')
|
|
return redeemer.date if redeemer.userID is userID
|
|
return null
|
|
|
|
initialize: ->
|
|
@listenTo @, 'add', ->
|
|
maxRedeemers = @get('maxRedeemers')
|
|
if _.isString(maxRedeemers)
|
|
@set 'maxRedeemers', parseInt(maxRedeemers)
|
|
super(arguments...)
|
|
|
|
status: ->
|
|
endDate = @get('endDate')
|
|
if endDate and new Date(endDate) < new Date()
|
|
return 'expired'
|
|
|
|
startDate = @get('startDate')
|
|
if startDate and new Date(startDate) > new Date()
|
|
return 'pending'
|
|
|
|
if @openSpots() <= 0
|
|
return 'empty'
|
|
|
|
return 'available'
|
|
|
|
redeem: (user, options={}) ->
|
|
options.url = _.result(@, 'url')+'/redeemers'
|
|
options.type = 'POST'
|
|
options.data ?= {}
|
|
options.data.userID = user.id or user
|
|
@fetch(options)
|