gitlab-org--gitlab-foss/app/assets/javascripts/subscription.js.coffee
Timothy Andrew 0444fa560a Original implementation to allow users to subscribe to labels
1. Allow subscribing (the current user) to a label

- Refactor the `Subscription` coffeescript class
  - The main change is that it accepts a container, and conducts all
    DOM queries within its scope. We need this because the labels
    page has multiple instances of `Subscription` on the same page.

2. Creating an issue or MR with labels notifies users subscribed to those labels

- Label `has_many` subscribers through subscriptions.

3. Adding a label to an issue or MR notifies users subscribed to those labels

- This only applies to subscribers of the label that has just been
  added, not all labels for the issue.
2016-03-15 17:25:37 +01:00

19 lines
822 B
CoffeeScript

class @Subscription
constructor: (@url, container) ->
@subscribe_button = $(container).find(".subscribe-button")
@subscription_status = $(container).find(".subscription-status")
@subscribe_button.unbind("click").click(@toggleSubscription)
toggleSubscription: (event) =>
btn = $(event.currentTarget)
action = btn.find("span").text()
current_status = @subscription_status.attr("data-status")
btn.prop("disabled", true)
$.post @url, =>
btn.prop("disabled", false)
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")