2010-01-14 10:30:53 +00:00
|
|
|
class Page < Item
|
2010-01-04 07:52:30 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
field :content
|
2011-12-23 10:34:21 +00:00
|
|
|
field :app_frontend_url
|
2011-09-05 07:18:36 +00:00
|
|
|
field :theme_id, :type => BSON::ObjectId, :default => nil
|
2010-01-28 09:42:55 +00:00
|
|
|
|
2011-08-22 05:45:21 +00:00
|
|
|
belongs_to :design
|
2011-12-23 10:34:21 +00:00
|
|
|
belongs_to :module_app
|
2012-03-21 10:30:12 +00:00
|
|
|
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
2012-02-16 04:16:27 +00:00
|
|
|
has_many :page_parts, :autosave => true, :dependent => :destroy
|
2012-02-21 11:22:42 +00:00
|
|
|
has_many :page_contexts, :autosave => true, :dependent => :destroy
|
2012-03-21 10:30:12 +00:00
|
|
|
has_many :page_metas, :autosave => true, :dependent => :destroy
|
2012-02-16 04:16:27 +00:00
|
|
|
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
2010-01-28 09:42:55 +00:00
|
|
|
|
2012-03-21 10:30:12 +00:00
|
|
|
before_save :create_parts, :set_key
|
2012-02-16 11:14:16 +00:00
|
|
|
|
2012-02-16 04:16:27 +00:00
|
|
|
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
2011-10-18 03:21:24 +00:00
|
|
|
|
2012-02-16 11:14:16 +00:00
|
|
|
def is_home?
|
|
|
|
self.parent ? false : true
|
|
|
|
end
|
2012-03-21 10:30:12 +00:00
|
|
|
|
|
|
|
def title
|
|
|
|
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
|
|
|
|
end
|
2012-02-16 11:14:16 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-06-01 02:24:14 +00:00
|
|
|
def create_parts
|
2011-08-25 00:13:38 +00:00
|
|
|
page_design = self.design
|
2012-05-08 20:15:45 +00:00
|
|
|
parent = self.parent
|
|
|
|
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)}
|
2012-02-16 11:14:16 +00:00
|
|
|
page_design.layout.layout_parts.each do |layout_part|
|
2012-05-08 20:15:45 +00:00
|
|
|
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
|
|
|
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
|
|
|
if menu_part && current_part.name.eql?(menu_part.name)
|
|
|
|
if current_part.new_record?
|
|
|
|
current_part.kind = menu_part.kind
|
|
|
|
current_part.public_r_tag = menu_part.public_r_tag
|
|
|
|
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
|
|
|
|
else
|
|
|
|
current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id)
|
|
|
|
end
|
|
|
|
end
|
2011-06-01 04:00:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-21 10:30:12 +00:00
|
|
|
def set_key
|
2012-04-01 18:41:42 +00:00
|
|
|
if title && title.new_record?
|
2012-03-21 10:30:12 +00:00
|
|
|
title.key = 'title'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-01 07:58:42 +00:00
|
|
|
end
|