mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-18 03:23:42 -05:00
32 lines
910 B
CoffeeScript
32 lines
910 B
CoffeeScript
|
View = require 'views/kinds/RootView'
|
||
|
template = require 'templates/contribute'
|
||
|
{me} = require('lib/auth')
|
||
|
|
||
|
module.exports = class ContributeView extends View
|
||
|
id: "contribute-view"
|
||
|
template: template
|
||
|
|
||
|
events:
|
||
|
'change input[type="checkbox"]': 'onCheckboxChanged'
|
||
|
|
||
|
afterRender: ->
|
||
|
super()
|
||
|
checkboxes = @$el.find('input[type="checkbox"]').toArray()
|
||
|
_.forEach checkboxes, (el) ->
|
||
|
el = $(el)
|
||
|
if el.attr('name') in me.get('emailSubscriptions')
|
||
|
el.attr('checked', true)
|
||
|
|
||
|
onCheckboxChanged: (e) ->
|
||
|
el = $(e.target)
|
||
|
checked = el.attr('checked')
|
||
|
subscription = el.attr('name')
|
||
|
subscriptions = me.get('emailSubscriptions')
|
||
|
if checked and not (subscription in subscriptions)
|
||
|
subscriptions.push(subscription)
|
||
|
if not checked
|
||
|
subscriptions = _.without subscriptions, subscription
|
||
|
|
||
|
me.set('emailSubscriptions', subscriptions)
|
||
|
me.save()
|