codecombat/app/views/courses/ChooseLanguageModal.coffee

53 lines
1.3 KiB
CoffeeScript
Raw Normal View History

ModalView = require 'views/core/ModalView'
template = require 'templates/courses/choose-language-modal'
module.exports = class ChooseLanguageModal extends ModalView
id: 'choose-language-modal'
template: template
2015-12-04 14:31:49 -05:00
events:
'click .lang-choice-btn': 'onClickLanguageChoiceButton'
2015-12-04 14:31:49 -05:00
initialize: (options) ->
options ?= {}
@logoutFirst = options.logoutFirst
onClickLanguageChoiceButton: (e) ->
2015-12-04 14:31:49 -05:00
@chosenLanguage = $(e.target).closest('.lang-choice-btn').data('language')
if @logoutFirst
@logoutUser()
else
@saveLanguageSetting()
2015-12-04 14:31:49 -05:00
logoutUser: ->
$.ajax({
method: 'POST'
url: '/auth/logout'
context: @
success: @onUserLoggedOut
})
onUserLoggedOut: ->
me.clear()
me.fetch({
url: '/auth/whoami'
})
@listenToOnce me, 'sync', @saveLanguageSetting
saveLanguageSetting: ->
aceConfig = _.clone(me.get('aceConfig') or {})
aceConfig.language = @chosenLanguage
me.set('aceConfig', aceConfig)
res = me.patch()
if res
@$('#choice-area').hide()
@$('#saving-progress').removeClass('hide')
@listenToOnce me, 'sync', @onLanguageSettingSaved
else
@onLanguageSettingSaved()
2015-12-04 14:31:49 -05:00
onLanguageSettingSaved: ->
@trigger('set-language')
2015-12-04 14:31:49 -05:00
window.tracker?.trackEvent 'Chose language', category: 'Courses', label: @chosenLanguage
@hide()