2011-05-18 02:00:00 +00:00
|
|
|
class PagePart
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
field :name
|
2012-07-25 21:07:32 +00:00
|
|
|
field :content, localize: true
|
2011-05-25 08:27:17 +00:00
|
|
|
field :kind
|
2012-02-16 04:16:27 +00:00
|
|
|
field :public_r_tag
|
2012-04-23 18:30:40 +00:00
|
|
|
field :public_r_tag_object_id, :default => nil
|
2012-05-08 20:15:45 +00:00
|
|
|
field :public_r_tag_option, :default => nil
|
2012-07-25 21:07:32 +00:00
|
|
|
field :page_title, localize: true
|
2012-02-16 04:16:27 +00:00
|
|
|
field :widget_path
|
2013-02-06 11:51:53 +00:00
|
|
|
field :category,type: Array, :default => []
|
|
|
|
field :tag, type: Array,:default => []
|
2012-08-09 07:25:30 +00:00
|
|
|
|
2012-07-16 08:13:38 +00:00
|
|
|
field :widget_style
|
2013-03-28 10:29:24 +00:00
|
|
|
field :widget_field , :type => Array,:default => []
|
|
|
|
|
|
|
|
field :widget_field_name , :type => Array,:default => []
|
|
|
|
field :widget_class , :type => Array,:default => []
|
|
|
|
field :widget_sat_to_link , :type => Array,:default => []
|
|
|
|
|
2012-12-28 07:30:46 +00:00
|
|
|
field :widget_options ,:type=>Hash
|
2012-07-16 08:13:38 +00:00
|
|
|
field :widget_data_count
|
2011-05-18 02:00:00 +00:00
|
|
|
|
|
|
|
belongs_to :page
|
2012-02-16 04:16:27 +00:00
|
|
|
belongs_to :module_app
|
2011-05-18 02:00:00 +00:00
|
|
|
|
2012-08-22 10:07:49 +00:00
|
|
|
before_save :delete_empty_widget_field
|
2012-12-19 09:15:31 +00:00
|
|
|
after_save :update_parent
|
2012-05-13 14:35:00 +00:00
|
|
|
|
2013-03-28 10:29:24 +00:00
|
|
|
def default_widget_field_sat_to_link?(i)
|
|
|
|
case widget_sat_to_link[i]
|
|
|
|
when 'true'
|
|
|
|
true
|
|
|
|
when 'false'
|
|
|
|
false
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_widget_field_name
|
|
|
|
return widget_field_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget_field=(settings)
|
|
|
|
settings.each_with_index do |setting,index|
|
|
|
|
self.widget_field_name[index] = setting["field_name"]
|
|
|
|
self.widget_class[index] = setting["class"]
|
|
|
|
self.widget_sat_to_link[index] = setting["sat_to_link"]
|
|
|
|
end
|
|
|
|
end
|
2012-12-28 07:30:46 +00:00
|
|
|
|
2012-05-13 14:35:00 +00:00
|
|
|
protected
|
|
|
|
|
2012-08-09 07:25:30 +00:00
|
|
|
def delete_empty_widget_field
|
2012-08-22 10:07:49 +00:00
|
|
|
if self.widget_field
|
|
|
|
self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
|
|
|
|
end
|
2012-08-09 07:25:30 +00:00
|
|
|
# self.widget_field.delete("") if self.widget_field
|
|
|
|
end
|
2012-05-13 14:35:00 +00:00
|
|
|
|
2012-12-19 09:15:31 +00:00
|
|
|
def update_parent
|
|
|
|
self.page.save
|
|
|
|
end
|
|
|
|
|
2011-05-18 02:00:00 +00:00
|
|
|
end
|