calentries -neuigkeiten calender fix
This commit is contained in:
@@ -16,6 +16,8 @@ class NeuigkeitenController < ApplicationController
|
||||
@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}
|
||||
|
||||
else
|
||||
@toolbar_elements << {:text=>I18n.t('common.verwalten'),:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit,{:verwalten=>true}),:icon=>:pencil} if can? :verwalten, @neuigkeit
|
||||
|
||||
@@ -30,12 +32,15 @@ class NeuigkeitenController < ApplicationController
|
||||
def add_calentry
|
||||
@neuigkeit=Neuigkeit.find(params[:id])
|
||||
if params[:calentry_id].nil?
|
||||
ce = Calentry.new
|
||||
ce = Calentry.new(:start=>Time.now, :ende=>1.hour.from_now, :typ=>1, :calendar=>@neuigkeit.rubrik.calendar)
|
||||
else
|
||||
ce=Calentry.find(params[:calentry_id])
|
||||
end
|
||||
@calentry=ce
|
||||
ce.object=@neuigkeit
|
||||
@neuigkeit.calentry=ce
|
||||
@neuigkeit.save
|
||||
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
|
||||
@@ -11,10 +11,13 @@
|
||||
#
|
||||
|
||||
class Calendar < ActiveRecord::Base
|
||||
attr_accessible :name, :public, :picture
|
||||
has_and_belongs_to_many :calentries
|
||||
attr_accessible :name, :public, :picture, :rubrik_id
|
||||
has_many :calentries
|
||||
mount_uploader :picture, PictureUploader
|
||||
belongs_to :rubrik
|
||||
validates :rubrik, :presence=>true
|
||||
|
||||
resourcify
|
||||
scope :public, -> { where(:public => :true) }
|
||||
scope :public_cals, -> { where(:public => :true) }
|
||||
|
||||
end
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#
|
||||
|
||||
class Calentry < ActiveRecord::Base
|
||||
attr_accessible :ende, :start, :summary, :typ,:calendar_ids
|
||||
has_and_belongs_to_many :calendars
|
||||
attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar
|
||||
belongs_to :calendar
|
||||
belongs_to :neuigkeit
|
||||
validates :start, :presence => true
|
||||
validates :typ, :presence => true
|
||||
before_save :get_public
|
||||
@@ -28,7 +29,7 @@ validate do |entry|
|
||||
|
||||
resourcify
|
||||
def get_public
|
||||
self.public = (self.try(:object).nil?)? (self.calendars.public.count>0) : object.try(:public)
|
||||
self.public = (self.try(:object).nil?)? (self.calendar.try(:public)) : object.try(:public)
|
||||
true
|
||||
end
|
||||
def start_time
|
||||
|
||||
@@ -14,18 +14,19 @@
|
||||
|
||||
class Neuigkeit < ActiveRecord::Base
|
||||
|
||||
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture
|
||||
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture, :calentry_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, :as => :object
|
||||
has_one :calentry
|
||||
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
|
||||
def datum_nilsave
|
||||
self.datum.nil? ? Time.now + 42.years : self.datum
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
|
||||
class Rubrik < ActiveRecord::Base
|
||||
attr_accessible :desc, :name, :prio
|
||||
attr_accessible :desc, :name, :prio, :calendar
|
||||
has_many :neuigkeiten, :class_name => "Neuigkeit"
|
||||
has_many :calentries, :through => :neuigkeiten, :as=>:object
|
||||
resourcify
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<%= f.input :name %>
|
||||
<%= f.input :public %>
|
||||
<%= f.input :picture, :as => :file %>
|
||||
<%= f.input :rubrik %>
|
||||
<% end %>
|
||||
|
||||
<%= f.actions do %>
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
<%= f.inputs :for => :memberships do |membership,i| %>
|
||||
<div class="row-fluid">
|
||||
<div class="span1"></div>
|
||||
<div class="span3"><%= membership.input :start, :as=>:datepicker %></div>
|
||||
<div class="span3"><%= membership.input :stop, :as=>:datepicker,:label=>false %></div>
|
||||
<div class="span3"><%= membership. input :gremium %></div>
|
||||
<div class="span2"><%= membership.input :typ ,:as=>:radio, :collection=>Membership::TYPEN.invert %></div>
|
||||
<div class="span3"><%= membership.input :start, :as=>:datepicker, :prepend=>"von",:label=>false%></div>
|
||||
<div class="span3"><%= membership.input :stop, :as=>:datepicker,:label=>false, :prepend =>"bis" %></div>
|
||||
<div class="span2"><%= membership.input :typ ,:as=>:select, :collection=>Membership::TYPEN.invert, :label=>false %></div>
|
||||
<div class="span3"><%= membership.input :gremium, :label=>false %></div>
|
||||
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -47,4 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<script>$('.datepicker').datepicker()</script>
|
||||
</div>
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
<%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %>
|
||||
<%= f.input :author, :as=> :radio %>
|
||||
<%= f.input :picture, :as=> :file %>
|
||||
<% unless @neuigkeit.calentry.nil? %>
|
||||
<%= f.inputs :for => :calentry do |calentry| %>
|
||||
<%= calentry.input :start, :as => :datepicker %>
|
||||
<%= calentry.input :ende , :as => :datepicker %>
|
||||
<%= calentry.input :typ %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
|
||||
5
db/migrate/20131003132456_add_rubrik_to_calendar.rb
Normal file
5
db/migrate/20131003132456_add_rubrik_to_calendar.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddRubrikToCalendar < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :calendars, :rubrik_id, :integer
|
||||
end
|
||||
end
|
||||
9
db/migrate/20131003133902_add_calendar_to_calentries.rb
Normal file
9
db/migrate/20131003133902_add_calendar_to_calentries.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class AddCalendarToCalentries < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :calentries, :calendar_id,:integer
|
||||
add_index :calentries, :calendar_id
|
||||
|
||||
drop_table :calendars_calentries
|
||||
|
||||
end
|
||||
end
|
||||
5
db/migrate/20131003140004_add_neuigkeit_to_calentry.rb
Normal file
5
db/migrate/20131003140004_add_neuigkeit_to_calentry.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddNeuigkeitToCalentry < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :calentries,:neuigkeit_id ,:integer
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user