2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable func-names, object-shorthand, comma-dangle, wrap-iife, space-before-function-paren, no-param-reassign, max-len */
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
class GroupLabelSubscription {
|
|
|
|
constructor(container) {
|
|
|
|
const $container = $(container);
|
|
|
|
this.$dropdown = $container.find('.dropdown');
|
|
|
|
this.$subscribeButtons = $container.find('.js-subscribe-button');
|
|
|
|
this.$unsubscribeButtons = $container.find('.js-unsubscribe-button');
|
|
|
|
|
|
|
|
this.$subscribeButtons.on('click', this.subscribe.bind(this));
|
|
|
|
this.$unsubscribeButtons.on('click', this.unsubscribe.bind(this));
|
2016-11-15 16:59:12 -05:00
|
|
|
}
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
unsubscribe(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const url = this.$unsubscribeButtons.attr('data-url');
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url
|
|
|
|
}).done(() => {
|
|
|
|
this.toggleSubscriptionButtons();
|
|
|
|
this.$unsubscribeButtons.removeAttr('data-url');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribe(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const $btn = $(event.currentTarget);
|
|
|
|
const url = $btn.attr('data-url');
|
|
|
|
|
|
|
|
this.$unsubscribeButtons.attr('data-url', url);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url
|
|
|
|
}).done(() => {
|
|
|
|
this.toggleSubscriptionButtons();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSubscriptionButtons() {
|
|
|
|
this.$dropdown.toggleClass('hidden');
|
|
|
|
this.$subscribeButtons.toggleClass('hidden');
|
|
|
|
this.$unsubscribeButtons.toggleClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.gl = window.gl || {};
|
|
|
|
window.gl.GroupLabelSubscription = GroupLabelSubscription;
|