diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 9703e8d..1211e41 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -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 diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 2d817cb..e4bbad6 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -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 diff --git a/app/models/calentry.rb b/app/models/calentry.rb index 1b9f245..e0b5508 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -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 diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index 33a720d..2612509 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 has_many :memberships, dependent: :delete_all has_many :gremien, :through=> :membership mount_uploader :picture, PictureUploader diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index fbbca88..7cb661a 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -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 diff --git a/app/models/rubrik.rb b/app/models/rubrik.rb index a74198b..e69658a 100755 --- a/app/models/rubrik.rb +++ b/app/models/rubrik.rb @@ -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 diff --git a/app/views/calendars/_form.html.erb b/app/views/calendars/_form.html.erb index 139e9d8..c7c5cee 100644 --- a/app/views/calendars/_form.html.erb +++ b/app/views/calendars/_form.html.erb @@ -3,6 +3,7 @@ <%= f.input :name %> <%= f.input :public %> <%= f.input :picture, :as => :file %> + <%= f.input :rubrik %> <% end %> <%= f.actions do %> diff --git a/app/views/fetprofiles/_form.html.erb b/app/views/fetprofiles/_form.html.erb index 5a056df..d6d6efb 100644 --- a/app/views/fetprofiles/_form.html.erb +++ b/app/views/fetprofiles/_form.html.erb @@ -31,10 +31,11 @@ <%= f.inputs :for => :memberships do |membership,i| %>
-
<%= membership.input :start, :as=>:datepicker %>
-
<%= membership.input :stop, :as=>:datepicker,:label=>false %>
-
<%= membership. input :gremium %>
-
<%= membership.input :typ ,:as=>:radio, :collection=>Membership::TYPEN.invert %>
+
<%= membership.input :start, :as=>:datepicker, :prepend=>"von",:label=>false%>
+
<%= membership.input :stop, :as=>:datepicker,:label=>false, :prepend =>"bis" %>
+
<%= membership.input :typ ,:as=>:select, :collection=>Membership::TYPEN.invert, :label=>false %>
+
<%= membership.input :gremium, :label=>false %>
+
<% end %> @@ -47,4 +48,7 @@ <% end %> + + + diff --git a/app/views/neuigkeiten/_form.html.erb b/app/views/neuigkeiten/_form.html.erb index f190993..4e55f1d 100755 --- a/app/views/neuigkeiten/_form.html.erb +++ b/app/views/neuigkeiten/_form.html.erb @@ -1,19 +1,20 @@ <%= tinymce_assets %> <%= semantic_form_for [@neuigkeit.rubrik,@neuigkeit] do |f| %> <%= f.inputs do %> - <%= f.input :title, :placeholder=>"Titel" %> - <%= f.input :text, :as=>:tinymce_text %> - <% f.input :datum, :as=>:datepicker %> - <%= f.input :rubrik, :as=>:radio, :collection=>Rubrik.all %> - <%= f.input :author, :as=>:radio %> - <%= f.input :picture, :as=>:file %> - <%= f.inputs :for => :calentry do |calentry| %> - <%= calentry.input :start, :as =>:datepicker %> - <%= calentry.input :ende, :as =>:datepicker %> - <%= calentry.input :typ %> + <%= f.input :title, :placeholder=> "Titel" %> + <%= f.input :text, :as=> :tinymce_text %> + <% f.input :datum, :as=> :datepicker %> + <%= 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 %> - <% end %> - <%= f.actions do %> <%= f.action :submit, :as => :input %> <% end %> diff --git a/app/views/neuigkeiten/new.html.erb b/app/views/neuigkeiten/new.html.erb index cb7500e..05828da 100755 --- a/app/views/neuigkeiten/new.html.erb +++ b/app/views/neuigkeiten/new.html.erb @@ -1,4 +1,4 @@ -

<%=I18n.t("neuigkeit.new.title") %>

+

<%= I18n.t("neuigkeit.new.title") %>

<%= render 'form' %> diff --git a/db/migrate/20131003132456_add_rubrik_to_calendar.rb b/db/migrate/20131003132456_add_rubrik_to_calendar.rb new file mode 100644 index 0000000..7828739 --- /dev/null +++ b/db/migrate/20131003132456_add_rubrik_to_calendar.rb @@ -0,0 +1,5 @@ +class AddRubrikToCalendar < ActiveRecord::Migration + def change + add_column :calendars, :rubrik_id, :integer + end +end diff --git a/db/migrate/20131003133902_add_calendar_to_calentries.rb b/db/migrate/20131003133902_add_calendar_to_calentries.rb new file mode 100644 index 0000000..463ad1e --- /dev/null +++ b/db/migrate/20131003133902_add_calendar_to_calentries.rb @@ -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 diff --git a/db/migrate/20131003140004_add_neuigkeit_to_calentry.rb b/db/migrate/20131003140004_add_neuigkeit_to_calentry.rb new file mode 100644 index 0000000..8371a07 --- /dev/null +++ b/db/migrate/20131003140004_add_neuigkeit_to_calentry.rb @@ -0,0 +1,5 @@ +class AddNeuigkeitToCalentry < ActiveRecord::Migration + def change +add_column :calentries,:neuigkeit_id ,:integer + end +end