Orbit/app/controllers/admin/users_new_interface_control...

408 lines
12 KiB
Ruby
Raw Permalink Normal View History

2013-08-09 07:07:05 +00:00
class Admin::UsersNewInterfaceController < OrbitMemberController
helper MemberHelper
2013-08-30 08:47:44 +00:00
helper OrbitBackendHelper
2012-09-11 02:53:05 +00:00
before_filter :set_attribute,:except => [:index,:show]
open_for_user :only => [:setting_account, :edit_user_data, :update]
open_for_visitor :only => [:index, :show]
2013-01-07 06:04:14 +00:00
2012-09-11 02:53:05 +00:00
def index
2012-09-17 04:06:21 +00:00
get_tags
get_sub_roles
2013-08-09 07:07:05 +00:00
@roles = Role.excludes('disabled' => true).asc("_id")
2012-09-17 04:06:21 +00:00
page_num = params[:page] || 1
@users = []
2013-08-09 07:07:05 +00:00
@filter = params[:filter]
2013-08-30 08:47:44 +00:00
@mq = params[:mq]
@new_filter = params[:new_filter]
2013-08-09 07:07:05 +00:00
if @filter && params[:clear]
@filter.delete(params[:type])
2013-08-30 08:47:44 +00:00
elsif @filter && @new_filter
if @filter.has_key?(@new_filter[:type]) && @filter[@new_filter[:type]].include?(@new_filter[:id].to_s)
@filter[@new_filter[:type]].delete(@new_filter[:id].to_s)
elsif @filter.has_key?(@new_filter[:type])
@filter[@new_filter[:type]] << @new_filter[:id].to_s
2012-09-11 02:53:05 +00:00
else
2013-08-30 08:47:44 +00:00
@filter.merge!({@new_filter[:type] => [@new_filter[:id].to_s]})
2013-08-09 07:07:05 +00:00
end
2013-08-30 08:47:44 +00:00
elsif @new_filter
@filter = {@new_filter[:type] => [@new_filter[:id].to_s]}
2013-08-09 07:07:05 +00:00
end
2013-08-30 08:47:44 +00:00
if @filter.blank? and @mq.blank?
2013-08-09 07:07:05 +00:00
render case params[:at]
when 'summary'
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.page(page_num).per(12).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index_summary"
when 'thumbnail'
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.page(page_num).per(36).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index_thumbnail"
else
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.page(page_num).per(10).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index"
end
2013-08-30 08:47:44 +00:00
elsif @filter.blank? and !@mq.blank?
render case params[:at]
when 'summary'
@users=User.not_guest_user.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id").includes('avatar')
"index_summary"
when 'thumbnail'
@users=User.not_guest_user.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id").includes('avatar')
"index_thumbnail"
else
@users=User.not_guest_user.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id").includes('avatar')
"index"
end
elsif !@filter.blank? and @mq.blank?
2013-08-09 07:07:05 +00:00
render case params[:at]
when 'summary'
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.any_in(:role_ids=>@filter['role']).page(page_num).per(12).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index_summary"
when 'thumbnail'
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.any_in(:role_ids=>@filter['role']).page(page_num).per(36).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index_thumbnail"
else
2013-08-30 08:47:44 +00:00
@users=User.not_guest_user.any_in(:role_ids=>@filter['role']).page(page_num).per(10).desc("_id").includes('avatar')
2013-08-09 07:07:05 +00:00
"index"
end
2012-09-11 02:53:05 +00:00
end
2013-08-09 07:07:05 +00:00
2012-09-11 02:53:05 +00:00
end
def show
2012-09-11 02:53:05 +00:00
@user = User.find(params[:id])
@plugins = OrbitApp::Plugin::Registration.all
@ppname = Array.new
@plugins.each do |aa|
@ppname << [aa.sort_number.to_i, [aa.name, aa.app_name, aa.intro_app_name, aa.front_partial_path]]
end
@plugin_shows = @ppname.sort.collect {|v| {"name"=>v[1][0],"app_name"=>v[1][1],"intro_app_name"=>v[1][2],"front_partial_path"=>v[1][3]} }
2012-09-17 04:06:21 +00:00
@profile_data = []
@teacher_data = []
@student_data = []
@staff_data = []
attribute_values = @user.attribute_values.asc("_id")
2012-10-18 10:36:21 +00:00
attribute_values.each{|att_val|
2012-11-05 03:30:15 +00:00
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale.to_s)}) if att_val.attribute_field.attribute.key=="profile" rescue false
2012-09-17 04:06:21 +00:00
}
if(!params[:show_plugin_profile].nil?)
@right_partial = OrbitApp::Plugin::Registration.find_by_app_name(params[:show_plugin_profile]).profile_partial_path rescue 'plugin_summary'
@plugin_app_name = OrbitApp::Plugin::Registration.find_by_app_name(params[:show_plugin_profile]).name rescue nil
else
@right_partial = "plugin_summary"
@plugin_app_name = ''
end
2012-09-17 04:06:21 +00:00
# @user.attribute_values.each{|att_val|
# @teacher_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# @user.attribute_values.each{|att_val|
# @student_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# @user.attribute_values.each{|att_val|
# @staff_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# [ {:name=> "1",:value =>"Matt"},{:name=> "2",:value =>"Mark"},{:name=> "3",:value =>"Luke"},{:name=> "4",:value =>"John"} ]
2012-09-11 02:53:05 +00:00
get_info_and_roles
end
def new
@user = User.new
# @disable_all_field = true
2012-10-15 05:54:29 +00:00
@form_index = 0
2012-09-11 02:53:05 +00:00
get_info_and_roles
end
def create
# puts params.to_yaml
# attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
# attribute_values = params[:user].delete(attribute_values_key)
2012-10-15 05:54:29 +00:00
@user = User.new(params["user"])
@checkuser = User.where(:user_id => params[:user][:user_id]).first
if !@checkuser.blank?
flash.now[:error] = t("users.user_id_error")
end
# attribute_values.to_hash.each{|key,value|
# @user.attribute_values.build(value)
# }
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
2012-11-08 10:59:19 +00:00
# binding.pry
if !flash.now[:error] && @user.save
Merge branch 'various_bugs' into nccu_master Conflicts: Gemfile.lock app/assets/javascripts/ajax_form.js.erb app/assets/stylesheets/style.css.erb app/controllers/application_controller.rb app/controllers/sessions_controller.rb app/helpers/admin/web_link_helper.rb app/views/admin/attributes/_attribute_field.html.erb app/views/admin/designs/_form.html.erb app/views/admin/pages/_form.html.erb app/views/admin/sites/_side_bar.html.erb app/views/layouts/_orbit_bar.html.erb app/views/layouts/_side_bar.html.erb config/locales/en.yml config/locales/zh_tw.yml config/mongoid.yml vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter_status.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_news_bulletin.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb
2012-10-29 08:10:07 +00:00
flash[:notice] = t('create.success.user')
2012-09-11 02:53:05 +00:00
redirect_to :action => :index
else
@user.attribute_values = nil
2012-10-15 05:54:29 +00:00
@form_index = 0
render :action => :new , :notice => flash.now[:error]
2012-09-11 02:53:05 +00:00
end
end
2012-10-08 08:58:33 +00:00
def temp_edit
@user = User.find(params[:id])
@form_index = 0
get_info_and_roles
end
2012-09-11 02:53:05 +00:00
def edit
# @disable_all_field = false
2012-09-11 02:53:05 +00:00
@user = User.find(params[:id])
2012-10-08 08:58:33 +00:00
@form_index = 0
2012-09-11 02:53:05 +00:00
get_info_and_roles
end
def edit_passwd
# @disable_all_field = false
@user = User.find(params[:users_new_interface_id])
2013-10-18 11:02:14 +00:00
if current_user.id == @user.id
redirect_to :action => :index
end
end
def edit_privilege
@user = User.find(params[:users_new_interface_id])
if current_user.id == @user.id
redirect_to :action => :index
end
end
def edit_user_data
if params[:users_new_interface_id].blank?
redirect_to :action => :index
else
@user = User.find(params[:users_new_interface_id])
if current_user.id != @user.id
redirect_to :action => :index
end
@form_index = 0
get_info_and_roles
end
end
def setting_account
if params[:users_new_interface_id].blank?
redirect_to :action => :index
else
@user = User.find(params[:users_new_interface_id])
if current_user.id != @user.id
redirect_to :action => :index
end
end
end
2012-09-11 02:53:05 +00:00
def update
2012-09-11 02:53:05 +00:00
@user = User.find(params[:id])
if params[:edit_type] == 'edit_passwd'
@checkuser = User.where(:user_id => params[:user][:user_id]).first
if !@checkuser.blank? && @checkuser.id != @user.id
flash.now[:error] = t("users.user_id_error")
elsif @user.admin && current_user.id == @user.id
flash.now[:error] = t("users.admin_change_password")
end
if !flash.now[:error] && @user.update_attributes(params[:user])
redirect_to :action => :show
else
render :action => :edit_passwd, :notice => flash.now[:error]
end
elsif params[:edit_type] == 'edit_user_data'
2013-10-18 11:02:14 +00:00
if current_user.id != @user.id
redirect_to :action => :index
end
2013-10-18 11:02:14 +00:00
@user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
@user.save
redirect_to :action => :show
elsif params[:edit_type] == 'setting_account'
if current_user.id != @user.id
redirect_to :action => :index
end
if !@user.valid_password?(params[:old_password])
flash.now[:error] = t("users.valid_old_password")
2013-10-18 11:02:14 +00:00
end
if !flash.now[:error] && @user.update_attributes(params[:user])
redirect_to :action => :show
else
render :action => :setting_account, :notice => flash.now[:error]
2013-10-18 11:02:14 +00:00
end
2013-10-18 11:02:14 +00:00
elsif params[:edit_type] == 'edit_privilege'
if @user.admin && current_user.id == @user.id
flash.now[:error] = t("users.admin_change_password")
end
if !flash.now[:error] && @user.update_attributes(params[:user])
redirect_to :action => :show
else
render :action => :edit_privilege, :notice => flash.now[:error]
end
else
@user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
@user.save
redirect_to :action => :show
end
2012-11-08 10:59:19 +00:00
2012-10-08 08:58:33 +00:00
# # Update changes to the avatar
# @user.remove_avatar! if params[:file]
# @user.avatar = params[:file] if params[:file]
2012-09-11 02:53:05 +00:00
2012-10-08 08:58:33 +00:00
# if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b
Merge branch 'various_bugs' into nccu_master Conflicts: Gemfile.lock app/assets/javascripts/ajax_form.js.erb app/assets/stylesheets/style.css.erb app/controllers/application_controller.rb app/controllers/sessions_controller.rb app/helpers/admin/web_link_helper.rb app/views/admin/attributes/_attribute_field.html.erb app/views/admin/designs/_form.html.erb app/views/admin/pages/_form.html.erb app/views/admin/sites/_side_bar.html.erb app/views/layouts/_orbit_bar.html.erb app/views/layouts/_side_bar.html.erb config/locales/en.yml config/locales/zh_tw.yml config/mongoid.yml vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter_status.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_news_bulletin.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb
2012-10-29 08:10:07 +00:00
# flash.now[:error] = t(:cant_revoke_self_admin)
2012-10-08 08:58:33 +00:00
# end
# if !flash[:error] && @user.update_attributes(params[:user])
Merge branch 'various_bugs' into nccu_master Conflicts: Gemfile.lock app/assets/javascripts/ajax_form.js.erb app/assets/stylesheets/style.css.erb app/controllers/application_controller.rb app/controllers/sessions_controller.rb app/helpers/admin/web_link_helper.rb app/views/admin/attributes/_attribute_field.html.erb app/views/admin/designs/_form.html.erb app/views/admin/pages/_form.html.erb app/views/admin/sites/_side_bar.html.erb app/views/layouts/_orbit_bar.html.erb app/views/layouts/_side_bar.html.erb config/locales/en.yml config/locales/zh_tw.yml config/mongoid.yml vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter_status.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_news_bulletin.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb
2012-10-29 08:10:07 +00:00
# flash[:notice] = t('update.success.user')
2012-10-08 08:58:33 +00:00
# redirect_to :action => :index
# else
# get_info_and_roles
# render :action => :edit
# end
2012-09-11 02:53:05 +00:00
end
def destroy
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
Merge branch 'various_bugs' into nccu_master Conflicts: Gemfile.lock app/assets/javascripts/ajax_form.js.erb app/assets/stylesheets/style.css.erb app/controllers/application_controller.rb app/controllers/sessions_controller.rb app/helpers/admin/web_link_helper.rb app/views/admin/attributes/_attribute_field.html.erb app/views/admin/designs/_form.html.erb app/views/admin/pages/_form.html.erb app/views/admin/sites/_side_bar.html.erb app/views/layouts/_orbit_bar.html.erb app/views/layouts/_side_bar.html.erb config/locales/en.yml config/locales/zh_tw.yml config/mongoid.yml vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter_status.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_news_bulletin.html.erb vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb
2012-10-29 08:10:07 +00:00
flash[:error] = t(:cant_delete_self)
2012-09-11 02:53:05 +00:00
else
@user = User.find(params[:id])
@user.destroy
end
2013-08-30 08:47:44 +00:00
# redirect_to :action => :index
respond_to do |format|
format.html { redirect_to(admin_users_new_interface_index_url(:at=>params[:at])) }
# format.xml { head :ok }
format.js
end
2012-09-11 02:53:05 +00:00
end
2013-10-07 07:52:10 +00:00
def edit_order_card
2013-09-26 11:46:14 +00:00
@users = User.not_guest_user
2013-10-07 07:52:10 +00:00
@type = 'card'
render 'edit_order'
end
2013-10-07 07:52:10 +00:00
def edit_order_list
@users = User.not_guest_user
@type = 'list'
render 'edit_order'
end
def update_order_card
@error = false
if params[:users].present?
to_go = params[:users][:position].to_i
user_at_position = User.where(position: to_go).first
user = User.find(params[:users][:id])
if user_at_position
if user.position > user_at_position.position
user.move_above(user_at_position)
else
user.move_below(user_at_position)
end
end
end
render nothing: true, status: 200
end
def update_order_list
@error = []
if params[:users].present?
params[:users].values.sort.each do |pair|
to_go = pair[0].to_i
if to_go > 0
user_at_position = User.where(position: to_go - 1).first
user = User.find(pair[1])
2013-09-27 04:46:19 +00:00
if user_at_position && !(user_at_position == user)
if user.position > user_at_position.position
user.move_above(user_at_position)
else
user.move_below(user_at_position)
end
elsif to_go > User.count
user.move_to_bottom
end
end
end
end
2013-09-26 11:46:14 +00:00
@users = User.not_guest_user
end
2012-09-11 02:53:05 +00:00
protected
2012-09-17 04:06:21 +00:00
def get_tags
@sub_role_tags = SubRoleTag.all
end
def get_sub_roles
@sub_roles = SubRole.all
end
2012-09-11 02:53:05 +00:00
def get_info_and_roles
@infos = Info.excludes('disabled' => true)
@roles = Role.excludes('disabled' => true)
end
def set_attribute
@class = 'users'
end
end