orbit-4-2/app/controllers/admin/member_selects_controller.rb

100 lines
2.6 KiB
Ruby
Raw Normal View History

class Admin::MemberSelectsController < OrbitBackendController
def index
# @member_selects = OrbitApp::Module::Role.all
@member_selects = Role.excludes('disabled' => true)
if(!params[:show_plugin_profile].nil?)
@right_partial = OrbitApp::Plugin::Registration.find_by_key(params[:show_plugin_profile]).profile_partial_path rescue 'plugin_summary'
else
@right_partial = "admin/users_new_interface/plugin_summary"
end
@member_select_results = Role.excludes('disabled' => true)
@member_select_search_url = admin_member_selects_path
# @aa = User.where(:role_ids.in => [ "4f45f3b9e9d02c5db900001c"])
end
# def show
# @aa = admin_member_selects_path
# respond_to do |format|
# format.js{ render 'member_select_search' }
# end
# end
def member_select_add
# @users = User.where(:ids.in => [params[:users].collect{|x| x[0]}])
@users = params[:users].collect{|key,value| User.find key } rescue []
# debugger
respond_to do |format|
format.js
end
end
def member_select_search
@pdatas = params[:member_selects]
@users = Role.excludes('disabled' => true)
# debugger
# User.where(:role_ids.in => [ "4f45f3b9e9d02c5db900001c"])
# @users = User.where(:role_ids.in => [ "your role_id"])
# @users.where(:sub_role_ids.in => [id, id, id])
# @member_select_results = Role.excludes('disabled' => true)
@member_select_results = User.not_guest_user.where(:sub_role_ids.in => params[:member_selects][:sub_role])
@member_select_search_url = admin_member_select_member_select_add_path('member_select_add')
respond_to do |format|
format.js
end
end
def select_members
selected_users = User.find(params[:ids]) rescue []
@field = params[:field]
roles = Role.all
@sorted_users = roles.inject({}) do |users, role|
# users[role] = role.users.where(:email.not => /guest|rulingcom/) - selected_users
users[role] = role.users.where(:email.not => /guest/) - selected_users
users
end
end
def set_roles
roles = Role.find(params[:role_ids]) rescue []
@field = params[:field]
@users = roles.inject([]) do |users, role|
# users += role.users.where(:email.not => /guest|rulingcom/).entries
users += role.users.where(:email.not => /guest/).entries
users
end
render 'admin/member_selects/update_selected_users'
end
def set_users
@users = User.find(params[:user_ids]) rescue []
@field = params[:field]
render 'admin/member_selects/update_selected_users'
end
end