class Interview::Grid

Attributes

object[R]
objects[RW]
sortable[RW]

Public Instance Methods

build(b) { || ... } click to toggle source
# File lib/interview/controls/grid.rb, line 7
def build(b)
  objects = @objects || find_attribute!(:objects)
  @object = find_attribute!(:object)
  
  sortable_id = "sortable_#{@object.class.model_name.plural}" if @sortable
  b.section style: 'table', html_class: 'table' do
    b.section style: 'thead' do
      b.section style: 'tr' do
        b.section style: 'th' if @sortable
        @build_captions = true
        b.meta_control pointer: self do
          yield if block_given?
        end
      end
    end
    html_opts = {}
    html_opts[:id] = sortable_id if @sortable
    b.section style: 'tbody', html_options: html_opts do
      objects.each do |object|
        @object = object
        html_opts = {}
        html_opts[:id] = "#{sortable_id}_#{object.id}" if @sortable
        b.section style: 'tr', htl_options: html_opts do
          if @sortable
            b.section style: 'td' do
              b.glyphicon style: 'resize-vertical', html_class: 'handle'
            end
          end
          @build_captions = false
          b.meta_control pointer: self do
            yield if block_given?
          end
        end
      end
    end  
  end
  if objects.empty?
    b.text text: "Keine #{@object.class.human_name(count: 2)} vorhanden.", style: 'p', 
           html_class: 'text-center text-muted'
  end
end
build_child(b, control, &block) click to toggle source
Calls superclass method Interview::Control#build_child
# File lib/interview/controls/grid.rb, line 49
def build_child(b, control, &block)
  if @build_captions
    b.section style: 'th' do
      control.build_caption(b)
    end
  else
    b.section style: 'td' do
      super
    end
  end
end