class DesktopWidget
	include Mongoid::Document
  	include Mongoid::Timestamps
  	include ParserLayoutWidget

  	field :name
  	field :author
  	field :shape
  	field :version, :type => String

  has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
	has_one :widget_layout, :autosave => true, :dependent => :destroy
	has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
	has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
  has_and_belongs_to_many :desktops, :autosave => true
  belongs_to :tiles, :autosave => true
	
	accepts_nested_attributes_for :images, :allow_destroy => true
  accepts_nested_attributes_for :javascripts, :allow_destroy => true
	
	after_save :parse_css_for_images

  	# belongs_to :desktop


  	protected
  
 	def parse_css_for_images
	    self.css_default.parse_urls
	    parse_widget_for_images(self)
  	end

end