2016-10-26 04:02:58 -04:00
|
|
|
/* eslint-disable */
|
2016-07-24 16:45:11 -04:00
|
|
|
(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;
|
2016-10-20 03:54:33 -04:00
|
|
|
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');
|
2016-07-24 16:45:11 -04:00
|
|
|
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');
|
2016-10-20 03:54:33 -04:00
|
|
|
|
|
|
|
if ($('html').hasClass('issue-boards-page')) {
|
|
|
|
this.url = this.$container.attr('data-url');
|
|
|
|
}
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.post(this.url, (function(_this) {
|
|
|
|
return function() {
|
|
|
|
var status;
|
|
|
|
btn.removeClass('disabled');
|
2016-10-05 07:20:59 -04:00
|
|
|
|
2016-10-20 03:54:33 -04:00
|
|
|
if ($('html').hasClass('issue-boards-page')) {
|
2016-10-05 07:20:59 -04:00
|
|
|
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');
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
};
|
|
|
|
|
|
|
|
return Subscription;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}).call(this);
|