class HtmlGrid::List
Constants
- BACKGROUND_ROW
- BACKGROUND_SUFFIX
- CSS_HEAD_MAP
- DEFAULT_CLASS
- DEFAULT_HEAD_CLASS
- EMPTY_LIST
- EMPTY_LIST_KEY
- OFFSET_STEP
- OMIT_HEADER
- OMIT_HEAD_TAG
- SORT_DEFAULT
- SORT_HEADER
- SORT_REVERSE
- STRIPED_BG
Public Instance Methods
compose(model = @model, offset = [0, 0])
click to toggle source
# File lib/htmlgrid/list.rb, line 47 def compose(model = @model, offset = [0, 0]) unless self.class::OMIT_HEADER offset = compose_header(offset) end if model.empty? offset = compose_empty_list(offset) unless self.class::EMPTY_LIST else offset = compose_list(model, offset) end compose_footer(offset) end
compose_empty_list(offset, klass = "list")
click to toggle source
# File lib/htmlgrid/list.rb, line 62 def compose_empty_list(offset, klass = "list") fill_row(offset, self.class::EMPTY_LIST_KEY, klass) end
compose_header(offset = [0, 0])
click to toggle source
# File lib/htmlgrid/list.rb, line 84 def compose_header(offset = [0, 0]) step = if defined?(self.class::HEAD_OFFSET_STEP) self.class::HEAD_OFFSET_STEP else self.class::OFFSET_STEP end ystep = step.at(1) components.each { |matrix, component| key = lookandfeel_key(component) header_key = "th_" << key.to_s if (txt = @lookandfeel.lookup(header_key)) if self.class::SORT_HEADER @grid.add(sort_link(header_key, matrix, component), *matrix) else @grid.add(txt, *matrix) end end if (cls = css_head_map[matrix]) \ || (cls = self.class::DEFAULT_HEAD_CLASS) @grid.add_attribute("class", cls, *matrix) # link.attributes['class'] = cls end unless self.class::OMIT_HEAD_TAG || matrix.at(1) >= ystep @grid.add_tag("TH", *matrix) end if (title = @lookandfeel.lookup(header_key + "_title")) @grid.add_attribute("title", title, *matrix) end } # span = full_colspan || 1 resolve_offset(offset, step) end
compose_list(model = @model, offset = [0, 0])
click to toggle source
# File lib/htmlgrid/list.rb, line 66 def compose_list(model = @model, offset = [0, 0]) bg_flag = false model.each_with_index { |mdl, idx| @list_index = idx _compose(mdl, offset, bg_flag) # compose_components(mdl, offset) # compose_css(offset, resolve_suffix(mdl, bg_flag)) # compose_colspan(offset) if (rcss = row_css(mdl, bg_flag)) @grid.set_row_attributes({"class" => rcss}, offset.at(1), self.class::OFFSET_STEP.at(1)) end offset = resolve_offset(offset, self.class::OFFSET_STEP) bg_flag = !bg_flag if self.class::STRIPED_BG } offset end
css_head_map()
click to toggle source
# File lib/htmlgrid/list.rb, line 117 def css_head_map @css_head_map ||= self.class::CSS_HEAD_MAP.dup end
fill_row(offset, key, klass)
click to toggle source
# File lib/htmlgrid/list.rb, line 121 def fill_row(offset, key, klass) @grid.add(@lookandfeel.lookup(key), *offset) @grid.add_attribute("class", klass, *offset) @grid.set_colspan(*offset) resolve_offset(offset, self.class::OFFSET_STEP) end
Private Instance Methods
init()
click to toggle source
Calls superclass method
HtmlGrid::AbstractComposite#init
# File lib/htmlgrid/list.rb, line 130 def init @model ||= [] @index = 0 sort_model if self.class::SORT_REVERSE && (@session.event != :sort) @model = @model.reverse end super end
row_css(model, bg_flag)
click to toggle source
# File lib/htmlgrid/list.rb, line 140 def row_css(model, bg_flag) self.class::BACKGROUND_ROW if bg_flag end
sort_link(header_key, matrix, component)
click to toggle source
# File lib/htmlgrid/list.rb, line 144 def sort_link(header_key, matrix, component) link = Link.new(header_key, @model, @session, self) args = { "sortvalue" => component.to_s } link.attributes["href"] = @lookandfeel.event_url(:sort, args) if (cls = css_head_map[matrix]) \ || (cls = self.class::DEFAULT_HEAD_CLASS) link.attributes["class"] = cls end link end
sort_model()
click to toggle source
# File lib/htmlgrid/list.rb, line 157 def sort_model block = self.class::SORT_DEFAULT if block && (@session.event != :sort) begin if block == :self @model = @model.sort else unless block.is_a?(Proc) block = proc { |item| begin item.send(self.class::SORT_DEFAULT) rescue RuntimeError item.to_s end } end @model = @model.sort_by(&block) end rescue => e puts "could not sort: #{e.message}" end end end