menu and section header progress

This commit is contained in:
2014-11-26 20:18:17 +01:00
parent a64d3de319
commit 60f014811c
38 changed files with 450 additions and 96 deletions
+27 -21
View File
@@ -7,9 +7,11 @@ class Product
property :code
property :price, type: Float
property :description
property :visible, type: :boolean, default: true
property :position, type: Fixnum
#belongs_to :product_category
has_and_belongs_to_many :product_categories, storing_keys: false
belongs_to :product_category
#has_and_belongs_to_many :product_categories, storing_keys: false
belongs_to :supplier # direct! category is an aid
has_many :product_orders
@@ -20,12 +22,16 @@ class Product
validates :price, presence: true, numericality: true
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
after_save :persist_product_category_ids
#after_save :persist_product_category_ids
def product_category_ids=(ids)
@product_category_ids = ids.select(&:present?)
is_dirty
end
#def product_category_ids=(ids)
#@product_category_ids = ids.select(&:present?)
#is_dirty
#end
#def product_category_id=(id)
#self.product_category_ids = [id]
#end
property :image_file_name
property :image_content_type
@@ -38,24 +44,24 @@ class Product
validates_attachment :image, content_type: {content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]}
private
#private
def persist_product_category_ids
return unless defined?(@product_category_ids) # Do not do anything if nothing happened to this attribute
@product_category_ids ||= []
existing_product_categories = product_categories
#def persist_product_category_ids
#return unless defined?(@product_category_ids) # Do not do anything if nothing happened to this attribute
#@product_category_ids ||= []
#existing_product_categories = product_categories
# do nothing if nothing has changed
return if @product_category_ids == existing_product_categories.map(&:id)
## do nothing if nothing has changed
#return if @product_category_ids == existing_product_categories.map(&:id)
# clear removed product categories
existing_product_categories.reject{|pc| @product_category_ids.include?(pc.id) }.each{|pc| pc.remove_product(self) }
## clear removed product categories
#existing_product_categories.reject{|pc| @product_category_ids.include?(pc.id) }.each{|pc| pc.remove_product(self) }
# Add product to newly added product categories
database.load(@product_category_ids - existing_product_categories.map(&:id)).each do |product_category|
product_category.add_product(self)
end
end
## Add product to newly added product categories
#database.load(@product_category_ids - existing_product_categories.map(&:id)).each do |product_category|
#product_category.add_product(self)
#end
#end
end