codecombat/app/views/play/level/modal/multiplayer_modal.coffee
2014-02-11 15:38:36 -08:00

47 lines
No EOL
1.2 KiB
CoffeeScript

View = require 'views/kinds/ModalView'
template = require 'templates/play/level/modal/multiplayer'
{me} = require('lib/auth')
module.exports = class MultiplayerModal extends View
id: 'level-multiplayer-modal'
template: template
events:
'click textarea': 'onClickLink'
'change #multiplayer': 'updateLinkSection'
constructor: (options) ->
super(options)
@session = options.session
@session.on 'change:multiplayer', @updateLinkSection, @
@playableTeams = options.playableTeams
getRenderData: ->
c = super()
c.joinLink = (document.location.href.replace(/\?.*/, '').replace('#', '') +
'?session=' +
@session.id)
c.multiplayer = @session.get('multiplayer')
c.playableTeams = @playableTeams
c
afterRender: ->
super()
@updateLinkSection()
onClickLink: (e) ->
e.target.select()
updateLinkSection: ->
multiplayer = @$el.find('#multiplayer').prop('checked')
la = @$el.find('#link-area')
if multiplayer then la.show() else la.hide()
true
onHidden: ->
multiplayer = Boolean(@$el.find('#multiplayer').prop('checked'))
@session.set('multiplayer', multiplayer)
destroy: ->
super()
@session.off 'change:multiplayer', @updateLinkSection, @