57 lines
911 B
Ruby
57 lines
911 B
Ruby
# -*- encoding : utf-8 -*-
|
|
class BlockContent < ActiveRecord::Base
|
|
has_one :portlet, :as => :content, :dependent => :destroy
|
|
has_many :blocks, :as => :blockable #, :dependent => :destroy
|
|
|
|
validates :nbr_columns, :presence => true
|
|
|
|
STYLES = [["normal",1],["fond gris",2],["fond bleu",3]]
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|