calentries -neuigkeiten calender fix

This commit is contained in:
Andreas Stephanides
2013-10-04 16:11:36 +02:00
parent 0fe92a4b48
commit 2e01fd574b
13 changed files with 63 additions and 28 deletions

View File

@@ -16,6 +16,8 @@ class NeuigkeitenController < ApplicationController
@toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions} @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 << {: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 << {: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 else
@toolbar_elements << {:text=>I18n.t('common.verwalten'),:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit,{:verwalten=>true}),:icon=>:pencil} if can? :verwalten, @neuigkeit @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 def add_calentry
@neuigkeit=Neuigkeit.find(params[:id]) @neuigkeit=Neuigkeit.find(params[:id])
if params[:calentry_id].nil? 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 else
ce=Calentry.find(params[:calentry_id]) ce=Calentry.find(params[:calentry_id])
end end
@calentry=ce @calentry=ce
ce.object=@neuigkeit ce.object=@neuigkeit
@neuigkeit.calentry=ce
@neuigkeit.save
render 'edit' render 'edit'
end end

View File

@@ -11,10 +11,13 @@
# #
class Calendar < ActiveRecord::Base class Calendar < ActiveRecord::Base
attr_accessible :name, :public, :picture attr_accessible :name, :public, :picture, :rubrik_id
has_and_belongs_to_many :calentries has_many :calentries
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
belongs_to :rubrik belongs_to :rubrik
validates :rubrik, :presence=>true
resourcify resourcify
scope :public, -> { where(:public => :true) } scope :public_cals, -> { where(:public => :true) }
end end

View File

@@ -13,8 +13,9 @@
# #
class Calentry < ActiveRecord::Base class Calentry < ActiveRecord::Base
attr_accessible :ende, :start, :summary, :typ,:calendar_ids attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar
has_and_belongs_to_many :calendars belongs_to :calendar
belongs_to :neuigkeit
validates :start, :presence => true validates :start, :presence => true
validates :typ, :presence => true validates :typ, :presence => true
before_save :get_public before_save :get_public
@@ -28,7 +29,7 @@ validate do |entry|
resourcify resourcify
def get_public 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 true
end end
def start_time def start_time

View File

@@ -15,7 +15,7 @@
# #
class Fetprofile < ActiveRecord::Base 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
has_many :memberships, dependent: :delete_all has_many :memberships, dependent: :delete_all
has_many :gremien, :through=> :membership has_many :gremien, :through=> :membership
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader

View File

@@ -14,18 +14,19 @@
class Neuigkeit < ActiveRecord::Base 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 :author, :class_name =>'User'
belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id" belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id"
validates :rubrik, :presence=>true validates :rubrik, :presence=>true
validates :author, :presence=>true validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
has_one :calentry, :as => :object has_one :calentry
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order} 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 :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)} scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)} scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
accepts_nested_attributes_for :calentry
def datum_nilsave def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum self.datum.nil? ? Time.now + 42.years : self.datum
end end

View File

@@ -11,7 +11,7 @@
# #
class Rubrik < ActiveRecord::Base class Rubrik < ActiveRecord::Base
attr_accessible :desc, :name, :prio attr_accessible :desc, :name, :prio, :calendar
has_many :neuigkeiten, :class_name => "Neuigkeit" has_many :neuigkeiten, :class_name => "Neuigkeit"
has_many :calentries, :through => :neuigkeiten, :as=>:object has_many :calentries, :through => :neuigkeiten, :as=>:object
resourcify resourcify

View File

@@ -3,6 +3,7 @@
<%= f.input :name %> <%= f.input :name %>
<%= f.input :public %> <%= f.input :public %>
<%= f.input :picture, :as => :file %> <%= f.input :picture, :as => :file %>
<%= f.input :rubrik %>
<% end %> <% end %>
<%= f.actions do %> <%= f.actions do %>

View File

@@ -31,10 +31,11 @@
<%= f.inputs :for => :memberships do |membership,i| %> <%= f.inputs :for => :memberships do |membership,i| %>
<div class="row-fluid"> <div class="row-fluid">
<div class="span1"></div> <div class="span1"></div>
<div class="span3"><%= membership.input :start, :as=>:datepicker %></div> <div class="span3"><%= membership.input :start, :as=>:datepicker, :prepend=>"von",:label=>false%></div>
<div class="span3"><%= membership.input :stop, :as=>:datepicker,:label=>false %></div> <div class="span3"><%= membership.input :stop, :as=>:datepicker,:label=>false, :prepend =>"bis" %></div>
<div class="span3"><%= membership. input :gremium %></div> <div class="span2"><%= membership.input :typ ,:as=>:select, :collection=>Membership::TYPEN.invert, :label=>false %></div>
<div class="span2"><%= membership.input :typ ,:as=>:radio, :collection=>Membership::TYPEN.invert %></div> <div class="span3"><%= membership.input :gremium, :label=>false %></div>
</div> </div>
<% end %> <% end %>
@@ -47,4 +48,7 @@
</div> </div>
</div> </div>
<% end %> <% end %>
<script>$('.datepicker').datepicker()</script>
</div> </div>

View File

@@ -1,19 +1,20 @@
<%= tinymce_assets %> <%= tinymce_assets %>
<%= semantic_form_for [@neuigkeit.rubrik,@neuigkeit] do |f| %> <%= semantic_form_for [@neuigkeit.rubrik,@neuigkeit] do |f| %>
<%= f.inputs do %> <%= f.inputs do %>
<%= f.input :title, :placeholder=>"Titel" %> <%= f.input :title, :placeholder=> "Titel" %>
<%= f.input :text, :as=>:tinymce_text %> <%= f.input :text, :as=> :tinymce_text %>
<% f.input :datum, :as=>:datepicker %> <% f.input :datum, :as=> :datepicker %>
<%= f.input :rubrik, :as=>:radio, :collection=>Rubrik.all %> <%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %>
<%= f.input :author, :as=>:radio %> <%= f.input :author, :as=> :radio %>
<%= f.input :picture, :as=>:file %> <%= f.input :picture, :as=> :file %>
<%= f.inputs :for => :calentry do |calentry| %> <% unless @neuigkeit.calentry.nil? %>
<%= calentry.input :start, :as =>:datepicker %> <%= f.inputs :for => :calentry do |calentry| %>
<%= calentry.input :ende, :as =>:datepicker %> <%= calentry.input :start, :as => :datepicker %>
<%= calentry.input :typ %> <%= calentry.input :ende , :as => :datepicker %>
<%= calentry.input :typ %>
<% end %>
<% end %>
<% end %> <% end %>
<% end %>
<%= f.actions do %> <%= f.actions do %>
<%= f.action :submit, :as => :input %> <%= f.action :submit, :as => :input %>
<% end %> <% end %>

View File

@@ -1,4 +1,4 @@
<h1><%=I18n.t("neuigkeit.new.title") %></h1> <h1><%= I18n.t("neuigkeit.new.title") %></h1>
<%= render 'form' %> <%= render 'form' %>

View File

@@ -0,0 +1,5 @@
class AddRubrikToCalendar < ActiveRecord::Migration
def change
add_column :calendars, :rubrik_id, :integer
end
end

View 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

View File

@@ -0,0 +1,5 @@
class AddNeuigkeitToCalentry < ActiveRecord::Migration
def change
add_column :calentries,:neuigkeit_id ,:integer
end
end