2012-11-21 03:46:06 +00:00
|
|
|
class Admin::UsersNewInterfaceController < OrbitBackendController
|
2012-09-11 02:53:05 +00:00
|
|
|
|
2012-11-21 03:46:06 +00:00
|
|
|
# before_filter :authenticate_user!
|
|
|
|
# before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
2012-09-11 02:53:05 +00:00
|
|
|
|
2012-11-21 03:46:06 +00:00
|
|
|
before_filter :force_order_for_visitor,:only=>[:index,:show]
|
|
|
|
before_filter :force_order_for_user,:except => [:index,:show]
|
2012-11-22 09:49:44 +00:00
|
|
|
before_filter :set_attribute,:except => [:index,:show]
|
2012-11-21 03:46:06 +00:00
|
|
|
|
2013-01-07 06:04:14 +00:00
|
|
|
def setup_vars
|
|
|
|
# @app_title ||= controller_path.split('/')[1].singularize
|
|
|
|
# @module_app ||= ModuleApp.first(conditions: {:key => @app_title} )
|
|
|
|
# raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil?
|
|
|
|
end
|
|
|
|
|
2012-09-11 02:53:05 +00:00
|
|
|
def index
|
2012-09-17 04:06:21 +00:00
|
|
|
get_tags
|
|
|
|
get_sub_roles
|
|
|
|
|
|
|
|
page_num = params[:page] || 1
|
|
|
|
@users = []
|
2012-09-11 02:53:05 +00:00
|
|
|
|
|
|
|
render case params[:at]
|
|
|
|
when 'summary'
|
2012-12-19 08:46:01 +00:00
|
|
|
@users=User.not_guest_user.page(page_num).per(12).includes('avatar')
|
2012-09-11 02:53:05 +00:00
|
|
|
"index_summary"
|
|
|
|
when 'thumbnail'
|
2012-12-19 08:46:01 +00:00
|
|
|
@users=User.not_guest_user.page(page_num).per(36).includes('avatar')
|
2012-09-11 02:53:05 +00:00
|
|
|
"index_thumbnail"
|
|
|
|
else
|
2012-12-19 08:46:01 +00:00
|
|
|
@users=User.not_guest_user.page(page_num).per(10).includes('avatar')
|
2012-09-11 02:53:05 +00:00
|
|
|
"index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@user = User.find(params[:id])
|
2012-11-20 07:56:52 +00:00
|
|
|
@plugins = OrbitApp::Plugin::Registration.all
|
2012-09-24 03:43:48 +00:00
|
|
|
|
2012-09-17 04:06:21 +00:00
|
|
|
@profile_data = []
|
|
|
|
@teacher_data = []
|
|
|
|
@student_data = []
|
|
|
|
@staff_data = []
|
|
|
|
|
2012-11-05 03:30:15 +00:00
|
|
|
attribute_values = @user.attribute_values
|
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
|
|
|
}
|
|
|
|
|
2012-10-12 10:17:05 +00:00
|
|
|
|
2012-09-24 03:43:48 +00:00
|
|
|
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 = "plugin_summary"
|
|
|
|
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
|
2012-10-24 06:46:25 +00:00
|
|
|
# @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
|
2012-10-24 06:46:25 +00:00
|
|
|
# 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"])
|
2012-10-24 06:46:25 +00:00
|
|
|
# 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
|
2012-09-11 02:53:05 +00:00
|
|
|
if @user.save
|
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
|
2012-10-15 05:54:29 +00:00
|
|
|
@form_index = 0
|
2012-09-11 02:53:05 +00:00
|
|
|
render :action => :new
|
|
|
|
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
|
2012-10-24 06:46:25 +00:00
|
|
|
# @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 update
|
|
|
|
@user = User.find(params[:id])
|
2012-11-08 10:59:19 +00:00
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
@user.update_attributes(params[:user])
|
2012-10-18 10:36:21 +00:00
|
|
|
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-24 06:46:25 +00:00
|
|
|
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
|
2012-10-08 08:58:33 +00:00
|
|
|
@user.save
|
|
|
|
redirect_to :action => :show
|
|
|
|
# # 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
|
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])
|
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)
|
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
|
|
|
|
|
|
|
|
redirect_to :action => :index
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|