debian-mirror-gitlab/app/assets/javascripts/subscription.js.coffee

27 lines
1 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @Subscription
2016-06-02 11:05:42 +05:30
constructor: (container) ->
$container = $(container)
@url = $container.attr('data-url')
@subscribe_button = $container.find('.js-subscribe-button')
@subscription_status = $container.find('.subscription-status')
@subscribe_button.unbind('click').click(@toggleSubscription)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
toggleSubscription: (event) =>
btn = $(event.currentTarget)
action = btn.find('span').text()
current_status = @subscription_status.attr('data-status')
btn.addClass('disabled')
$.post @url, =>
btn.removeClass('disabled')
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')
if btn.attr('data-original-title')
btn.tooltip('hide')
.attr('data-original-title', action)
.tooltip('fixTitle')