setup global team switch view and controller action

This commit is contained in:
zmagod 2016-10-11 11:40:14 +02:00
parent 7a23caff69
commit d86a4dd311
6 changed files with 113 additions and 7 deletions

View file

@ -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();
})();

View file

@ -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

View file

@ -100,6 +100,23 @@
</ul>
</li>
<!-- Global team switch -->
<li class="dropdown" id="team-switch">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span>Current Organisation</span>
</a>
<ul class="dropdown-menu">
<%= form_for(current_user,
url: user_current_organization_path,
method: :post) do |f| %>
<%= hidden_field(:user, :current_organization_id) %>
<% current_user.organizations.each do |org| %>
<li><a href="#" data-id="<%= org.id %>"><%= org.name %></a></li>
<% end %>
<% end %>
</ul>
</li>
<!-- greetings -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">

View file

@ -19,6 +19,9 @@ Rails.application.routes.draw do
to: 'users/settings#notifications_settings',
as: 'notifications_settings',
defaults: { format: 'json' }
post 'users/settings/user_current_organization',
to: 'users/settings#user_current_organization',
as: 'user_current_organization'
get "users/settings/organizations", to: "users/settings#organizations", as: "organizations"
get "users/settings/organizations/new", to: "users/settings#new_organization", as: "new_organization"
post "users/settings/organizations/new", to: "users/settings#create_organization", as: "create_organization"

View file

@ -0,0 +1,14 @@
class AddCurrentOrganizationToUser < ActiveRecord::Migration
def up
add_column :users, :current_organization_id, :integer
add_foreign_key :users, :organizations, column: :current_organization_id
User.find_each do |user|
user.update(current_organization_id: user.organizations.first.id)
end
end
def down
remove_column :users, :current_organization_id
end
end

View file

@ -11,6 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161012112900) do
# These are extensions that must be enabled in order to support this database
@ -63,6 +64,41 @@ ActiveRecord::Schema.define(version: 20161012112900) do
add_index "assets", ["file_file_name"], name: "index_assets_on_file_file_name", using: :gist
add_index "assets", ["last_modified_by_id"], name: "index_assets_on_last_modified_by_id", using: :btree
create_table "billing_accounts", force: :cascade do |t|
t.string "braintree_customer_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "billing_accounts", ["braintree_customer_id"], name: "index_billing_accounts_on_braintree_customer_id", using: :btree
create_table "billing_plans", force: :cascade do |t|
t.string "braintree_plan_id", null: false
t.string "name", null: false
t.string "description"
t.integer "price_cents", default: 0, null: false
t.string "price_currency", default: "USD", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "main", default: false, null: false
t.integer "max_storage", limit: 8, default: 0
t.integer "position", default: 0, null: false
t.boolean "free", default: false, null: false
end
add_index "billing_plans", ["braintree_plan_id"], name: "index_billing_plans_on_braintree_plan_id", using: :btree
create_table "billing_subscriptions", force: :cascade do |t|
t.string "braintree_subscription_id"
t.integer "billing_account_id", null: false
t.integer "billing_plan_id", null: false
t.boolean "active", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "billing_subscriptions", ["braintree_subscription_id"], name: "index_billing_subscriptions_on_braintree_subscription_id", using: :btree
create_table "checklist_items", force: :cascade do |t|
t.string "text", null: false
t.boolean "checked", default: false, null: false
@ -245,8 +281,11 @@ ActiveRecord::Schema.define(version: 20161012112900) do
t.integer "last_modified_by_id"
t.string "description"
t.integer "space_taken", limit: 8, default: 1048576, null: false
t.integer "billing_account_id"
t.integer "agile_crm_deal_id", limit: 8
end
add_index "organizations", ["billing_account_id"], name: "index_organizations_on_billing_account_id", using: :btree
add_index "organizations", ["created_by_id"], name: "index_organizations_on_created_by_id", using: :btree
add_index "organizations", ["last_modified_by_id"], name: "index_organizations_on_last_modified_by_id", using: :btree
add_index "organizations", ["name"], name: "index_organizations_on_name", using: :btree
@ -658,12 +697,13 @@ ActiveRecord::Schema.define(version: 20161012112900) do
t.integer "invitation_limit"
t.integer "invited_by_id"
t.string "invited_by_type"
t.integer "invitations_count", default: 0
t.integer "tutorial_status", default: 0, null: false
t.boolean "assignments_notification", default: true
t.boolean "recent_notification", default: true
t.boolean "assignments_notification_email", default: false
t.boolean "recent_notification_email", default: false
t.integer "invitations_count", default: 0
t.integer "tutorial_status", default: 0, null: false
t.boolean "assignments_notification", default: true
t.boolean "recent_notification", default: true
t.boolean "assignments_notification_email", default: false
t.boolean "recent_notification_email", default: false
t.integer "current_organization_id"
t.boolean "system_message_notification_email", default: false
end
@ -680,6 +720,8 @@ ActiveRecord::Schema.define(version: 20161012112900) do
add_foreign_key "asset_text_data", "assets"
add_foreign_key "assets", "users", column: "created_by_id"
add_foreign_key "assets", "users", column: "last_modified_by_id"
add_foreign_key "billing_subscriptions", "billing_accounts"
add_foreign_key "billing_subscriptions", "billing_plans"
add_foreign_key "checklist_items", "checklists"
add_foreign_key "checklist_items", "users", column: "created_by_id"
add_foreign_key "checklist_items", "users", column: "last_modified_by_id"
@ -710,6 +752,7 @@ ActiveRecord::Schema.define(version: 20161012112900) do
add_foreign_key "my_modules", "users", column: "last_modified_by_id"
add_foreign_key "my_modules", "users", column: "restored_by_id"
add_foreign_key "notifications", "users", column: "generator_user_id"
add_foreign_key "organizations", "billing_accounts"
add_foreign_key "organizations", "users", column: "created_by_id"
add_foreign_key "organizations", "users", column: "last_modified_by_id"
add_foreign_key "project_comments", "comments"
@ -795,4 +838,5 @@ ActiveRecord::Schema.define(version: 20161012112900) do
add_foreign_key "user_projects", "projects"
add_foreign_key "user_projects", "users"
add_foreign_key "user_projects", "users", column: "assigned_by_id"
add_foreign_key "users", "organizations", column: "current_organization_id"
end