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

138 lines
3.9 KiB
Ruby
Raw Normal View History

2012-09-11 02:53:05 +00:00
class Admin::UsersNewInterfaceController < ApplicationController
layout "new_admin"
before_filter :authenticate_user!
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
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-09-17 04:06:21 +00:00
@users=User.page(page_num).per(12).includes('avatar')
2012-09-11 02:53:05 +00:00
"index_summary"
when 'thumbnail'
2012-09-17 04:06:21 +00:00
@users=User.page(page_num).per(36).includes('avatar')
2012-09-11 02:53:05 +00:00
"index_thumbnail"
else
2012-09-17 04:06:21 +00:00
@users=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-09-17 04:06:21 +00:00
@profile_data = []
@teacher_data = []
@student_data = []
@staff_data = []
@user.attribute_values.each{|att_val|
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]}) if att_val.attribute_field.attribute.key=="profile" rescue false
}
@user.attribute_values.each{|att_val|
@teacher_data.push({:name => att_val.attribute_field.title,:value => eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="teacher"rescue false
}
@user.attribute_values.each{|att_val|
@student_data.push({:name => att_val.attribute_field.title,:value =>eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="student"rescue false
}
@user.attribute_values.each{|att_val|
@staff_data.push({:name => att_val.attribute_field.title,:value =>eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="staff_data"rescue false
}
# binding.pry
# @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
get_info_and_roles
end
def create
puts params.to_yaml
@user = User.new(params[:user])
if @user.save
flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index
else
render :action => :new
end
end
def edit
@user = User.find(params[:id])
get_info_and_roles
end
def update
@user = User.find(params[:id])
# Update changes to the avatar
@user.remove_avatar! if params[:file]
@user.avatar = params[:file] if params[:file]
if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b
flash.now[:error] = t('admin.cant_revoke_self_admin')
end
if !flash[:error] && @user.update_attributes(params[:user])
flash[:notice] = t('admin.update_success_user')
redirect_to :action => :index
else
get_info_and_roles
render :action => :edit
end
end
def destroy
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
flash[:error] = t('admin.cant_delete_self')
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