mehrere Termine je neuigkeit

This commit is contained in:
Andreas Stephanides
2013-11-13 12:50:04 +01:00
parent 0b6ed94662
commit e62f5a2600
18 changed files with 69 additions and 26 deletions

View File

@@ -67,7 +67,7 @@ class Ability
if user.has_role?("newsadmin") || user.has_role?("fetadmin")
can :addmoderator, Rubrik
end
can [:show, :index], [Rubrik,Neuigkeit], :public=>true
can [:show, :index], [Rubrik,Neuigkeit]
if user.has_role?("newsadmin") || user.has_role?( "fetadmin") || user.has_role?( "fetuser")
can :manage, Rubrik
can :manage, Neuigkeit

View File

@@ -15,7 +15,7 @@ class Calendar < ActiveRecord::Base
has_many :calentries
mount_uploader :picture, PictureUploader
belongs_to :rubrik
validates :rubrik, :presence=>true
# validates :rubrik, :presence=>true
resourcify
scope :public_cals, -> { where(:public => :true) }

View File

@@ -40,10 +40,15 @@ validate do |entry|
start.to_date
end
def dauer
(self.ende-self.start)/3600
if self.ende.nil? && self.start.nil?
0
else
self.ende = self.start unless self.start.nil?
(self.ende-self.start)/3600
end
end
def dauer=(dauer)
self.ende=self.start+dauer.to_i.hours
self.ende=self.start+dauer.to_i.hours
end
def name
unless self.object.nil?

View File

@@ -14,25 +14,30 @@
class Neuigkeit < ActiveRecord::Base
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture, :calentry_attributes
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture, :calentries_attributes
belongs_to :author, :class_name =>'User'
belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id"
validates :rubrik, :presence=>true
validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
has_one :calentry, inverse_of: :object
has_many :calentries, inverse_of: :object
mount_uploader :picture, PictureUploader
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order}
scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
accepts_nested_attributes_for :calentry, :allow_destroy=>true
accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
before_save :sanitize
def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum
end
def public
self.rubrik.public && self.datum_nilsave >=Time.now.to_date
end
def published?
self.datum_nilsave>=Time.now.to_date
end
def publish
self.datum = Date.today
end
@@ -46,4 +51,11 @@ end
md = /<p>(?<text>[\w\s,\.!\?]*)/.match self.text
md[:text].split(" ")[0..100].join(" ")+ " ..."
end
private
def sanitize
self.calentries.each do |calentry|
calentry.calendar= self.rubrik.calendar
calentry.typ=1
end
end
end

View File

@@ -16,6 +16,7 @@ class Rubrik < ActiveRecord::Base
has_many :calentries, :through => :neuigkeiten, :as=>:object
resourcify
has_one :calendar
validates :calender , :presence=>true
def moderator
u=User.with_role(:newsmoderator).first
if !u.nil?