Permalink
Browse files

filter teachers on school

  • Loading branch information...
1 parent fcd7ec6 commit 764dd578612937d740f6f71385384b640fdafa01 @panterch committed Dec 29, 2011
@@ -9,9 +9,11 @@ class KidsController < ApplicationController
before_filter :assign_mentor_selection, :only => [:edit_schedules]
def index
+ # filter kids with additional criterias if any
if params[:kid]
@kids = @kids.where(params[:kid].delete_if {|key, val| val.blank? })
end
+ # provide a prototype kid for the filter form
@kid = Kid.new(params[:kid])
return redirect_to collection.first if (1 == collection.count)
index!
@@ -1,4 +1,12 @@
class TeachersController < InheritedResources::Base
load_and_authorize_resource
+ def index
+ if params[:teacher]
+ @teachers = @teachers.where(params[:teacher].delete_if {|key, val| val.blank? })
+ end
+ @teacher = Kid.new(params[:teacher])
+ index!
+ end
+
end
@@ -32,8 +32,14 @@ def translator_collection
{ "Ja" => true, "Nein" => false }
end
- def school_collection
- Kid.connection.select_values("SELECT distinct school FROM kids").compact.sort
+ def school_collection_for_kids
+ values = Kid.connection.select_values("SELECT distinct school FROM kids")
+ values.compact.sort.reject(&:blank?)
+ end
+
+ def school_collection_for_teachers
+ values = Teacher.connection.select_values("SELECT distinct school FROM users WHERE type='Teacher'")
+ values.compact.sort.reject(&:blank?)
end
def term_collection
@@ -6,7 +6,7 @@
= f.select :term, term_collection, { :include_blank => true }
.filterfield
%label Schulhaus
- = f.select :school, school_collection, { :include_blank => true }
+ = f.select :school, school_collection_for_kids, { :include_blank => true }
.filterfield
%label Übersetzer
= f.select :translator, translator_collection, { :include_blank => true }
@@ -16,7 +16,7 @@
.filterfield
%label Aktion
= f.submit 'Filter anwenden'
- = link_to 'Filter aufheben', kids_path
+ = link_to 'Filter aufheben', collection_path
%h2 Sch&uuml;ler/innen
@@ -1,3 +1,14 @@
+-if current_user.is_a?(Admin)
+ %h2 Filterkriterium f&uuml;r Lehrpersonen
+ = form_for :teacher, :url => { :action => 'index' }, :html => { :method => :get, :class => 'filter' } do |f|
+ .filterfield
+ %label Schulhaus
+ = f.select :school, school_collection_for_teachers, { :include_blank => true }
+ .filterfield
+ %label Aktion
+ = f.submit 'Filter anwenden'
+ = link_to 'Filter aufheben', collection_path
+
%h2 Lehrpersonen
%ul
- collection.each do |o|
@@ -268,6 +268,7 @@ de:
user:
email: "E-Mail"
password: Passwort
+ password_confirmation: "Passwort Bestätigung"
name: Name
prename: Vorname
address: Adresse

0 comments on commit 764dd57

Please sign in to comment.