From 7c668809dcae5a6ff791fff5890ab5fd447cf68f Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 24 May 2015 13:43:37 +0200 Subject: [PATCH] neuigkeit no fallback for editor --- app/controllers/neuigkeiten_controller.rb | 2 +- app/models/neuigkeit.rb | 19 ++++++++++++++++++- app/views/neuigkeiten/_form.html.erb | 9 +++++++-- app/views/neuigkeiten/edit.html.erb | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 937aab4..2a8ade6 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -99,7 +99,7 @@ class NeuigkeitenController < ApplicationController end def edit @neuigkeit = Neuigkeit.find(params[:id]) - + @neuigkeit.no_fallbacks=true @calentries= @neuigkeit.calentries @calentries<< Calentry.new diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index c338d41..85a31a2 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -41,7 +41,24 @@ class Neuigkeit < ActiveRecord::Base accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?} before_validation :sanitize after_save :update_cache - + attr_accessor :no_fallbacks + def globalize_fallbacks(locale) + if self.no_fallbacks + [locale] + else + super + end + end + def read_attribute(name,options={}) + if translated?(name) + a=super(name,options) + a=self.translation_for(options[:locale] || I18n.locale).read_attribute(name) if self.no_fallbacks + + a + else + super(name) + end + end def picture_robust unless self.picture.url.nil? return self.picture diff --git a/app/views/neuigkeiten/_form.html.erb b/app/views/neuigkeiten/_form.html.erb index 76f452f..925415d 100755 --- a/app/views/neuigkeiten/_form.html.erb +++ b/app/views/neuigkeiten/_form.html.erb @@ -1,17 +1,22 @@ <%= tinymce_assets %> +<% trans = (@neuigkeit.translation.id.nil?) %> +<%= "Diese Neuigkeit ist noch nicht in " + I18n.locale.to_s + "vorhanden!" if trans %> + +
<%= semantic_form_for [@neuigkeit.rubrik,@neuigkeit] do |f| %> <%= f.inputs do %>
- <%= f.input :title, :placeholder=> "Titel" %> + + <%= f.input :title, :placeholder=> "Titel", :value=> @neuigkeit.translation.title.to_s %> <%= f.input :text, :as=> :tinymce_text %>
<% f.input :datum, :as=> :datepicker %> - <%= f.input :rubrik, :as=> :radio, :collection=>Rubrik.all %> + <%= f.input :rubrik, :as=> :select, :collection=>Rubrik.all %> <% f.input :flag_important %>
diff --git a/app/views/neuigkeiten/edit.html.erb b/app/views/neuigkeiten/edit.html.erb index 8c8b5a9..650341e 100755 --- a/app/views/neuigkeiten/edit.html.erb +++ b/app/views/neuigkeiten/edit.html.erb @@ -1,4 +1,4 @@

<%= I18n.t("neuigkeit.edit") %>

<%= %> -<%= render 'form' %> +<%= render 'form' , :locale=>:de %> <%= render 'layouts/pretty_toolbar' %>