2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/tome/problem_alert'
|
|
|
|
{me} = require 'lib/auth'
|
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class ProblemAlertView extends CocoView
|
2014-11-07 00:43:39 -05:00
|
|
|
id: 'problem-alert-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
className: 'problem-alert'
|
|
|
|
template: template
|
|
|
|
|
2014-11-07 00:43:39 -05:00
|
|
|
subscriptions:
|
|
|
|
'tome:show-problem-alert': 'onShowProblemAlert'
|
2014-11-08 01:46:12 -05:00
|
|
|
'tome:jiggle-problem-alert': 'onJiggleProblemAlert'
|
2014-11-07 00:43:39 -05:00
|
|
|
'tome:manual-cast': 'onHideProblemAlert'
|
|
|
|
'real-time-multiplayer:manual-cast': 'onHideProblemAlert'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-06-30 22:16:26 -04:00
|
|
|
'click .close': 'onRemoveClicked'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-11-07 00:43:39 -05:00
|
|
|
if options.problem?
|
2014-11-08 14:59:39 -05:00
|
|
|
@problem = options.problem
|
2014-11-07 00:43:39 -05:00
|
|
|
@onWindowResize()
|
|
|
|
else
|
|
|
|
@$el.hide()
|
|
|
|
$(window).on 'resize', @onWindowResize
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
$(window).off 'resize', @onWindowResize
|
|
|
|
super()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super context
|
2014-11-07 00:43:39 -05:00
|
|
|
if @problem?
|
|
|
|
format = (s) -> s?.replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br>')
|
|
|
|
context.message = format @problem.aetherProblem.message
|
|
|
|
context.hint = format @problem.aetherProblem.hint
|
2014-01-03 13:32:13 -05:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-11-07 00:43:39 -05:00
|
|
|
if @problem?
|
|
|
|
@$el.addClass('alert').addClass("alert-#{@problem.aetherProblem.level}").hide().fadeIn('slow')
|
|
|
|
@$el.addClass('no-hint') unless @problem.aetherProblem.hint
|
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'error_appear', volume: 1.0
|
|
|
|
|
|
|
|
onShowProblemAlert: (data) ->
|
|
|
|
return if @problem? and data.problem.aetherProblem.message is @problem.aetherProblem.message and data.problem.aetherProblem.hint is @problem.aetherProblem.hint
|
|
|
|
return unless $('#code-area').is(":visible")
|
|
|
|
@problem = data.problem
|
|
|
|
@lineOffsetPx = data.lineOffsetPx or 0
|
|
|
|
@$el.show()
|
|
|
|
@onWindowResize()
|
|
|
|
@render()
|
2014-11-08 01:46:12 -05:00
|
|
|
@onJiggleProblemAlert()
|
|
|
|
|
|
|
|
onJiggleProblemAlert: ->
|
|
|
|
if @$el.is(":visible")
|
2014-11-08 14:59:39 -05:00
|
|
|
@$el.addClass 'jiggling'
|
2014-11-08 01:46:12 -05:00
|
|
|
pauseJiggle = =>
|
2014-11-08 14:59:39 -05:00
|
|
|
@$el?.removeClass 'jiggling'
|
2014-11-08 01:46:12 -05:00
|
|
|
_.delay pauseJiggle, 2000
|
2014-11-07 00:43:39 -05:00
|
|
|
|
|
|
|
onHideProblemAlert: ->
|
|
|
|
@onRemoveClicked()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onRemoveClicked: ->
|
2014-11-07 00:43:39 -05:00
|
|
|
@$el.hide()
|
|
|
|
@problem = null
|
|
|
|
|
2014-11-08 14:59:39 -05:00
|
|
|
onWindowResize: (e) =>
|
2014-11-07 00:43:39 -05:00
|
|
|
# TODO: This all seems a little hacky
|
|
|
|
if @problem?
|
|
|
|
@$el.css('left', $('#goals-view').outerWidth(true) + 'px')
|
|
|
|
@$el.css('right', $('#code-area').outerWidth(true) + 'px')
|
|
|
|
|
2014-11-08 14:59:39 -05:00
|
|
|
# 110px from top roughly aligns top of alert with top of first code line
|
2014-11-07 00:43:39 -05:00
|
|
|
# TODO: calculate this in a more dynamic, less sketchy way
|
2014-11-08 14:59:39 -05:00
|
|
|
@$el.css('top', (110 + @lineOffsetPx) + 'px')
|