diff --git a/app/assets/javascripts/navigation.js b/app/assets/javascripts/navigation.js index 8c7e77092..3f5180507 100644 --- a/app/assets/javascripts/navigation.js +++ b/app/assets/javascripts/navigation.js @@ -80,8 +80,23 @@ } + function initGlobalSwitchForm() { + var teamSwitch = $('#team-switch'); + teamSwitch + .find('.dropdown-menu a') + .on('click', function(el){ + $('#user_current_organization_id') + .val($(el.toElement).attr('data-id')); + + teamSwitch + .find('form') + .submit(); + }); + } + // init loadDropdownNotifications(); loadUnseenNotificationsNumber(); toggleNotificationBellPosition(); + initGlobalSwitchForm(); })(); diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 57032dbc0..a1158a517 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -10,7 +10,8 @@ class Users::SettingsController < ApplicationController :organization_users_datatable, :tutorial, :reset_tutorial, - :notifications_settings + :notifications_settings, + :user_current_organization ] before_action :check_organization_permission, only: [ @@ -491,6 +492,18 @@ class Users::SettingsController < ApplicationController end end + def user_current_organization + @user.current_organization_id = params[:user][:current_organization_id] + + if @user.save + flash[:success] = 'Success!' + redirect_to :back + else + flash[:alert] = 'Something get terribly wrong' + redirect_to :back + end + end + private def load_user diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index c5b2cf583..8167de818 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -100,6 +100,23 @@ + + +