From 01a8a9b5b614dcdb55d06fad75dd43c3c93a9bb7 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 11 Sep 2012 10:53:05 +0800 Subject: [PATCH] users new interface controller --- .../admin/users_new_interface_controller.rb | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 app/controllers/admin/users_new_interface_controller.rb diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb new file mode 100644 index 00000000..30f8a023 --- /dev/null +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -0,0 +1,87 @@ +class Admin::UsersNewInterfaceController < ApplicationController + + layout "new_admin" + before_filter :authenticate_user! + before_filter :set_attribute, :only => [:index, :show, :new, :edit] + + def index + @users = User.all.entries + + render case params[:at] + when 'summary' + "index_summary" + when 'thumbnail' + "index_thumbnail" + else + "index" + end + end + + def show + @user = User.find(params[:id]) + 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 + + def get_info_and_roles + @infos = Info.excludes('disabled' => true) + @roles = Role.excludes('disabled' => true) + end + + def set_attribute + @class = 'users' + end + +end