musifrat_app/app/models/block_content.rb
Nicolas Bally a1aef72f7f intial
2019-02-03 15:12:58 +01:00

63 lines
1.1 KiB
Ruby

# -*- encoding : utf-8 -*-
class BlockContent < ActiveRecord::Base
belongs_to :image_file
has_one :portlet, :as => :content, :dependent => :destroy
has_many :blocks, :as => :blockable, :dependent => :destroy
validates :nbr_columns, :presence => true
STYLES = [["normal",1],["Blanc encadré",2],["centré",3],["timeline",4],["centré sombre",5],["gris accueil",6]]
before_create do
self.row1 = self.row2 = self.row3 = self.row4 = 12/self.nbr_columns.to_i
end
def row1_value
self.row1.to_i
end
def row2_value
self.row1.to_i+self.row2.to_i
end
def row3_value
self.row1.to_i+self.row2.to_i+self.row3.to_i
end
def row4_value
self.row1.to_i+self.row2.to_i+self.row3.to_i+self.row4.to_i
end
def dup
@new = BlockContent.new(self.attributes)
@new.id = nil
@new.save
self.blocks.each do |block|
new_b = block.dup
new_b.blockable = @new
new_b.save
end
@new
end
def self.picto
"columns"
end
end