2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/RootView'
|
|
|
|
template = require 'templates/contribute'
|
2014-01-05 17:20:48 -05:00
|
|
|
{me} = require 'lib/auth'
|
|
|
|
SignupModalView = require 'views/modal/signup_modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
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')
|
2014-01-04 18:49:13 -05:00
|
|
|
el.prop('checked', true)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onCheckboxChanged: (e) ->
|
|
|
|
el = $(e.target)
|
2014-01-04 18:49:13 -05:00
|
|
|
checked = el.prop('checked')
|
2014-01-03 13:32:13 -05:00
|
|
|
subscription = el.attr('name')
|
2014-01-05 17:20:48 -05:00
|
|
|
subscriptions = me.get('emailSubscriptions') ? []
|
2014-01-03 13:32:13 -05:00
|
|
|
if checked and not (subscription in subscriptions)
|
|
|
|
subscriptions.push(subscription)
|
2014-01-05 17:20:48 -05:00
|
|
|
if me.get 'anonymous'
|
|
|
|
@openModalView new SignupModalView()
|
2014-01-03 13:32:13 -05:00
|
|
|
if not checked
|
|
|
|
subscriptions = _.without subscriptions, subscription
|
2014-01-05 17:45:55 -05:00
|
|
|
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
me.set('emailSubscriptions', subscriptions)
|
|
|
|
me.save()
|