BigW Consortium Gitlab

subscription.js.coffee 677 Bytes
Newer Older
Valery Sizov committed
1 2
class @Subscription
  constructor: (url) ->
Valery Sizov committed
3
    $(".subscribe-button").unbind("click").click (event)=>
Valery Sizov committed
4
      btn = $(event.currentTarget)
Valery Sizov committed
5 6 7
      action = btn.find("span").text()
      current_status = $(".subscription-status").attr("data-status")
      btn.prop("disabled", true)
Valery Sizov committed
8
      
Valery Sizov committed
9
      $.post url, =>
Valery Sizov committed
10
        btn.prop("disabled", false)
Valery Sizov committed
11
        status = if current_status == "subscribed" then "unsubscribed" else "subscribed"
Valery Sizov committed
12
        $(".subscription-status").attr("data-status", status)
Valery Sizov committed
13
        action = if status == "subscribed" then "Unsubscribe" else "Subscribe"
Valery Sizov committed
14 15
        btn.find("span").text(action)
        $(".subscription-status>div").toggleClass("hidden")
Valery Sizov committed
16 17