Skip to content

Commit

Permalink
[frontend] Fix default subscription switch
Browse files Browse the repository at this point in the history
PR#4336 added a switch that allows users to reset their notification
subscription to default. This was hardcoded to clear all subscriptions.

With this commit the default subscription settings are retrieved from
the server via ajax and properly set in the ui.
The user can then decide to save the new settings or cancel it by
reloading the page.
  • Loading branch information
bgeuken committed Jan 22, 2018
1 parent 5fef34c commit cbd05fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/api/app/assets/javascripts/webui/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ $(document).on('click','.close-dialog', function() {
}
});

$(document).on('click', 'a[data-clear-checkboxes]', function(event) {
event.preventDefault();
$('input:checkbox').prop('checked', false);
});

// show/hide functionality for text
$(function() {
$('.show-hide').on('click', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def update
private

def subscriptions_form
EventSubscription::Form.new(nil)
EventSubscription::Form.new
end
end
15 changes: 12 additions & 3 deletions src/api/app/controllers/webui/users/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ def index
@user = User.current
@groups_users = User.current.groups_users

@subscriptions_form = subscriptions_form
@subscriptions_form = subscriptions_form(default_form: params[:default_form])

respond_to do |format|
format.html
format.js
end
end

def update
Expand All @@ -24,7 +29,11 @@ def update

private

def subscriptions_form
EventSubscription::Form.new(User.current)
def subscriptions_form(options = {})
if options[:default_form]
EventSubscription::Form.new
else
EventSubscription::Form.new(User.current)
end
end
end
2 changes: 1 addition & 1 deletion src/api/app/models/event_subscription/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class EventSubscription
class Form
attr_reader :subscriber

def initialize(subscriber)
def initialize(subscriber = nil)
@subscriber = subscriber
end

Expand Down
5 changes: 3 additions & 2 deletions src/api/app/views/webui/users/subscriptions/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

%h3 Events
%p.description Choose from which events you want to get an email
= render partial: 'webui/subscriptions/subscriptions_form'
#subscriptions-form
= render partial: 'webui/subscriptions/subscriptions_form'
%p
= submit_tag 'Update'
= link_to('Reset to default', '#', data: { 'clear-checkboxes': true })
= link_to('Reset to default', user_notifications_path(default_form: true), remote: true)
.grid_16.alpha.omega.box.box-shadow
%h2 RSS Feed
= form_tag(user_rss_token_path, id: 'generate_rss_token_form', method: :post) do
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/views/webui/users/subscriptions/index.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#subscriptions-form').replaceWith('<%= escape_javascript(render(partial: 'webui/subscriptions/subscriptions_form')) %>');

0 comments on commit cbd05fc

Please sign in to comment.