2015-03-15 12:17:12 -04:00
|
|
|
class @Subscription
|
2016-03-01 11:33:13 -05:00
|
|
|
constructor: (container) ->
|
|
|
|
$container = $(container)
|
|
|
|
@url = $container.attr('data-url')
|
2016-04-12 10:54:26 -04:00
|
|
|
@subscribe_button = $container.find('.js-subscribe-button')
|
2016-03-01 11:33:13 -05:00
|
|
|
@subscription_status = $container.find('.subscription-status')
|
|
|
|
@subscribe_button.unbind('click').click(@toggleSubscription)
|
2015-03-15 12:17:12 -04:00
|
|
|
|
2016-02-12 09:58:39 -05:00
|
|
|
toggleSubscription: (event) =>
|
|
|
|
btn = $(event.currentTarget)
|
2016-03-01 11:33:13 -05:00
|
|
|
action = btn.find('span').text()
|
|
|
|
current_status = @subscription_status.attr('data-status')
|
2016-04-04 13:38:16 -04:00
|
|
|
btn.addClass('disabled')
|
2016-02-12 09:58:39 -05:00
|
|
|
|
|
|
|
$.post @url, =>
|
2016-04-04 13:38:16 -04:00
|
|
|
btn.removeClass('disabled')
|
2016-03-01 11:33:13 -05:00
|
|
|
status = if current_status == 'subscribed' then 'unsubscribed' else 'subscribed'
|
|
|
|
@subscription_status.attr('data-status', status)
|
|
|
|
action = if status == 'subscribed' then 'Unsubscribe' else 'Subscribe'
|
|
|
|
btn.find('span').text(action)
|
|
|
|
@subscription_status.find('>div').toggleClass('hidden')
|
2016-05-25 04:43:03 -04:00
|
|
|
|
|
|
|
if btn.attr('data-original-title')
|
|
|
|
btn.tooltip('hide')
|
|
|
|
.attr('data-original-title', action)
|
|
|
|
.tooltip('fixTitle')
|