2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/play/level/modal/multiplayer'
|
2014-02-06 20:31:08 -05:00
|
|
|
{me} = require('lib/auth')
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = class MultiplayerModal extends View
|
|
|
|
id: 'level-multiplayer-modal'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click textarea': 'onClickLink'
|
|
|
|
'change #multiplayer': 'updateLinkSection'
|
2014-02-13 13:16:27 -05:00
|
|
|
'click #submit-session-button': 'submitSession'
|
2014-01-04 18:49:13 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
constructor: (options) ->
|
|
|
|
super(options)
|
|
|
|
@session = options.session
|
2014-02-13 13:16:27 -05:00
|
|
|
@level = options.level
|
2014-02-11 18:38:36 -05:00
|
|
|
@session.on 'change:multiplayer', @updateLinkSection, @
|
2014-02-06 20:31:08 -05:00
|
|
|
@playableTeams = options.playableTeams
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
|
|
|
c.joinLink = (document.location.href.replace(/\?.*/, '').replace('#', '') +
|
|
|
|
'?session=' +
|
|
|
|
@session.id)
|
|
|
|
c.multiplayer = @session.get('multiplayer')
|
2014-02-06 20:31:08 -05:00
|
|
|
c.playableTeams = @playableTeams
|
2014-02-13 13:16:27 -05:00
|
|
|
c.ladderGame = @level?.get('name') is 'Project DotA'
|
2014-01-03 13:32:13 -05:00
|
|
|
c
|
2014-01-04 18:49:13 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@updateLinkSection()
|
2014-01-04 18:49:13 -05:00
|
|
|
|
2014-02-06 20:31:08 -05:00
|
|
|
onClickLink: (e) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
e.target.select()
|
2014-01-04 18:49:13 -05:00
|
|
|
|
2014-02-11 18:38:36 -05:00
|
|
|
updateLinkSection: ->
|
2014-01-04 18:49:13 -05:00
|
|
|
multiplayer = @$el.find('#multiplayer').prop('checked')
|
2014-01-03 13:32:13 -05:00
|
|
|
la = @$el.find('#link-area')
|
2014-02-13 12:26:21 -05:00
|
|
|
la.toggle Boolean(multiplayer)
|
2014-01-04 18:49:13 -05:00
|
|
|
true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-13 13:16:27 -05:00
|
|
|
submitSession: ->
|
|
|
|
$.ajax('/queue/scoring', {
|
|
|
|
method: 'POST'
|
|
|
|
data:
|
|
|
|
session: @session.id
|
|
|
|
})
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
onHidden: ->
|
2014-01-04 18:49:13 -05:00
|
|
|
multiplayer = Boolean(@$el.find('#multiplayer').prop('checked'))
|
|
|
|
@session.set('multiplayer', multiplayer)
|
2014-02-11 18:38:36 -05:00
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
super()
|
2014-02-13 12:26:21 -05:00
|
|
|
@session.off 'change:multiplayer', @updateLinkSection, @
|