From d86a4dd3117437b2f40242e43998f6565f907f27 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 11 Oct 2016 11:40:14 +0200 Subject: [PATCH 01/17] setup global team switch view and controller action --- app/assets/javascripts/navigation.js | 15 +++++ app/controllers/users/settings_controller.rb | 15 ++++- app/views/shared/_navigation.html.erb | 17 ++++++ config/routes.rb | 3 + ...074804_add_current_organization_to_user.rb | 14 +++++ db/schema.rb | 56 +++++++++++++++++-- 6 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20161011074804_add_current_organization_to_user.rb 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 @@ + + +