From 182a90af4a6a0fce5d635fc3a36b1c92474833e8 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 11 Jan 2013 16:03:24 +0600 Subject: [PATCH] [refs #818] refactoring part4 --- app/controllers/admin/users_controller.rb | 13 ++++--------- app/views/admin/users/_users_ajax.json.jbuilder | 8 ++++---- app/views/admin/users/index.html.haml | 2 +- config/routes.rb | 1 - 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 2db5b4f11..301b4561e 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -9,8 +9,7 @@ class Admin::UsersController < Admin::BaseController end def system - @users = @users.system - @filter = 'system' + @users, @filter = @users.system, 'system' render :index end @@ -58,10 +57,10 @@ class Admin::UsersController < Admin::BaseController end def list - if action_name == 'list' + if params[:system] != 'true' colName, @users = ['users.name', 'users.uname', 'users.email'], @users.opened - else # system_list - colName, @users = ['users.uname'], @users.system + else + colName, @users, @system_list = ['users.uname'], @users.system, true end sort_col = params[:iSortCol_0] || 0 sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc' @@ -79,10 +78,6 @@ class Admin::UsersController < Admin::BaseController render :partial => 'users_ajax', :layout => false end - def system_list - list - end - def reset_auth_token @user.reset_authentication_token! flash[:notice] = t("flash.user.reset_auth_token") diff --git a/app/views/admin/users/_users_ajax.json.jbuilder b/app/views/admin/users/_users_ajax.json.jbuilder index d2eb160ef..052003e36 100644 --- a/app/views/admin/users/_users_ajax.json.jbuilder +++ b/app/views/admin/users/_users_ajax.json.jbuilder @@ -1,12 +1,12 @@ users = @users.map do |user| link_block = [ - (link_to t('layout.show'), user if can?(:read, user) && action_name == 'list'), - (link_to t('layout.edit'), edit_admin_user_path(user) if can?(:edit, user) && action_name == 'list'), - (link_to t('layout.users.reset_token'), reset_auth_token_admin_user_path(user), :method => :put, :confirm => t('layout.users.confirm_reset_token') if can?(:edit, user) && action_name == 'system_list'), + (link_to t('layout.show'), user if can?(:read, user) && !@system_list), + (link_to t('layout.edit'), edit_admin_user_path(user) if can?(:edit, user) && !@system_list), + (link_to t('layout.users.reset_token'), reset_auth_token_admin_user_path(user), :method => :put, :confirm => t('layout.users.confirm_reset_token') if can?(:edit, user) && @system_list), (link_to t('layout.delete'), admin_user_path(user), :method => :delete, :confirm => t('layout.users.confirm_delete') if can? :destroy, user) ].compact.join(' | ').html_safe - if action_name == 'list' + if !@system_list [ user.name, user.uname, diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index 1ef60941d..2ccbc25d6 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -11,7 +11,7 @@ :filtered_label => t("datatables.filtered_label"), :table_dom_id => 'datatable', :auto_width => 'false', - :ajax_source => "#{url_for :controller => 'admin/users', :action => @filter == 'system' ? :system_list : :list}", + :ajax_source => "#{url_for :controller => 'admin/users', :action => :list, :system => (@filter == 'system')}", :additional_data => {:filter => "' + $('#users_filter[type=\"radio\"]:checked').val() + '"} }) %table#datatable.tablesorter.list-users{:cellspacing => 0, :cellpadding => 0} diff --git a/config/routes.rb b/config/routes.rb index 982a73968..a03dc68e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,7 +98,6 @@ Rosa::Application.routes.draw do collection do get :list get :system - get :system_list end put :reset_auth_token, :on => :member end