Now default tags can be removed from module

This commit is contained in:
chris committed 2013-04-25 19:20:37 +08:00
1 parent 19405cf006
commit 3714403f85
17 files changed
+248 -109

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ class ModuleApp
field :title
field :sidebar_order,type: Integer,default: 0
has_and_belongs_to_many :module_tags, dependent: :destroy
has_many :module_tags, dependent: :destroy
def refetch_setting!(reg)
# %w{module_label category base_url version organization author intro update_info create_date}.each do |field|
+27 -9
View File
@@ -3,20 +3,22 @@ class ModuleTag
include Mongoid::Timestamps
field :is_default, type: Boolean, default: false
field :name, localize: true
has_one :tag, as: :tag_lease, autosave: true
has_and_belongs_to_many :module_apps
belongs_to :module_app
after_initialize :init_tag
belongs_to :parent, :class_name => 'ModuleTag', :inverse_of => :children
has_many :children, :class_name => 'ModuleTag', :inverse_of => :parent, autosave: true, dependent: :destroy
validates :name, :at_least_one => true
before_save :init_update_tag
before_destroy :destroy_tag
private
after_save :update_children
def init_tag
if new_record?
self.build_tag(name_translations: self.name_translations, is_default: self.is_default)
end
end
private
def destroy_tag
Tag.without_callback(:destroy, :before, :destroy_module_tag) do
@@ -24,4 +26,20 @@ class ModuleTag
end
end
end
def init_update_tag
if self.new_record?
self.build_tag(name_translations: self.name_translations)
else
self.tag.name_translations = self.name_translations
end
end
def update_children
unless self.children.blank?
self.children.each do |child|
child.update_attributes(name_translations: self.name_translations)
end
end
end
end