diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-17 22:19:16 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-17 22:19:16 +0300 |
commit | d9f9be3c9548e8e99e071d764163c47c073c3c28 (patch) | |
tree | 879d15c8d794a2f0265debbb3dd76a73e1eb4432 /app/assets/javascripts | |
parent | 8a7860fd7fe91a9d2642dab9e66be5b22012901d (diff) | |
parent | 3344e1e8dbcb3e53e388511a661f6769b375b748 (diff) |
Merge branch 'master' into 22539-display-folders
* master: (26 commits)
Remove extra subscribable_type filter on migration
Add feature spec for labels subscription
Avoid code duplication for label subscription status on label partial
Rename LabelSubscription javascript to ProjectLabelSubscription
Fix label subscription menu on small screens resolution
Allow users to subscribe to a group label at group or project level
Use button instead of an icon to subscribe/unsubscribe to labels
Add CHANGELOG entry
Add toggle_subscription action to Groups::LabelsController
Allow subscriptions to be created without a project
Use subqueries instead of joins to migrate subscriptions
Add helper method to toggle label subscription on labels controller spec
Remove default value for `project` argument on subscribable concern
Use @project as default on ToggleSubscriptionAction concern
Allow users to subscribe to group labels at project-level
Pass project to Entities::Label to check if user is subscribed
Fix specs to pass a project when creating subscriptions
Refactoring label subscription toggle button text to accept a project
Refactoring label subscription status to accept a project
Refactoring notification service to find subscriptions per project
...
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/group_label_subscription.js.es6 | 53 | ||||
-rw-r--r-- | app/assets/javascripts/project_label_subscription.js.es6 | 53 |
2 files changed, 106 insertions, 0 deletions
diff --git a/app/assets/javascripts/group_label_subscription.js.es6 b/app/assets/javascripts/group_label_subscription.js.es6 new file mode 100644 index 00000000000..eea6cd40859 --- /dev/null +++ b/app/assets/javascripts/group_label_subscription.js.es6 @@ -0,0 +1,53 @@ +/* eslint-disable */ +(function(global) { + 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)); + } + + 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'); + } + } + + global.GroupLabelSubscription = GroupLabelSubscription; + +})(window.gl || (window.gl = {})); diff --git a/app/assets/javascripts/project_label_subscription.js.es6 b/app/assets/javascripts/project_label_subscription.js.es6 new file mode 100644 index 00000000000..03a115cb35b --- /dev/null +++ b/app/assets/javascripts/project_label_subscription.js.es6 @@ -0,0 +1,53 @@ +/* eslint-disable */ +(function(global) { + class ProjectLabelSubscription { + constructor(container) { + this.$container = $(container); + this.$buttons = this.$container.find('.js-subscribe-button'); + + this.$buttons.on('click', this.toggleSubscription.bind(this)); + } + + toggleSubscription(event) { + event.preventDefault(); + + const $btn = $(event.currentTarget); + const $span = $btn.find('span'); + const url = $btn.attr('data-url'); + const oldStatus = $btn.attr('data-status'); + + $btn.addClass('disabled'); + $span.toggleClass('hidden'); + + $.ajax({ + type: 'POST', + url: url + }).done(() => { + let newStatus, newAction; + + if (oldStatus === 'unsubscribed') { + [newStatus, newAction] = ['subscribed', 'Unsubscribe']; + } else { + [newStatus, newAction] = ['unsubscribed', 'Subscribe']; + } + + $span.toggleClass('hidden'); + $btn.removeClass('disabled'); + + this.$buttons.attr('data-status', newStatus); + this.$buttons.find('> span').text(newAction); + + for (let button of this.$buttons) { + let $button = $(button); + + if ($button.attr('data-original-title')) { + $button.tooltip('hide').attr('data-original-title', newAction).tooltip('fixTitle'); + } + } + }); + } + } + + global.ProjectLabelSubscription = ProjectLabelSubscription; + +})(window.gl || (window.gl = {})); |