codecombat/app/views/contribute/ContributeClassView.coffee

35 lines
1.5 KiB
CoffeeScript
Raw Normal View History

CreateAccountModal = require 'views/core/CreateAccountModal'
RootView = require 'views/core/RootView'
{me} = require 'core/auth'
contributorSignupAnonymousTemplate = require 'templates/contribute/contributor_signup_anonymous'
contributorSignupTemplate = require 'templates/contribute/contributor_signup'
contributorListTemplate = require 'templates/contribute/contributor_list'
2014-01-06 18:18:40 -05:00
module.exports = class ContributeClassView extends RootView
events:
'change input[type="checkbox"]': 'onCheckboxChanged'
2014-01-06 18:18:40 -05:00
afterRender: ->
super()
@$el.find('.contributor-signup-anonymous').replaceWith(contributorSignupAnonymousTemplate(me: me))
@$el.find('.contributor-signup').each ->
context = me: me, contributorClassName: $(@).data('contributor-class-name')
$(@).replaceWith(contributorSignupTemplate(context))
@$el.find('#contributor-list').replaceWith(contributorListTemplate(contributors: @contributors, contributorClassName: @contributorClassName))
checkboxes = @$el.find('input[type="checkbox"]').toArray()
_.forEach checkboxes, (el) ->
2014-01-06 18:18:40 -05:00
el = $(el)
el.prop('checked', true) if me.isEmailSubscriptionEnabled(el.attr('name')+'News')
onCheckboxChanged: (e) ->
el = $(e.target)
checked = el.prop('checked')
subscription = el.attr('name')
2014-06-30 22:16:26 -04:00
me.setEmailSubscription subscription+'News', checked
2014-06-11 16:16:17 -04:00
me.patch()
@openModalView new CreateAccountModal() if me.get 'anonymous'
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)