application_helper.rb 1.62 KB
module ApplicationHelper

  def display_base_errors resource
    return '' if (resource.errors.empty?) or (resource.errors[:base].empty?)
    messages = resource.errors[:base].map { |msg| content_tag(:p, msg) }.join
    html = <<-HTML
    <div class="alert alert-error alert-block">
      <button type="button" class="close" data-dismiss="alert">&#215;</button>
      #{messages}
    </div>
    HTML
    html.html_safe
  end

  def bootstrap_class_for(flash_type)
    case flash_type.to_s
      when "success"
        "alert-success"   # Green
      when "error"
        "alert-danger"    # Red
      when "alert"
        "alert-warning"   # Yellow
      when "notice"
        "alert-info"      # Blue
      else
        flash_type
    end
  end

  def request_status_label(request)
    classes = [ 'badge' ]

    status = request.status

    case status
      when 'created'
      when 'processing'
        classes << 'badge-warning'
      when 'error'
        classes << 'badge-important'
      when 'success'
        classes << 'badge-success'
    end

    content_tag(:a, t(status, scope: 'status'), :class => classes,
                :data => { 'toggle' => "tooltip" }, :title => request.response)
  end

  def custom_video_tag(video)
    html5_video_tag('/video.mp4', "#video_#{video.id}")
  end

  def html5_video_tag(url, id, classes = nil, *args)
    options = args.first || {}
    options[:id] = id
    options[:class] = "video-js vjs-default skin #{classes}"
    options[:controls] = 'controls'
    options[:preload] = 'auto'

    content_tag(:video, options) do
      content_tag(:source, '', :src => url, :type => 'video/mp4')
    end
  end

end