orbit-basic/app/models/page.rb

45 lines
804 B
Ruby

class Page < Item
#include LayoutSupport
field :content
field :layout_name
field :layout_id
validates_presence_of :layout_name, :layout_id
referenced_in :layout
has_many :page_parts
def create_parts
page_layout = self.get_layout
page_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
end
end
def get_layout
Layout.find(layout_id)
end
protected
def setup_default_value
super
if self.layout_id
self.layout_name = get_layout.name
end
end
end