2014-07-17 20:22:26 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/modal/multiplayer'
|
2014-05-17 14:55:41 -04:00
|
|
|
{me} = require 'lib/auth'
|
2014-07-23 10:02:45 -04:00
|
|
|
LadderSubmissionView = require 'views/play/common/LadderSubmissionView'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-17 20:22:26 -04:00
|
|
|
module.exports = class MultiplayerModal extends ModalView
|
2014-01-03 13:32:13 -05:00
|
|
|
id: 'level-multiplayer-modal'
|
|
|
|
template: template
|
|
|
|
|
2014-05-17 14:55:41 -04:00
|
|
|
subscriptions:
|
|
|
|
'ladder:game-submitted': 'onGameSubmitted'
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
events:
|
|
|
|
'click textarea': 'onClickLink'
|
|
|
|
'change #multiplayer': 'updateLinkSection'
|
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-03-24 12:58:34 -04:00
|
|
|
@listenTo(@session, '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)
|
2014-05-05 19:59:12 -04:00
|
|
|
c.multiplayer = @session.get 'multiplayer'
|
2014-02-20 13:14:25 -05:00
|
|
|
c.team = @session.get 'team'
|
2014-05-05 19:59:12 -04:00
|
|
|
c.levelSlug = @level?.get 'slug'
|
2014-02-06 20:31:08 -05:00
|
|
|
c.playableTeams = @playableTeams
|
2014-02-22 15:01:05 -05:00
|
|
|
# For now, ladderGame will disallow multiplayer, because session code combining doesn't play nice yet.
|
2014-05-05 19:59:12 -04:00
|
|
|
if @level?.get('type') is 'ladder'
|
|
|
|
c.ladderGame = true
|
|
|
|
c.readyToRank = @session?.readyToRank()
|
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-05-17 14:55:41 -04:00
|
|
|
@ladderSubmissionView = new LadderSubmissionView session: @session, level: @level
|
|
|
|
@insertSubView @ladderSubmissionView, @$el.find('.ladder-submission-view')
|
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-05-17 14:55:41 -04:00
|
|
|
onGameSubmitted: (e) ->
|
|
|
|
ladderURL = "/play/ladder/#{@level.get('slug')}#my-matches"
|
|
|
|
Backbone.Mediator.publish 'router:navigate', route: ladderURL
|
|
|
|
|
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
|
|
|
|
|
|
|
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: ->
|
2014-02-14 13:57:47 -05:00
|
|
|
super()
|