From a6b5b4399478f0be9e69cf69e166976887a491db Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 23 Sep 2015 17:22:31 +0200 Subject: [PATCH] Moved to ajax searchable select for organization selection. --- app/controllers/sessions/collection_base.rb | 15 ++-- .../20140831000001_create_object_manager.rb | 1 + .../20141217000001_update_object_manager2.rb | 2 +- .../20150977000001_update_object_manager3.rb | 71 +++++++++++++++++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20150977000001_update_object_manager3.rb diff --git a/app/controllers/sessions/collection_base.rb b/app/controllers/sessions/collection_base.rb index 5bcfb5132..4843d8db9 100644 --- a/app/controllers/sessions/collection_base.rb +++ b/app/controllers/sessions/collection_base.rb @@ -26,19 +26,14 @@ module ExtraCollection Group.all.each {|item| assets = item.assets(assets) } - if !user.role?(Z_ROLENAME_CUSTOMER) - collections[ Organization.to_app_model ] = [] - Organization.all.each {|item| + + collections[ Organization.to_app_model ] = [] + if user.organization_id + Organization.where( id: user.organization_id ).each {|item| assets = item.assets(assets) } - else - if user.organization_id - collections[ Organization.to_app_model ] = [] - Organization.where( id: user.organization_id ).each {|item| - assets = item.assets(assets) - } - end end + [collections, assets] end module_function :session diff --git a/db/migrate/20140831000001_create_object_manager.rb b/db/migrate/20140831000001_create_object_manager.rb index d77192158..fa9d3e69b 100644 --- a/db/migrate/20140831000001_create_object_manager.rb +++ b/db/migrate/20140831000001_create_object_manager.rb @@ -30,6 +30,7 @@ class CreateObjectManager < ActiveRecord::Migration display: 'Customer', data_type: 'user_autocompletion', data_option: { + relation: 'User', autocapitalize: false, multiple: false, null: false, diff --git a/db/migrate/20141217000001_update_object_manager2.rb b/db/migrate/20141217000001_update_object_manager2.rb index a78bc14a5..5e3ba806e 100644 --- a/db/migrate/20141217000001_update_object_manager2.rb +++ b/db/migrate/20141217000001_update_object_manager2.rb @@ -292,7 +292,7 @@ class UpdateObjectManager2 < ActiveRecord::Migration object: 'User', name: 'organization_id', display: 'Organization', - data_type: 'select', + data_type: 'autocompletion_ajax', data_option: { multiple: false, nulloption: true, diff --git a/db/migrate/20150977000001_update_object_manager3.rb b/db/migrate/20150977000001_update_object_manager3.rb new file mode 100644 index 000000000..eb8757de4 --- /dev/null +++ b/db/migrate/20150977000001_update_object_manager3.rb @@ -0,0 +1,71 @@ +class UpdateObjectManager3 < ActiveRecord::Migration + def up + + ObjectManager::Attribute.add( + object: 'User', + name: 'organization_id', + display: 'Organization', + data_type: 'autocompletion_ajax', + data_option: { + multiple: false, + nulloption: true, + null: true, + relation: 'Organization', + item_class: 'formGroup--halfSize', + }, + editable: false, + active: true, + screens: { + signup: {}, + invite_agent: {}, + edit: { + '-all-' => { + null: true, + }, + }, + view: { + '-all-' => { + shown: true, + }, + }, + }, + pending_migration: false, + position: 900, + created_by_id: 1, + updated_by_id: 1, + ) + + ObjectManager::Attribute.add( + object: 'Ticket', + name: 'customer_id', + display: 'Customer', + data_type: 'user_autocompletion', + data_option: { + relation: 'User', + autocapitalize: false, + multiple: false, + null: false, + limit: 200, + placeholder: 'Enter Person or Organization/Company', + minLengt: 2, + translate: false, + }, + editable: false, + active: true, + screens: { + create_top: { + Agent: { + null: false, + }, + }, + edit: {}, + }, + pending_migration: false, + position: 10, + created_by_id: 1, + updated_by_id: 1, + ) + + end + +end