Permalink
Browse files

User view mods

* Modified the user_types method to sort the results in a sane way
* Modified each user to properly use the homeroom and user_types changes
  • Loading branch information...
1 parent fe3043d commit cc2babe231010ef9796c531df3dd58eab4243312 @rnhurt committed Aug 21, 2010
@@ -25,7 +25,7 @@ def show
def new
@student = Student.new
- @homerooms = Student.homerooms.active
+ @homerooms = Student.homerooms
render :action => :edit
end
@@ -41,15 +41,11 @@ def create
@student = Student.new(params[:student])
@homerooms = Student.homerooms
- respond_to do |format|
if @student.save
flash[:notice] = 'Student was successfully created.'
- format.html { redirect_to(@student) }
- format.xml { render :xml => @student, :status => :created, :location => @student }
+ redirect_to @student
else
- format.html { render :action => "new" }
- format.xml { render :xml => @student.errors, :status => :unprocessable_entity }
- end
+ render :action => :edit
end
end
@@ -64,7 +60,7 @@ def update
flash[:notice] = "Student '" + @student.full_name + "' was successfully updated."
redirect_to students_url
else
- @homerooms = Student.homerooms.active
+ @homerooms = Student.homerooms
render :action => "edit"
end
end
@@ -34,40 +34,30 @@ def edit
def create
@teacher_assistant = TeacherAssistant.new(params[:teacher_assistant])
- respond_to do |format|
- if @teacher_assistant.save
- flash[:notice] = "Teacher Assistant '#{@teacher_assistant.full_name}' was successfully created."
- format.html { redirect_to(@teacher_assistant) }
- format.xml { render :xml => @teacher_assistant, :status => :created, :location => @teacher_assistant }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @teacher_assistant.errors, :status => :unprocessable_entity }
- end
+ if @teacher_assistant.save
+ flash[:notice] = "Teacher Assistant '#{@teacher_assistant.full_name}' was successfully created."
+ redirect_to @teacher_assistant
+ else
+ render :action => :new
end
end
def update
@teacher_assistant = TeacherAssistant.find(params[:id])
- respond_to do |format|
- if @teacher_assistant.update_attributes(params[:teacher_assistant])
- flash[:notice] = 'TeacherAssistant was successfully updated.'
- format.html { redirect_to(@teacher_assistant) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @teacher_assistant.errors, :status => :unprocessable_entity }
- end
+ if @teacher_assistant.update_attributes(params[:teacher_assistant])
+ flash[:notice] = 'TeacherAssistant was successfully updated.'
+ redirect_to @teacher_assistant
+ else
+ render :action => :edit
end
end
def destroy
@teacher_assistant = TeacherAssistant.find(params[:id])
@teacher_assistant.destroy
- respond_to do |format|
- format.html { redirect_to(teacher_assistants_url) }
- format.xml { head :ok }
- end
+ redirect_to teacher_assistants_url
+
end
end
@@ -37,27 +37,23 @@ def edit
def create
@teacher = Teacher.new(params[:teacher])
- respond_to do |format|
- if @teacher.save
- flash[:notice] = "Teacher was '#{@teacher.full_name}' successfully created."
- format.html { redirect_to(teachers_url) }
- else
- format.html { render :action => "new" }
- end
+ if @teacher.save
+ flash[:notice] = "Teacher was '#{@teacher.full_name}' successfully created."
+ redirect_to teachers_url
+ else
+ render :action => :edit
end
end
def update
@teacher = Teacher.find(params[:id])
- respond_to do |format|
- if @teacher.update_attributes(params[:teacher])
- flash[:notice] = "Teacher was '#{@teacher.full_name}' successfully updated."
- format.html { redirect_to(teachers_url) }
- else
- format.html { render :action => "edit" }
- end
+ if @teacher.update_attributes(params[:teacher])
+ flash[:notice] = "Teacher was '#{@teacher.full_name}' successfully updated."
+ redirect_to teachers_url
+ else
+ render :action => :edit
end
end
@@ -66,9 +62,7 @@ def destroy
@teacher = Teacher.find(params[:id])
@teacher.destroy
- respond_to do |format|
- format.html { redirect_to(teachers_url) }
- format.xml { head :ok }
- end
+ redirect_to teachers_url
end
+
end
View
@@ -17,7 +17,10 @@ class Student < User
:in => from_year..to_year,
:message => "must be in the range of #{from_year} to #{to_year}"
- named_scope :homerooms, :select => 'DISTINCT homeroom', :conditions => {:active => true}
+ named_scope :homerooms, :select => 'DISTINCT homeroom', :order => 'homeroom',
+ :conditions => { :active => true }
+# :conditions => ["active = ? AND homeroom != ''", true]
+
named_scope :sorted, :order => 'last_name ASC'
def current_course_terms
View
@@ -31,8 +31,9 @@ def self.search(params)
# Return the valid user types available
def self.user_types
- return 'All (active)' => nil, 'Students' => Student,
- 'Teachers' => Teacher, 'Teacher Assistants' => TeacherAssistant
+ types = []
+ types << {'All (active)' => nil} << {'Students' => Student}
+ types << {'Teachers' => Teacher} << {'Teacher Assistants' => TeacherAssistant}
end
# Display the user's full name.
@@ -40,7 +40,8 @@
<%= f.label :homeroom %>
<%= text_field_tag :homeroom1, {}, :maxlength => 20 %>
- <%= f.select :homeroom, @homerooms, :include_blank => true %>
+ <%#= f.select :homeroom, @homerooms, :include_blank => true %>
+ <%= collection_select :student, :homeroom, @homerooms, :homeroom, :homeroom %>
<% end %>
<div class="spacer">
@@ -6,12 +6,13 @@
</tr>
</thead>
<tbody>
- <% User.user_types.each do |key, value| %>
+ <% 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' : ''}"%>"
+ <tr class="<%= "#{cycle('odd', 'even')} #{value.nil? || !current_page?(:controller => url) ? '' : ' current'}" %>"
onclick="location.href='<%= url -%>'">
<%= content_tag :td, key %>
- <%= content_tag :td, value.nil? ? '' : button_to(
+ <%= content_tag :td, value.nil? ? '' : button_to(
'New', "#{url}/new", :method => :get, :class => 'btn standard sml' ) %>
</tr>
<% end %>

0 comments on commit cc2babe

Please sign in to comment.