2015-03-15 12:17:12 -04:00
|
|
|
class @Subscription
|
|
|
|
constructor: (url) ->
|
2015-03-17 09:04:25 -04:00
|
|
|
$(".subscribe-button").unbind("click").click (event)=>
|
2015-03-15 12:17:12 -04:00
|
|
|
btn = $(event.currentTarget)
|
2015-03-17 09:04:25 -04:00
|
|
|
action = btn.find("span").text()
|
|
|
|
current_status = $(".subscription-status").attr("data-status")
|
|
|
|
btn.prop("disabled", true)
|
2015-03-15 12:17:12 -04:00
|
|
|
|
2015-03-16 11:20:17 -04:00
|
|
|
$.post url, =>
|
2015-03-17 09:04:25 -04:00
|
|
|
btn.prop("disabled", false)
|
2015-03-15 12:17:12 -04:00
|
|
|
status = if current_status == "subscribed" then "unsubscribed" else "subscribed"
|
2015-03-17 09:04:25 -04:00
|
|
|
$(".subscription-status").attr("data-status", status)
|
2015-03-15 12:17:12 -04:00
|
|
|
action = if status == "subscribed" then "Unsubscribe" else "Subscribe"
|
2015-03-17 09:04:25 -04:00
|
|
|
btn.find("span").text(action)
|
|
|
|
$(".subscription-status>div").toggleClass("hidden")
|
2015-03-15 12:17:12 -04:00
|
|
|
|
|
|
|
|