2014-12-01 13:49:38 -05:00
|
|
|
AuthModal = require 'views/core/AuthModal'
|
2014-11-28 20:49:41 -05:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
{me} = require 'core/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-07-17 20:16:32 -04:00
|
|
|
module.exports = class ContributeClassView extends RootView
|
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 ->
|
2014-04-21 19:15:23 -04:00
|
|
|
context = me: me, contributorClassName: $(@).data('contributor-class-name')
|
2014-04-12 17:53:09 -04:00
|
|
|
$(@).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)
|
2014-04-21 19:15:23 -04:00
|
|
|
el.prop('checked', true) if me.isEmailSubscriptionEnabled(el.attr('name')+'News')
|
2014-01-06 17:30:35 -05:00
|
|
|
|
|
|
|
onCheckboxChanged: (e) ->
|
|
|
|
el = $(e.target)
|
|
|
|
checked = el.prop('checked')
|
|
|
|
subscription = el.attr('name')
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-04-21 19:15:23 -04:00
|
|
|
me.setEmailSubscription subscription+'News', checked
|
2014-06-11 16:16:17 -04:00
|
|
|
me.patch()
|
2014-12-01 13:49:38 -05:00
|
|
|
@openModalView new AuthModal() if me.get 'anonymous'
|
2014-04-21 19:15:23 -04:00
|
|
|
el.parent().find('.saved-notification').finish().show('fast').delay(3000).fadeOut(2000)
|
2014-02-07 21:38:17 -05:00
|
|
|
|
|
|
|
contributors: []
|