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 @@
+
+
+
+ Current Organisation
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb
index dabeaaef2..d1aca0457 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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"
diff --git a/db/migrate/20161011074804_add_current_organization_to_user.rb b/db/migrate/20161011074804_add_current_organization_to_user.rb
new file mode 100644
index 000000000..0b97fbb6a
--- /dev/null
+++ b/db/migrate/20161011074804_add_current_organization_to_user.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 4b05fc448..5e00cef52 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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