orbit-basic/app/models/page_part.rb

45 lines
927 B
Ruby

class PagePart
include Mongoid::Document
include Mongoid::Timestamps
field :name
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
field :widget_style
field :widget_field , :type => Array
field :widget_options ,:type=>Hash
field :widget_data_count
belongs_to :page
belongs_to :module_app
before_save :delete_empty_widget_field
after_save :update_parent
def widget_options_uri
self.widget_options.map{|t| "#{t[0]}: #{t[1]}"}.join(',') rescue ''
end
protected
def delete_empty_widget_field
if self.widget_field
self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
end
# self.widget_field.delete("") if self.widget_field
end
def update_parent
self.page.save
end
end