Permalink
Browse files

WIP: archived 'users' now work correctly; now working on other user '…

…types'
  • Loading branch information...
1 parent d64513f commit 1e297b5c40503ae3c6b4e1787ba1830821025d97 @rnhurt committed Nov 2, 2010
@@ -1,16 +1,25 @@
class UsersController < ApplicationController
before_filter :require_user
- before_filter :decode_user_type, :except => "archive"
+ before_filter :decode_user_type, :except => ["archive"]
append_before_filter :authorized?
include SortHelper
+ # Show 'active' users
def index
sort_init 'last_name'
sort_update
params[:sort_clause] = sort_clause
@users = @user_type.active.search(params)
end
+ # Show 'archived' users
+ def archived
+ sort_init 'last_name'
+ sort_update
+ params[:sort_clause] = sort_clause
+ @users = @user_type.archived.search(params)
+ render :index
+ end
# Show the group of users
@@ -23,7 +32,6 @@ def show
render :index
end
-
def new
@user = @user_type.new
render :action => 'edit'
@@ -85,7 +93,7 @@ def archive
# The list of users is sent to this method using the "on" value. Therefor we grab all the
# elements in the params array that has a value of "on" and process them.
params.reject{|k,v| v !="on" }.keys.each do |id|
- User.find(id).archive
+ User.find(id).toggle_archive
end
redirect_to users_url
View
@@ -18,13 +18,13 @@ class User < ActiveRecord::Base
validates_existence_of :site
named_scope :active, :conditions => { :active => true }
- scope :archived, :conditions => { :active => false }
+ named_scope :archived, :conditions => { :active => false }
# Search for a user using the 'will_paginate' plugin
def self.search(params)
search = params[:search]
search.downcase! if search # Make sure we don't have any case sensitivity problems
- paginate :per_page => 15, :page => params[:page],
+ paginate :per_page => 20, :page => params[:page],
:conditions => ['LOWER(first_name) like ? or LOWER(last_name) like ?', "%#{search}%", "%#{search}%"],
:order => params[:sort_clause],
:include => :site
@@ -35,7 +35,7 @@ def self.user_types
types = []
types << {'All (active)' => nil} << {'Students' => Student}
types << {'Teachers' => Teacher} << {'Teacher Assistants' => TeacherAssistant}
- types << {'Archived' => nil}
+ types << {:name => "archived", "Archived" => nil }
end
# Display the user's full name.
@@ -50,9 +50,9 @@ def full_name=(name)
self.last_name = split.last
end
- # Archive a user by setting its "active" bit to false
- def archive
- self.active = false
+ # Change a users Archive status by toggling it's "active" bit
+ def toggle_archive
+ self.active = !self.active
self.save!
end
end
@@ -1,3 +1,5 @@
+<% archived = current_page?(:action => :archived) %>
+
<table id="users" class="master">
<thead>
<tr>
@@ -16,7 +18,7 @@
<form method="post" action="/users/0/archive">
<input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>" />
- <th><%= submit_tag "Archive" %></th>
+ <th><%= submit_tag archived ? "Restore" : "Archive" %></th>
</tr>
</thead>
@@ -52,6 +54,4 @@
<span class="paginate">
<%= will_paginate users %>
-</span>
-
-<%#= javascript_tag "$$('input:checked')" %>
+</span>
@@ -8,8 +8,18 @@
<tbody>
<% User.user_types.each do |type| %>
<% key,value = type.shift %>
- <% url = %W{/users #{value.try(:name).try(:tableize)}}.join('/') %>
- <tr class="<%= "#{cycle('odd', 'even')} #{value.nil? || !current_page?(:controller => url) ? '' : ' current'}" %>"
+ <% if Class == value.class %>
+ <% url = %W{/users #{value.try(:name).try(:tableize)}}.join('/') %>
+ <% current = current_page?(:controller => url) %>
+ <% elsif !type[:name].nil? %>
+ <% url = "/users/#{type[:name]}" %>
+ <% current = true if current_page?(:action => type[:name]) %>
+ <% else %>
+ <% url = "/users" %>
+ <% current = current_page?(:controller => url) %>
+ <% end %>
+
+ <tr class="<%= "#{cycle('odd', 'even')} #{current ? ' current' : ''}" %>"
onclick="location.href='<%= url -%>'">
<%= content_tag :td, key %>
<%= content_tag :td, value.nil? ? '' : button_to(
View
@@ -6,7 +6,7 @@
# Since we subclass the Users into different types,
# we need to build routes for them.
- map.resources :users, :member => { :archive => :post }
+ map.resources :users, :member => { :archive => :post }, :collection => { :archived => :get }
map.namespace :users do |u|
u.resources :students, :name_prefix => nil
u.resources :teachers, :name_prefix => nil

0 comments on commit 1e297b5

Please sign in to comment.