Remove i18n_variable for controllers, helpers and models

This commit is contained in:
Christophe Vilayphiou committed 2012-07-27 19:13:39 +08:00
1 parent 327996a7b0
commit 49dd3a1770
16 files changed
+196 -103

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ class Admin::AssetsController < OrbitBackendController
def create
@asset = Asset.new(params[:asset])
@asset.filename = @asset.title[I18n.locale] rescue nil
@asset.filename = @asset.title rescue nil
if @asset.filename && @asset.save
respond_to do |format|
format.js {
+1 -1
View File
@@ -3,7 +3,7 @@ module Admin::AssetHelper
def show_all_fields(asset, field)
a = []
@site_valid_locales.each do |locale|
a << asset.send(field)[locale] rescue nil
a << asset.send("#{field}_translations")[locale] rescue nil
end
a.join(' - ')
end
+1 -1
View File
@@ -13,7 +13,7 @@ module Admin::ItemHelper
ret << "<li id='#{node.id}' class='#{no_nested}'>"
# ret << "<i class='icons-moves'></i>"
ret << "<div class='with_action'><i class='icons-moves'></i>"
ret << (link_to node.i18n_variable[I18n.locale], dest, :class => 'js_history')
ret << (link_to node.title, dest, :class => 'js_history')
ret << "<div class='quick-edit hide'>"
ret << (link_to t('admin.edit'), eval("edit_admin_#{node._type.downcase}_path(node)"), :class => 'js_history') if node._type.eql?('Page')
ret << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page js_history') if node._type.eql?('Page')
+3 -3
View File
@@ -122,11 +122,11 @@ module ApplicationHelper
def page_title(page)
res = "<title>"
page_title = page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]
page_title = page.page_title ? page.page_title : page.title
if page.root? && @site.title
res << @site.title[I18n.locale]
res << @site.title
elsif @site.title && @site.title_always_on
res << @site.title[I18n.locale] + ' - ' + page_title
res << @site.title + ' - ' + page_title
else
res << page_title
end
+2 -2
View File
@@ -4,8 +4,8 @@ class AdImage
mount_uploader :file, ImageUploader
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :title, localize: true
field :context, localize: true
field :direct_to_after_click,type: Boolean
+2 -25
View File
@@ -6,10 +6,8 @@ class Asset
mount_uploader :data, FileAssetUploader
field :filename
field :description
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :description, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :description, localize: true
field :title, localize: true
validates_presence_of :title, :data, :description
@@ -17,29 +15,8 @@ class Asset
belongs_to :assetable, polymorphic: true
has_and_belongs_to_many :tags, :class_name => "AssetTag"
before_save :set_key
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def description
@description ||= I18nVariable.first(:conditions => {:key => 'description', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def sorted_tags
tags.order_by(I18n.locale, :asc)
end
protected
def set_key
if title && title.new_record?
title.key = 'title'
end
if description && description.new_record?
description.key = 'description'
end
end
end
+1 -2
View File
@@ -4,8 +4,7 @@ class AssetCategory
field :key
field :display
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
field :title, localize: true
has_many :assets
+1 -1
View File
@@ -10,8 +10,8 @@ class Item
field :is_published, :type => Boolean, :default => false
field :enabled_for, :type => Array, :default => nil
field :menu_enabled_for, :type => Array, :default => nil
field :title, localize: true
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
+2 -3
View File
@@ -4,16 +4,15 @@ class Meta
include Mongoid::Timestamps
field :key
field :title, localize: true
field :value, :default => nil
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
def get_name_content
[self.key, get_content]
end
def get_content
self.value ? self.value : self.i18n_variable[I18n.locale]
self.value ? self.value : self.title
end
end
+1 -11
View File
@@ -9,10 +9,10 @@ class Page < Item
field :category
field :tag
field :view_count, :type => Integer, :default => 0
field :page_title, localize: true
belongs_to :design
belongs_to :module_app
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_many :page_parts, :autosave => true, :dependent => :destroy
has_many :page_contexts, :autosave => true, :dependent => :destroy
has_many :page_metas, :autosave => true, :dependent => :destroy
@@ -21,10 +21,6 @@ class Page < Item
before_save :create_parts, :set_key
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
protected
@@ -47,10 +43,4 @@ class Page < Item
end
end
def set_key
if title && title.new_record?
title.key = 'title'
end
end
end
+2 -21
View File
@@ -4,34 +4,15 @@ class PagePart
include Mongoid::Timestamps
field :name
field :content
field :content, localize: true
field :kind
field :public_r_tag
field :public_r_tag_object_id, :default => nil
field :public_r_tag_option, :default => nil
field :page_title, localize: true
field :widget_path
has_one :i18n_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
belongs_to :page
belongs_to :module_app
before_save :set_key
def i18n_variable
@i18n_variable ||= I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
protected
def set_key
title.key = 'title' if title && (title.key.blank? rescue true)
i18n_variable.key = 'i18n_variable' if i18n_variable && (i18n_variable.key.blank? rescue true)
end
end
+4 -25
View File
@@ -20,12 +20,11 @@ class Site
field :search,:type => Hash
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :footer, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :sub_menu, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_many :site_metas, :autosave => true, :dependent => :destroy
field :title, localize: true
field :footer, localize: true
field :sub_menu, localize: true
before_save :set_key
has_many :site_metas, :autosave => true, :dependent => :destroy
def generate_keys
private_key = OpenSSL::PKey::RSA.generate(2048)
@@ -42,18 +41,6 @@ class Site
res.eql?('local out of date') ? false : true
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def footer
@footer ||= I18nVariable.first(:conditions => {:key => 'footer', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def sub_menu
@sub_menu ||= I18nVariable.first(:conditions => {:key => 'sub_menu', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
METAS.each do |meta|
define_method meta do
fetch_meta = self.site_metas.where(key: meta).limit(1)
@@ -68,13 +55,5 @@ class Site
end
end
end
protected
def set_key
title.key = 'title' if title && (title.key.blank? rescue true)
footer.key = 'footer' if footer && (footer.key.blank? rescue true)
sub_menu.key = 'sub_menu' if sub_menu && (sub_menu.key.blank? rescue true)
end
end
+1 -1
View File
@@ -6,9 +6,9 @@ class Attribute
field :key
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
has_many :attribute_fields, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
def is_built_in?
+1 -1
View File
@@ -9,9 +9,9 @@ class AttributeField
field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
belongs_to :attribute
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :attribute_values
# validates_uniqueness_of :key
+1 -1
View File
@@ -6,9 +6,9 @@ class Role
field :key
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
has_many :sub_roles, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :users
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
accepts_nested_attributes_for :sub_roles, :allow_destroy => true