From 13514317c9ee93166637e8d2db218c948e5b717f Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 27 May 2014 19:41:35 +0530 Subject: [PATCH] fetprofileprivate data --- app/controllers/fetprofiles_controller.rb | 7 ++++-- app/models/fetprofile.rb | 20 +++++++++++++++- app/views/fetprofiles/_form.html.erb | 23 +++++++++++++++++++ app/views/fetprofiles/_interninfo.html.erb | 13 +++++++++++ app/views/fetprofiles/_internrow.html.erb | 12 ++++++++++ app/views/fetprofiles/internlist.html.erb | 5 ++++ app/views/fetprofiles/show.html.erb | 9 ++++++-- app/views/home/intern.html.erb | 22 +++++++++++++----- config/routes.rb | 1 + ...20140522094444_add_adress_to_fetprofile.rb | 15 ++++++++++++ 10 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 app/views/fetprofiles/_interninfo.html.erb create mode 100644 app/views/fetprofiles/_internrow.html.erb create mode 100644 app/views/fetprofiles/internlist.html.erb create mode 100644 db/migrate/20140522094444_add_adress_to_fetprofile.rb diff --git a/app/controllers/fetprofiles_controller.rb b/app/controllers/fetprofiles_controller.rb index ad61588..83af41c 100644 --- a/app/controllers/fetprofiles_controller.rb +++ b/app/controllers/fetprofiles_controller.rb @@ -12,9 +12,12 @@ class FetprofilesController < ApplicationController @gremientabs = Gremium.tabs respond_to do |format| format.html # index.html.erb - format.json { render json: @fetprofiles } - end + end end + def internlist + @fetprofiles = Fetprofile.order(:vorname,:nachname) + end + # GET /fetprofiles/1 # GET /fetprofiles/1.json diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index 787c175..143b672 100644 --- a/app/models/fetprofile.rb +++ b/app/models/fetprofile.rb @@ -15,7 +15,7 @@ # class Fetprofile < ActiveRecord::Base - attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache + attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache, :plz, :street, :city, :instant,:skype, :telnr, :hdynr, :birth_day,:birth_month, :birth_year has_many :memberships, dependent: :delete_all has_many :gremien, :through=> :membership mount_uploader :picture, PictureUploader @@ -23,11 +23,18 @@ class Fetprofile < ActiveRecord::Base validates :desc, :presence=>true validates :nachname, length:{minimum: 3},:presence=>true validates :vorname, length:{minimum: 3},:presence=>true + validate :validate_birthday has_many :users scope :search, ->(query) {where("nachname like ? or vorname like ? or short like ?", "%#{query}%", "%#{query}%", "%#{query}%")} accepts_nested_attributes_for :memberships, :reject_if=>lambda{|a| a[:typ].blank?|| a[:start].blank? ||a[:gremium_id].blank?}, :allow_destroy=>true has_many :nlinks, as: :link + def validate_birthday + unless Date.valid_date?(birth_year, birth_month, birth_day) + errors.add(:birth_month, "Invalides Datum") + errors.add(:birth_day, "Invalides Datum") + end + end def title self.name @@ -39,4 +46,15 @@ validates :desc, :presence=>true def fetmail (fetmailalias.nil? || fetmailalias.empty?) ? short.to_s + "@fet.at" : fetmailalias.to_s + "@fet.at" end + def adress + connector= (self.street.nil?||self.street.empty?||(self.city.empty? && self.plz.empty?)) ? '' : ', ' + self.plz.to_s + ' ' + self.city.to_s + connector.to_s + self.street.to_s + end + def birthday + if self.birth_year.nil? || self.birth_year.zero? + Date.new( Date.today.year,self.birth_month,self.birth_day) + else + Date.new( self.birth_year,self.birth_month,self.birth_day) + end + end end diff --git a/app/views/fetprofiles/_form.html.erb b/app/views/fetprofiles/_form.html.erb index 8143c08..3714148 100644 --- a/app/views/fetprofiles/_form.html.erb +++ b/app/views/fetprofiles/_form.html.erb @@ -28,6 +28,29 @@
<%= f.input :fetmailalias %>
+
+
+Adresse: + +<%=f.input :street %> +<%=f.input :plz %> +<%=f.input :city %> +KOntakt: +<%=f.input :instant %> +<%=f.input :skype %> +<%=f.input :telnr %> +<%=f.input :hdynr %> + +
+
+Geburtstag: +<%=f.input :birth_day %> +<%=f.input :birth_month %> +<%=f.input :birth_year %> + +
+ +
<% @memberships.each do |m| %> <%= f.semantic_fields_for :memberships, m do |membership| %> diff --git a/app/views/fetprofiles/_interninfo.html.erb b/app/views/fetprofiles/_interninfo.html.erb new file mode 100644 index 0000000..b85b608 --- /dev/null +++ b/app/views/fetprofiles/_interninfo.html.erb @@ -0,0 +1,13 @@ +

+ Adresse: + <%= interninfo.plz %> + <%= interninfo.city %>, + <%= interninfo.street %> +

+

+ <%= raw("Telefon: ")+ interninfo.telnr + "
" unless interninfo.telnr.empty?%> + <%= raw("Handy: ") +interninfo.hdynr unless interninfo.hdynr.empty? %>
+<%= raw("Skype: ") +interninfo.skype unless interninfo.skype.empty? %>
+<%= raw("Instant Messaging: ") +interninfo.instant unless interninfo.instant.empty? %>
+ +

diff --git a/app/views/fetprofiles/_internrow.html.erb b/app/views/fetprofiles/_internrow.html.erb new file mode 100644 index 0000000..63fbb75 --- /dev/null +++ b/app/views/fetprofiles/_internrow.html.erb @@ -0,0 +1,12 @@ + + <%= link_to internrow.name, internrow %> + + <%= internrow.adress %> + + <%= raw("Telefon: ")+ internrow.telnr + "
" unless internrow.telnr.nil? || internrow.telnr.empty?%> + <%= raw("Handy: ") +internrow.hdynr + raw("
") unless internrow.hdynr.nil? || internrow.hdynr.empty? %> +<%= raw("Skype: ") +internrow.skype + raw("
") unless internrow.skype.nil? || internrow.skype.empty? %> +<%= raw("Instant Messaging: ") +internrow.instant + raw("
") unless internrow.instant.nil? || internrow.instant.empty? %> + +<%= internrow.fetmail %> + diff --git a/app/views/fetprofiles/internlist.html.erb b/app/views/fetprofiles/internlist.html.erb new file mode 100644 index 0000000..5d8f566 --- /dev/null +++ b/app/views/fetprofiles/internlist.html.erb @@ -0,0 +1,5 @@ + +<% @fetprofiles.each do |item| %> +<%= render partial: "internrow", object: item %> +<% end %> +
diff --git a/app/views/fetprofiles/show.html.erb b/app/views/fetprofiles/show.html.erb index ded2659..b62caae 100644 --- a/app/views/fetprofiles/show.html.erb +++ b/app/views/fetprofiles/show.html.erb @@ -10,10 +10,15 @@

<%= @fetprofile.fetmail %>

-

+ respond_to do |format| + format.html # index.html.erb + format.json { render json: @fetprofiles } + end + +

<%= @fetprofile.desc %>

- + <%= render partial: "interninfo", object: @fetprofile if can?(:seeintern, @fetprofile) %>