diff --git a/app/assets/javascripts/users/settings/account/preferences/index.js b/app/assets/javascripts/users/settings/account/preferences/index.js index bb29998d3..892ceb761 100644 --- a/app/assets/javascripts/users/settings/account/preferences/index.js +++ b/app/assets/javascripts/users/settings/account/preferences/index.js @@ -66,13 +66,13 @@ }); notificationsSettings(); - initNotificationSettingsForm(); + tooltipSettings(); + initTogglableSettingsForm(); // Setup notification checkbox buttons function notificationsSettings() { var notification_settings = [ "recent_notification", - "assignments_notification", - "popovers_enabled" ] + "assignments_notification" ] for (var i = 0; i < notification_settings.length; i++ ) { var setting = $('[name="' + notification_settings[i] + '"]'); @@ -142,9 +142,22 @@ ); } +// Initialize tooltips settings form + function tooltipSettings() { + var toggleInput = $('[name="tooltips_enabled"]'); + toggleInput + .checkboxpicker({ onActiveCls: 'btn-toggle', offActiveCls: 'btn-toggle' }); + + if (toggleInput.attr('value') === 'true') { + toggleInput.prop('checked', true); + } else { + toggleInput.prop('checked', false); + } + } + // triggers submit action when the user clicks - function initNotificationSettingsForm() { - $('#notifications-settings-panel') + function initTogglableSettingsForm() { + $('#togglable-settings-panel') .find('.btn-group') .on('click', function() { $(this).submit(); diff --git a/app/controllers/users/settings/account/preferences_controller.rb b/app/controllers/users/settings/account/preferences_controller.rb index 0224594a1..51f767be8 100644 --- a/app/controllers/users/settings/account/preferences_controller.rb +++ b/app/controllers/users/settings/account/preferences_controller.rb @@ -5,7 +5,7 @@ module Users before_action :load_user, only: [ :index, :update, - :notifications_settings + :update_togglable_settings ] layout 'fluid' @@ -30,19 +30,25 @@ module Users end end - def notifications_settings - @user.assignments_notification = - params[:assignments_notification] ? true : false - @user.recent_notification = - params[:recent_notification] ? true : false - @user.recent_email_notification = - params[:recent_notification_email] ? true : false - @user.assignments_email_notification = - params[:assignments_notification_email] ? true : false - @user.system_message_email_notification = - params[:system_message_notification_email] ? true : false - @user.popovers_enabled = - params[:popovers_enabled] ? true : false + def update_togglable_settings + read_from_params(:assignments_notification) do |val| + @user.assignments_notification = val + end + read_from_params(:recent_notification) do |val| + @user.recent_notification = val + end + read_from_params(:recent_notification_email) do |val| + @user.recent_email_notification = val + end + read_from_params(:assignments_notification_email) do |val| + @user.assignments_email_notification = val + end + read_from_params(:system_message_notification_email) do |val| + @user.system_message_email_notification = val + end + read_from_params(:tooltips_enabled) do |val| + @user.settings[:tooltips_enabled] = val + end if @user.save respond_to do |format| format.json do @@ -73,6 +79,10 @@ module Users :time_zone ) end + + def read_from_params(name) + yield(params.include?(name) ? true : false) + end end end end diff --git a/app/models/user.rb b/app/models/user.rb index 61b2fe45a..fbab2c132 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -44,8 +44,8 @@ class User < ApplicationRecord recent: true, recent_email: false, system_message_email: false, - popovers_enabled: true - } + }, + tooltips_enabled: true ) # Relations @@ -457,8 +457,8 @@ class User < ApplicationRecord NOTIFICATIONS_TYPES = %w(assignments_notification recent_notification assignments_email_notification recent_email_notification - system_message_email_notification - popovers_enabled ) + system_message_email_notification) + # declare notifications getters NOTIFICATIONS_TYPES.each do |name| define_method(name) do diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4171475a5..d51cf1209 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -29,7 +29,7 @@ data-atwho-rep-items-url="<%= atwho_rep_items_team_path(current_team) %>" data-atwho-menu-items="<%= atwho_menu_items_team_path(current_team) %>" data-file-max-size-mb="<%= Rails.configuration.x.file_max_size_mb %>" - data-popover_v2_enabled="<%= current_user.popovers_enabled %>" + data-tooltips-enabled="<%= current_user.settings[:tooltips_enabled] %>" <% end %> > diff --git a/app/views/users/settings/account/preferences/index.html.erb b/app/views/users/settings/account/preferences/index.html.erb index 5a453edf2..cc9fac02c 100644 --- a/app/views/users/settings/account/preferences/index.html.erb +++ b/app/views/users/settings/account/preferences/index.html.erb @@ -50,52 +50,27 @@ <% end %>
<%=t 'notifications.form.assignments_description' %>
-<%=t 'notifications.form.recent_notification_description' %>
+<%=t 'notifications.form.assignments_description' %>
<%=t 'notifications.form.system_message_description' %>
-<%=t 'notifications.form.recent_notification_description' %>
+<%=t 'notifications.form.system_message_description' %>
+<%=t 'users.settings.account.preferences.edit.tips.text1' %>
-<%=t 'users.settings.account.preferences.edit.tips.text2' %>
-<%=t 'users.settings.account.preferences.edit.tips.text1' %>
+<%=t 'users.settings.account.preferences.edit.tips.text2' %>
+