2016-11-15 16:59:12 -05:00
|
|
|
/* eslint-disable */
|
|
|
|
(function(global) {
|
|
|
|
class GroupLabelSubscription {
|
|
|
|
constructor(container) {
|
|
|
|
const $container = $(container);
|
|
|
|
this.$dropdown = $container.find('.dropdown');
|
2016-11-15 18:00:45 -05:00
|
|
|
this.$subscribeButtons = $container.find('.js-subscribe-button');
|
|
|
|
this.$unsubscribeButtons = $container.find('.js-unsubscribe-button');
|
2016-11-15 16:59:12 -05:00
|
|
|
|
2016-11-15 18:00:45 -05:00
|
|
|
this.$subscribeButtons.on('click', this.subscribe.bind(this));
|
|
|
|
this.$unsubscribeButtons.on('click', this.unsubscribe.bind(this));
|
2016-11-15 16:59:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsubscribe(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2016-11-15 18:00:45 -05:00
|
|
|
const url = this.$unsubscribeButtons.attr('data-url');
|
2016-11-15 16:59:12 -05:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url
|
|
|
|
}).done(() => {
|
2016-11-15 18:00:45 -05:00
|
|
|
this.toggleSubscriptionButtons();
|
|
|
|
this.$unsubscribeButtons.removeAttr('data-url');
|
2016-11-15 16:59:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribe(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const $btn = $(event.currentTarget);
|
|
|
|
const url = $btn.attr('data-url');
|
|
|
|
|
2016-11-15 18:00:45 -05:00
|
|
|
this.$unsubscribeButtons.attr('data-url', url);
|
2016-11-15 16:59:12 -05:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url
|
|
|
|
}).done(() => {
|
2016-11-15 18:00:45 -05:00
|
|
|
this.toggleSubscriptionButtons();
|
2016-11-15 16:59:12 -05:00
|
|
|
});
|
|
|
|
}
|
2016-11-15 18:00:45 -05:00
|
|
|
|
|
|
|
toggleSubscriptionButtons() {
|
|
|
|
this.$dropdown.toggleClass('hidden');
|
|
|
|
this.$subscribeButtons.toggleClass('hidden');
|
|
|
|
this.$unsubscribeButtons.toggleClass('hidden');
|
|
|
|
}
|
2016-11-15 16:59:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
global.GroupLabelSubscription = GroupLabelSubscription;
|
|
|
|
|
|
|
|
})(window.gl || (window.gl = {}));
|