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

@@ -8,15 +8,17 @@ class NeuigkeitenController < ApplicationController
@neuigkeit.versions.reverse[params[:version].to_i].reify.save!
@neuigkeit=Neuigkeit.find(params[:id])
end
@calentries1=@neuigkeit.calentries
if params[:verwalten]
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>"Sure?" } if can? :publish, @neuigkeit
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>"Sure?" } if can? :unpublish, @neuigkeit
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>"Sure?" } if can?(:unpublish, @neuigkeit) && !@neuigkeit.published?
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
@versions= @neuigkeit.versions.select([:created_at]).reverse
@toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions}
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>"Sure?" } if can? :delete, @neuigkeit
@toolbar_elements << {:path=> add_calentry_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :text=>"Add Calentry", :icon=>:plus}
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>'Sure?' } if can? :delete, @neuigkeit
# @toolbar_elements << {:path=> add_calentry_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :text=>"Add Calentry", :icon=>:plus}
else
@toolbar_elements << {:text=>I18n.t('common.verwalten'),:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit,{:verwalten=>true}),:icon=>:pencil} if can? :verwalten, @neuigkeit
@@ -66,6 +68,9 @@ class NeuigkeitenController < ApplicationController
def edit
@neuigkeit = Neuigkeit.find(params[:id])
@toolbar_elements << {:text=>I18n.t('common.show'),:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit)} if can? :show, @neuigkeit
@calentries= @neuigkeit.calentries
@calentries<< Calentry.new
end
def create

View File

@@ -14,6 +14,12 @@ class RubrikenController < ApplicationController
else
@neuigkeiten = @rubrik.neuigkeiten.published
end
@toolbar_elements << {:text=>I18n.t('neuigkeit.new.title'),:path=> new_rubrik_neuigkeit_path(@rubrik),:hicon=>'icon-plus-sign'} if can? :verwalten, @rubrik
@toolbar_elements << {:text=>I18n.t('common.verwalten'),:path=>verwalten_rubrik_path(@rubrik),:icon=>:pencil} if can? :verwalten, @rubrik
end
def new
@@ -83,6 +89,9 @@ end
@neuigkeiten_unpublished = @rubrik.neuigkeiten.unpublished
@neuigkeiten_published=@rubrik.neuigkeiten.published
@moderatoren=User.with_role(:newsmoderator,@rubrik)
@toolbar_elements << {:text=>I18n.t('neuigkeit.new.title'),:path=> new_rubrik_neuigkeit_path(@rubrik),:hicon=>'icon-plus-sign'} if can? :verwalten, @rubrik
end
# Alle Rubriken verwalten und Sachen einstellen..

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?

View File

@@ -17,7 +17,7 @@
<span class="pull-left" >
<img class="media-object img-circle" src="<%= calendar.picture.thumb.url %>"/>
</span>
y<div class="media-body">
<div class="media-body">
<h4><%= calendar.name %></h4>
</div>
</div>

View File

@@ -24,7 +24,7 @@
</div>
<div class="row-fluid">
<%= calendar @calendar.calentries do |entry| %>
<div><%= link_to entry.name.to_s, entry %></div>
<div><%= link_to entry.name.to_s, polymorphic_path(entry.object) %></div>
<% end %>
</div>
<div class="row-fluid">

View File

@@ -1,5 +1,9 @@
<div class="contentbox">
<%= image_tag("/icon_kalender_small.png") %>
<%= link_to I18n.l(calentry.start) +" bis "+ I18n.l(calentry.ende), calendar_path(calentry.calendar) %>
<% if calentry.start.to_date == calentry.ende.to_date
format=:timeonly
else
format =:default
end%>
<%= link_to I18n.l(calentry.start) +" bis "+ I18n.l(calentry.ende,:format=>format), calendar_path(calentry.calendar) %>
</div>

View File

@@ -5,5 +5,5 @@
<div class="span4">
<%= f.input :start, :as => :datepicker %></div><div class="span4">
<%= f.input :dauer , :as => :string, :append=>"h" %></div><div class="span1">
<%= f.input :typ %></div> <div class="span1"><%= f.check_box :_destroy %></div>
<% f.input :typ %></div> <div class="span1"><%= f.check_box :_destroy %> <%= I18n.t 'common.delete' %></div>
</div>

View File

@@ -21,13 +21,13 @@
<%= f.input :picture, :as=> :file %>
</div> </div>
<% unless @neuigkeit.calentry.nil? %>
<%= f.inputs :for => :calentry do |calentry| %>
<%= f.semantic_fields_for :calentries , @calentries do |calentry| %>
<%= render 'calentries/nested_fields', :f => calentry %>
<% end %>
<% end %>
<% end %>
<%= f.actions do %>
<%= f.action :submit, :as => :input %>

View File

@@ -19,5 +19,7 @@
<p></p>
</div>
</div>
<%= render @neuigkeit.calentry unless @neuigkeit.calentry.nil? %>
<% @calentries1.each do |ce|%>
<%= render ce unless ce.nil? %>
<% end %>
<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>

View File

@@ -3,7 +3,9 @@
<%= f.input :name %>
<%= f.input :desc %>
<%= f.input :prio %>
<%= f.input :public %>
<%= f.input :public %>
<% end %>
<%= f.actions do %>

View File

@@ -25,10 +25,9 @@
<% end %>
<br>
<%= link_to 'Verwalten', verwalten_rubrik_path(@rubrik) %> |
<%= link_to '<i class="icon-plus-sign"></i>'.html_safe+"Neuer Artikel", new_rubrik_neuigkeit_path(@rubrik) %>
<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>
<%= toolbar_html(@toolbar_elements)%>

View File

@@ -194,4 +194,5 @@ de:
default: ! '%d.%m.%Y, %H:%M Uhr'
long: ! '%A, %d. %B %Y, %H:%M Uhr'
short: ! '%d.%m.%Y, %H:%M Uhr'
timeonly: ! '%H:%M Uhr'
pm: nachmittags

View File

@@ -2,8 +2,10 @@
de:
neuigkeit:
publish: "Neuigkeit veröffentlichen"
republish: "Neuigkeit erneut veröffentlichen"
unpublish: "Veröffentlichung rückgängig"
new:
title: "Neue Neuigkeit"
title: "Neuer Artikel"
rubriken:
alle: "Alle Rubriken"
rubrik:

View File

@@ -56,6 +56,7 @@
#resources :neuigkeiten, :except => [:index] do
#end
resources :neuigkeiten, :only =>[:show]
resources :rubriken do
collection do
get 'verwalten' , :action => :alle_verwalten