2015-08-29 10:15:35 -04:00
|
|
|
CocoModel = require './CocoModel'
|
|
|
|
schema = require 'schemas/models/course_instance.schema'
|
|
|
|
|
|
|
|
module.exports = class CourseInstance extends CocoModel
|
|
|
|
@className: 'CourseInstance'
|
|
|
|
@schema: schema
|
|
|
|
urlRoot: '/db/course_instance'
|
2015-11-19 18:26:45 -05:00
|
|
|
|
2015-11-21 14:38:34 -05:00
|
|
|
upsertForHOC: (opts) ->
|
|
|
|
options = {
|
|
|
|
url: _.result(@, 'url') + '/~/create-for-hoc'
|
|
|
|
type: 'POST'
|
|
|
|
}
|
|
|
|
_.extend options, opts
|
|
|
|
@fetch(options)
|
2015-12-04 15:08:08 -05:00
|
|
|
|
2015-11-29 18:13:23 -05:00
|
|
|
addMember: (userID, opts) ->
|
2015-11-23 11:46:08 -05:00
|
|
|
options = {
|
|
|
|
method: 'POST'
|
2015-11-29 18:13:23 -05:00
|
|
|
url: _.result(@, 'url') + '/members'
|
2015-11-23 11:46:08 -05:00
|
|
|
data: { userID: userID }
|
|
|
|
}
|
|
|
|
_.extend options, opts
|
2016-04-19 16:44:48 -04:00
|
|
|
@fetch options
|
2015-12-04 15:08:08 -05:00
|
|
|
if userID is me.id
|
|
|
|
unless me.get('courseInstances')
|
|
|
|
me.set('courseInstances', [])
|
|
|
|
me.get('courseInstances').push(@id)
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
addMembers: (userIDs, opts) ->
|
|
|
|
options = {
|
|
|
|
method: 'POST'
|
|
|
|
url: _.result(@, 'url') + '/members'
|
|
|
|
data: { userIDs }
|
2016-04-19 16:44:48 -04:00
|
|
|
success: =>
|
|
|
|
@trigger 'add-members', { userIDs }
|
2016-03-30 16:57:19 -04:00
|
|
|
}
|
|
|
|
_.extend options, opts
|
2016-08-23 13:43:31 -04:00
|
|
|
jqxhr = @fetch(options)
|
2016-03-30 16:57:19 -04:00
|
|
|
if me.id in userIDs
|
|
|
|
unless me.get('courseInstances')
|
|
|
|
me.set('courseInstances', [])
|
|
|
|
me.get('courseInstances').push(@id)
|
2016-08-23 13:43:31 -04:00
|
|
|
return jqxhr
|
2015-11-21 14:38:34 -05:00
|
|
|
|
2015-12-02 14:56:38 -05:00
|
|
|
removeMember: (userID, opts) ->
|
|
|
|
options = {
|
|
|
|
url: _.result(@, 'url') + '/members'
|
|
|
|
type: 'DELETE'
|
|
|
|
data: { userID: userID }
|
|
|
|
}
|
|
|
|
_.extend options, opts
|
|
|
|
@fetch(options)
|
2015-12-03 19:32:37 -05:00
|
|
|
me.set('courseInstances', _.without(me.get('courseInstances'), @id)) if userID is me.id
|
2015-12-04 15:08:08 -05:00
|
|
|
|
2015-11-21 14:38:34 -05:00
|
|
|
firstLevelURL: ->
|
2015-11-27 11:30:25 -05:00
|
|
|
"/play/level/dungeons-of-kithgard?course=#{@get('courseID')}&course-instance=#{@id}"
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
hasMember: (userID, opts) ->
|
|
|
|
userID = userID.id or userID
|
|
|
|
userID in @get('members')
|