2014-01-07 02:45:33 -05:00
|
|
|
SignupModalView = require 'views/modal/signup_modal'
|
2014-01-06 17:30:35 -05:00
|
|
|
View = require 'views/kinds/RootView'
|
2014-01-06 18:18:40 -05:00
|
|
|
{me} = require('lib/auth')
|
2014-04-12 17:53:09 -04:00
|
|
|
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
|
|
|
|
2014-01-06 17:30:35 -05:00
|
|
|
module.exports = class ContributeClassView extends View
|
2014-01-06 18:18:40 -05:00
|
|
|
navPrefix: '/contribute'
|
2014-01-06 17:30:35 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-01-06 17:30:35 -05:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-04-12 17:53:09 -04:00
|
|
|
@$el.find('.contributor-signup-anonymous').replaceWith(contributorSignupAnonymousTemplate(me: me))
|
|
|
|
@$el.find('.contributor-signup').each ->
|
|
|
|
context = me: me, contributorClassID: $(@).data('contributor-class-id'), contributorClassName: $(@).data('contributor-class-name')
|
|
|
|
$(@).replaceWith(contributorSignupTemplate(context))
|
|
|
|
@$el.find('#contributor-list').replaceWith(contributorListTemplate(contributors: @contributors, contributorClassName: @contributorClassName))
|
|
|
|
|
2014-01-06 17:30:35 -05:00
|
|
|
checkboxes = @$el.find('input[type="checkbox"]').toArray()
|
|
|
|
_.forEach checkboxes, (el) ->
|
2014-01-06 18:18:40 -05:00
|
|
|
el = $(el)
|
|
|
|
if el.attr('name') in me.get('emailSubscriptions')
|
|
|
|
el.prop('checked', true)
|
2014-01-06 17:30:35 -05:00
|
|
|
|
|
|
|
onCheckboxChanged: (e) ->
|
|
|
|
el = $(e.target)
|
|
|
|
checked = el.prop('checked')
|
|
|
|
subscription = el.attr('name')
|
|
|
|
subscriptions = me.get('emailSubscriptions') ? []
|
|
|
|
if checked and not (subscription in subscriptions)
|
|
|
|
subscriptions.push(subscription)
|
|
|
|
if me.get 'anonymous'
|
|
|
|
@openModalView new SignupModalView()
|
|
|
|
if not checked
|
|
|
|
subscriptions = _.without subscriptions, subscription
|
|
|
|
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)
|
|
|
|
|
|
|
|
me.set('emailSubscriptions', subscriptions)
|
2014-01-06 18:18:40 -05:00
|
|
|
me.save()
|
2014-02-07 21:38:17 -05:00
|
|
|
|
|
|
|
contributors: []
|