codecombat/app/views/account/unsubscribe_view.coffee

36 lines
948 B
CoffeeScript
Raw Normal View History

2014-01-17 13:47:42 -05:00
RootView = require 'views/kinds/RootView'
template = require 'templates/account/unsubscribe'
{me} = require 'lib/auth'
module.exports = class UnsubscribeView extends RootView
id: "unsubscribe-view"
template: template
2014-01-17 13:47:42 -05:00
events:
'click #unsubscribe-button': 'onUnsubscribeButtonClicked'
getRenderData: ->
context = super()
context.email = @getQueryVariable 'email'
context
onUnsubscribeButtonClicked: ->
@$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-01-17 13:47:42 -05:00
success = =>
@$el.find('.progress').hide()
@$el.find('#success-alert').show()
2014-01-17 13:47:42 -05:00
me.fetch()
2014-01-17 13:47:42 -05:00
error = =>
@$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 }