merge with november_presentation

This commit is contained in:
chris2tof committed 2011-12-22 15:43:38 +08:00
1 parent fa27bfc86b
commit d465febca7
27 files changed
+437 -6

No files matched your search

+33 -1
View File
@@ -24,6 +24,35 @@ class Design
after_save :procs_embedded_objects
# after_destroy :del_embedded_objects
# validate do
# errors.add('atttribute1', 'error for 1') if files_with_duplicate?
# errors.add('atttribute2', 'error for 1') if files_with_noname?
# end
def files_with_duplicate?
[self.javascripts, self.images,self.themes].each do |objects_hash|
ary = objects_hash.collect{ |k| k.file_filename}
ary.compact!
# debugger
return true if(ary.count!=ary.uniq.count)
end
false
end
def files_with_noname?
[self.javascripts, self.images,self.themes].each do |objects_hash|
objects_hash.each{ |k|
return true if(k.file_filename.nil? && !k.to_save?)
}
end
false
end
def new_files=(*attrs)
attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs
self.files=([items_ary, key])
end
end
def javascripts=(*attrs)
self.files = (attrs << 'javascripts')
end
@@ -45,6 +74,7 @@ class Design
files = eval(attrs.last)
end
attrs[0].each do |a|
if a[:id].blank? && !a[:file].blank?
files.build(:file => a[:file], :to_save => true)
else
@@ -86,12 +116,14 @@ class Design
end
end
end
self.valid?
end
def process_object(object)
if object.to_save
if object.file_filename.nil?
new_object = self.send(object._type.downcase.pluralize).build(object)
new_object = self.send(object._type.downcase.pluralize).build(object.attributes)
new_object.file = object.file
object.destroy
new_object.to_save = false
new_object.save