Changes into page_part edition.
Can choose between 'text', 'public_r_tag' and 'widget'
This commit is contained in:
1 parent
7ea1745f73
commit
e0accbecaa
25 files changed
+119
-179
No files matched your search
@@ -1,7 +1,8 @@
|
||||
class Theme < Stylesheet
|
||||
embedded_in :design
|
||||
field :name
|
||||
|
||||
embedded_in :design
|
||||
|
||||
before_save :set_name
|
||||
|
||||
protected
|
||||
|
||||
+1
-22
@@ -5,7 +5,6 @@ class Item
|
||||
|
||||
field :name, :index => true
|
||||
field :full_name, :index => true
|
||||
field :i18n_variable_id, :type => BSON::ObjectId
|
||||
field :parent_id, :index => true
|
||||
field :parent_name
|
||||
field :position, :type => Integer
|
||||
@@ -17,15 +16,11 @@ class Item
|
||||
validates_presence_of :name, :full_name, :position, :is_published
|
||||
|
||||
belongs_to :parent, :class_name => "Item"
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :children, :class_name => "Item", :as => 'parent'
|
||||
|
||||
before_validation :setup_default_value
|
||||
|
||||
# Destroy the i18n_variable
|
||||
def destroy_i18n_variable
|
||||
self.i18n_variable.destroy rescue nil
|
||||
end
|
||||
|
||||
def self.find_by_name(item_name)
|
||||
Item.first(:conditions => { :name => item_name, :is_published => true })
|
||||
end
|
||||
@@ -37,22 +32,6 @@ class Item
|
||||
nodes.reverse
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr) rescue nil
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Build the url from the array of ancestors
|
||||
def url
|
||||
urls = ancestors.map{ |a| a.name } << self.name
|
||||
|
||||
@@ -10,7 +10,7 @@ class ModuleApp
|
||||
field :intro
|
||||
field :update_info
|
||||
field :create_date
|
||||
field :enable_frontend,type: Boolean
|
||||
field :enable_frontend, type: Boolean, :default => true
|
||||
|
||||
field :app_pages ,type: Array
|
||||
field :widgets ,type: Array
|
||||
@@ -19,6 +19,8 @@ class ModuleApp
|
||||
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
|
||||
|
||||
has_many :tags
|
||||
has_many :page_parts
|
||||
has_many :pages
|
||||
|
||||
has_one :app_auth,dependent: :delete
|
||||
|
||||
|
||||
+4
-11
@@ -5,23 +5,16 @@ class Page < Item
|
||||
field :theme_id, :type => BSON::ObjectId, :default => nil
|
||||
|
||||
belongs_to :design
|
||||
has_many :page_parts
|
||||
belongs_to :module_app
|
||||
has_many :page_parts, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
||||
|
||||
embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
|
||||
def create_parts
|
||||
page_design = self.design
|
||||
page_design.layout.layout_parts.each do |p|
|
||||
self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p.editable?
|
||||
end
|
||||
end
|
||||
|
||||
# Destroy the page_parts
|
||||
def destroy_page_parts
|
||||
self.page_parts.each do |part|
|
||||
part.destroy_i18n_variable
|
||||
part.destroy
|
||||
self.page_parts.create( :name => p.name, :i18n_variable => I18nVariable.create, :kind => 'text' ) if p.editable?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+6
-34
@@ -6,41 +6,13 @@ class PagePart
|
||||
field :name
|
||||
field :content
|
||||
field :kind
|
||||
field :i18n_variable_id, :type => BSON::ObjectId
|
||||
field :public_r_tag
|
||||
field :public_r_tag_object_id, :type => BSON::ObjectId, :default => nil
|
||||
field :widget_path
|
||||
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
belongs_to :page
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr)
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_i18n_variable
|
||||
self.i18n_variable.destroy rescue nil
|
||||
end
|
||||
|
||||
# Build the content from the i18n_variable
|
||||
def build_content(locales)
|
||||
res = ''
|
||||
res << "<r:multi_lang i18n_id='#{i18n_variable.id}'>"
|
||||
locales.each do |locale|
|
||||
res << "<r:lang name='#{locale.to_s}'>"
|
||||
res << i18n_variable[locale.to_s]
|
||||
res << "</r:lang>"
|
||||
end
|
||||
res << "</r:multi_lang>"
|
||||
self.content = res
|
||||
end
|
||||
belongs_to :module_app
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user