module Panel::Announcement::BackEnd::BulletinsHelper
  
  def show_approval_link(bulletin)
    by_bulletin = (!bulletin.is_expired? and bulletin.is_pending?)
    by_user = ((bulletin.bulletin_category.authed_users('fact_check').include?(current_user) rescue nil) or is_manager? or is_admin?)
    by_bulletin and  by_user
  end

  def show_delete_link(bulletin)
    by_bulletin = (bulletin.create_user_id == current_user.id)
    by_user = (is_manager? or is_admin?)
    by_bulletin or  by_user
  end

  def show_bulletin_title_at_index (bulletin)
    if bulletin.is_checked?
      link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''
    else
      bulletin.title[I18n.locale]
    end  
  end

  def file_picture_preview_setting(file_path)
    res= ""
    ext = File.extname(file_path)
    unless file_path.nil?
      case ext
        when ".jpg",".jpeg",".png",".gif"
          #res = '<div class="for_preview" style="display:none;">'
          #res << image_tag(file_path, {:title => t(:view)})
          #res << '</div>'
          #res.html_safe
          {"data-content" => "#{image_tag file_path}" }
        else
          {"data-content" => t("sys.not_previewable") }
      end
    end
  end

end