codecombat/app/views/contribute/contribute_class_view.coffee

44 lines
1.6 KiB
CoffeeScript
Raw Normal View History

SignupModalView = require 'views/modal/signup_modal'
View = require 'views/kinds/RootView'
2014-01-06 18:18:40 -05:00
{me} = require('lib/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 View
2014-01-06 18:18:40 -05:00
navPrefix: '/contribute'
events:
'change input[type="checkbox"]': 'onCheckboxChanged'
2014-01-06 18:18:40 -05:00
getRenderData: ->
c = super()
c.navPrefix = @navPrefix
2014-02-07 21:38:17 -05:00
c.contributors = @contributors
2014-01-06 18:18:40 -05:00
c
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')
me.setEmailSubscription subscription+'News', checked
2014-06-11 16:16:17 -04:00
me.patch()
@openModalView new SignupModalView() if me.get 'anonymous'
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)
2014-02-07 21:38:17 -05:00
contributors: []