BigW Consortium Gitlab

subscription.js 1.92 KB
Newer Older
1
/* eslint-disable */
Fatih Acet committed
2 3 4 5 6 7 8
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  this.Subscription = (function() {
    function Subscription(container) {
      this.toggleSubscription = bind(this.toggleSubscription, this);
      var $container;
9 10 11 12
      this.$container = $(container);
      this.url = this.$container.attr('data-url');
      this.subscribe_button = this.$container.find('.js-subscribe-button');
      this.subscription_status = this.$container.find('.subscription-status');
Fatih Acet committed
13 14 15 16 17 18 19 20 21
      this.subscribe_button.unbind('click').click(this.toggleSubscription);
    }

    Subscription.prototype.toggleSubscription = function(event) {
      var action, btn, current_status;
      btn = $(event.currentTarget);
      action = btn.find('span').text();
      current_status = this.subscription_status.attr('data-status');
      btn.addClass('disabled');
22 23 24 25 26

      if ($('html').hasClass('issue-boards-page')) {
        this.url = this.$container.attr('data-url');
      }

Fatih Acet committed
27 28 29 30
      return $.post(this.url, (function(_this) {
        return function() {
          var status;
          btn.removeClass('disabled');
31

32
          if ($('html').hasClass('issue-boards-page')) {
33 34 35 36 37 38 39 40 41 42
            Vue.set(gl.issueBoards.BoardsStore.detail.issue, 'subscribed', !gl.issueBoards.BoardsStore.detail.issue.subscribed);
          } else {
            status = current_status === 'subscribed' ? 'unsubscribed' : 'subscribed';
            _this.subscription_status.attr('data-status', status);
            action = status === 'subscribed' ? 'Unsubscribe' : 'Subscribe';
            btn.find('span').text(action);
            _this.subscription_status.find('>div').toggleClass('hidden');
            if (btn.attr('data-original-title')) {
              return btn.tooltip('hide').attr('data-original-title', action).tooltip('fixTitle');
            }
Fatih Acet committed
43 44 45 46 47 48 49 50 51 52
          }
        };
      })(this));
    };

    return Subscription;

  })();

}).call(this);