72 lines
1.4 KiB
Ruby
72 lines
1.4 KiB
Ruby
class Design
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :title
|
|
field :author
|
|
field :intro
|
|
|
|
field :version
|
|
|
|
validates_presence_of :title
|
|
validates_presence_of :author
|
|
|
|
mount_uploader :layout, DesignFileUploader
|
|
|
|
embeds_many :stylesheets
|
|
embeds_many :javascripts
|
|
embeds_many :images
|
|
|
|
after_update :destroy_attrs
|
|
|
|
def javascripts=(*attrs)
|
|
self.attribute_models=(attrs<<'javascripts')
|
|
end
|
|
|
|
def stylesheets=(*attrs)
|
|
self.attribute_models=(attrs<<'stylesheets')
|
|
end
|
|
|
|
def images=(*attrs)
|
|
self.attribute_models=(attrs<<'images')
|
|
end
|
|
|
|
# Update or create the attribute_model records
|
|
def attribute_models=(attrs)
|
|
#attribute_models = eval(attributes[:type])
|
|
# if attributes.original_filename.blank?
|
|
attribute_models=eval(attrs.last)
|
|
a=attribute_models.build()
|
|
a.file=attrs[0]
|
|
# else
|
|
# attribute_model = attribute_models.detect {|a| a.id.to_s == attributes[:id].to_s }
|
|
# attribute_model.update_attributes(attributes)
|
|
#end
|
|
end
|
|
|
|
def is_built_in?
|
|
self.built_in
|
|
end
|
|
|
|
def is_disabled?
|
|
self.disabled
|
|
end
|
|
|
|
def get_enabled_attribute_models
|
|
self.attribute_models.excludes('disabled' => true)
|
|
end
|
|
|
|
protected
|
|
|
|
# Destroy the i18n_variable for each attribute_models if marked to destroy
|
|
def destroy_attrs
|
|
=begin
|
|
attribute_models.each do |a|
|
|
if a.should_destroy?
|
|
a.destroy_i18n_variable
|
|
end
|
|
end
|
|
=end
|
|
end
|
|
end
|