# -*- encoding : utf-8 -*-
class ImgLinkContent < ApplicationRecord
  belongs_to :image_file

 belongs_to :item

  belongs_to :cible, :polymorphic => true

   has_one :portlet, :as => :content, :dependent => :destroy

  validates :title, :presence => true

  accepts_nested_attributes_for :cible, :reject_if => lambda { |a| 1 == 1 }

  before_validation do
    if !self.with_cible
      
      self.cible_type = nil
      self.cible_id = nil
    end
  end


  def url

    if self.cible
      cible.url
    else
      ""  
    end

  end

  STYLES = [["Style 1",1], ["Style 2",2]]
  
  def self.picto
    "cloud-download"
  end
end
