2014-11-28 20:49:41 -05:00
|
|
|
RootView = require 'views/core/RootView'
|
2014-01-17 13:47:42 -05:00
|
|
|
template = require 'templates/account/unsubscribe'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
2014-01-17 13:47:42 -05:00
|
|
|
|
|
|
|
module.exports = class UnsubscribeView extends RootView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'unsubscribe-view'
|
2014-01-17 13:47:42 -05:00
|
|
|
template: template
|
2014-02-13 12:26:21 -05:00
|
|
|
|
2014-01-17 13:47:42 -05:00
|
|
|
events:
|
|
|
|
'click #unsubscribe-button': 'onUnsubscribeButtonClicked'
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
|
|
|
context.email = @getQueryVariable 'email'
|
|
|
|
context
|
|
|
|
|
|
|
|
onUnsubscribeButtonClicked: ->
|
2014-02-13 12:26:21 -05:00
|
|
|
@$el.find('#unsubscribe-button').hide()
|
|
|
|
@$el.find('.progress').show()
|
|
|
|
@$el.find('.alert').hide()
|
|
|
|
|
2014-01-17 13:47:42 -05:00
|
|
|
email = @getQueryVariable 'email'
|
|
|
|
url = "/auth/unsubscribe?email=#{encodeURIComponent(email)}"
|
2014-02-13 12:26:21 -05:00
|
|
|
|
2014-01-17 13:47:42 -05:00
|
|
|
success = =>
|
2014-02-13 12:26:21 -05:00
|
|
|
@$el.find('.progress').hide()
|
|
|
|
@$el.find('#success-alert').show()
|
2014-01-17 13:47:42 -05:00
|
|
|
me.fetch()
|
2014-02-13 12:26:21 -05:00
|
|
|
|
2014-01-17 13:47:42 -05:00
|
|
|
error = =>
|
2014-02-13 12:26:21 -05:00
|
|
|
@$el.find('.progress').hide()
|
|
|
|
@$el.find('#fail-alert').show()
|
|
|
|
@$el.find('#unsubscribe-button').show()
|
|
|
|
|
2014-01-17 13:47:42 -05:00
|
|
|
$.ajax { url: url, success: success, error: error }
|