diff --git a/app/controllers/calentries_controller.rb b/app/controllers/calentries_controller.rb index 7e0c537..6b488e1 100644 --- a/app/controllers/calentries_controller.rb +++ b/app/controllers/calentries_controller.rb @@ -2,14 +2,14 @@ class CalentriesController < ApplicationController # GET /calentries # GET /calentries.json load_and_authorize_resource - def index - @calentries = Calentry.all + # def index + # @calentries = Calentry.all - respond_to do |format| - format.html # index.html.erb - format.json { render json: @calentries } - end - end + # respond_to do |format| + # format.html # index.html.erb + # format.json { render json: @calentries } + # end + # end # GET /calentries/1 # GET /calentries/1.json @@ -25,35 +25,36 @@ class CalentriesController < ApplicationController # GET /calentries/new # GET /calentries/new.json - def new - @calentry = Calentry.new + # def new + # @calentry = Calentry.new - respond_to do |format| - format.html # new.html.erb - format.json { render json: @calentry } - end - end + # respond_to do |format| + # format.html # new.html.erb + # format.json { render json: @calentry } + # end + # end # GET /calentries/1/edit - def edit - @calentry = Calentry.find(params[:id]) - end + #def edit + # @calentry = Calentry.find(params[:id]) + + # end # POST /calentries # POST /calentries.json - def create - @calentry = Calentry.new(params[:calentry]) + # def create + # @calentry = Calentry.new(params[:calentry]) - respond_to do |format| - if @calentry.save - format.html { redirect_to @calentry, notice: 'Calentry was successfully created.' } - format.json { render json: @calentry, status: :created, location: @calentry } - else - format.html { render action: "new" } - format.json { render json: @calentry.errors, status: :unprocessable_entity } - end - end - end +# respond_to do |format| +# if @calentry.save +# format.html { redirect_to @calentry, notice: 'Calentry was successfully created.' } +# format.json { render json: @calentry, status: :created, location: @calentry } +# else + # format.html { render action: "new" } +# format.json { render json: @calentry.errors, status: :unprocessable_entity } +# end +# end +# end # PUT /calentries/1 # PUT /calentries/1.json diff --git a/app/models/calentry.rb b/app/models/calentry.rb index e8f8ef4..9057992 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -15,8 +15,9 @@ class Calentry < ActiveRecord::Base attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar, :dauer belongs_to :calendar - belongs_to :neuigkeit + #belongs_to :neuigkeit validates :start, :presence => true + validates :object, :presence => true validates :typ, :presence => true before_save :get_public belongs_to :object, polymorphic: true # Objekt zu dem der Calentry gehört (derzeit ein Newsartikel) diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index e957fe1..d15cf71 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -20,13 +20,13 @@ class Neuigkeit < ActiveRecord::Base validates :rubrik, :presence=>true validates :author, :presence=>true translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true - has_one :calentry + has_one :calentry, 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 +accepts_nested_attributes_for :calentry, :allow_destroy=>true def datum_nilsave self.datum.nil? ? Time.now + 42.years : self.datum end @@ -39,6 +39,9 @@ accepts_nested_attributes_for :calentry def reverse_publish self.datum = nil end + def name +self.title +end def text_first_words md = /

(?[\w\s,\.!\?]*)/.match self.text md[:text].split(" ")[0..100].join(" ")+ " ..." diff --git a/app/views/calentries/_calentry.html.erb b/app/views/calentries/_calentry.html.erb new file mode 100644 index 0000000..37e4989 --- /dev/null +++ b/app/views/calentries/_calentry.html.erb @@ -0,0 +1,5 @@ +

+<%= image_tag("/icon_kalender_small.png") %> + +<%= link_to I18n.l(calentry.start) +" bis "+ I18n.l(calentry.ende), calendar_path(calentry.calendar) %> +
diff --git a/app/views/calentries/_nested_fields.html.erb b/app/views/calentries/_nested_fields.html.erb new file mode 100644 index 0000000..b678357 --- /dev/null +++ b/app/views/calentries/_nested_fields.html.erb @@ -0,0 +1,9 @@ +
+
+<%= image_tag("/icon_kalender_small.png") %> +
+
+ <%= f.input :start, :as => :datepicker %>
+ <%= f.input :dauer , :as => :string, :append=>"h" %>
+ <%= f.input :typ %>
<%= f.check_box :_destroy %>
+
diff --git a/app/views/neuigkeiten/_form.html.erb b/app/views/neuigkeiten/_form.html.erb index 3956dfd..879cd8d 100755 --- a/app/views/neuigkeiten/_form.html.erb +++ b/app/views/neuigkeiten/_form.html.erb @@ -1,17 +1,31 @@ <%= 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 :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.input :author, :as=> :select %> +
+
+
+ <%= f.input :picture, :as=> :file %> +
+ + <% unless @neuigkeit.calentry.nil? %> + + <%= f.inputs :for => :calentry do |calentry| %> - <%= calentry.input :start, :as => :datepicker %> - <%= calentry.input :dauer , :as => :string %> - <%= calentry.input :typ %> + <%= render 'calentries/nested_fields', :f => calentry %> <% end %> <% end %> <% end %> @@ -19,5 +33,6 @@ <%= f.action :submit, :as => :input %> <% end %> <% end %> +
<%= tinymce %> diff --git a/public/icon_kalender_small.png b/public/icon_kalender_small.png new file mode 100644 index 0000000..8314489 Binary files /dev/null and b/public/icon_kalender_small.png differ