Module: ODDB::Html::View::OffsetHeader

Included in:
Drugs::ProductsList
Defined in:
lib/oddb/html/view/offset_header.rb

Instance Method Summary collapse

Instance Method Details

#compose_header(offset = [0,0]) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oddb/html/view/offset_header.rb', line 8

def compose_header(offset=[0,0])
  offset = super
  model = @session.state.model
  items = model.size
  step = @session.pagelength
  if(items > step)
    current_offset = @session.user_input(:offset).to_i
    0.step(items - 1, step) { |idx|
      link = HtmlGrid::Link.new(:page, @model, @session, self)
      link.value = sprintf("%i - %i", idx.next, 
                           [idx + step, items].min)
      unless(idx == current_offset)
        link.href = @lookandfeel._event_url(@session.event,
          [query_key, model.query, 'offset', idx])
      end
      @grid.add(link, *offset)
    }
    @grid.set_colspan(offset.at(0), offset.at(1), full_colspan)
    @grid.add_attribute('id', 'offsetheader', *offset)
    resolve_offset(offset, self::class::OFFSET_STEP)
  else
    offset
  end
end