Class: HtmlGrid::List

Inherits:
Composite show all
Defined in:
lib/htmlgrid/list.rb

Direct Known Subclasses

FormList

Constant Summary collapse

BACKGROUND_ROW =
nil
BACKGROUND_SUFFIX =
'-bg'
CSS_HEAD_MAP =
{}
DEFAULT_CLASS =
Value
DEFAULT_HEAD_CLASS =
nil
EMPTY_LIST =
false
EMPTY_LIST_KEY =
:empty_list
OFFSET_STEP =
[0,1]
OMIT_HEADER =
false
OMIT_HEAD_TAG =
false
SORT_DEFAULT =
:to_s
SORT_HEADER =
true
SORT_REVERSE =
false
STRIPED_BG =
true

Constants inherited from Composite

Composite::COLSPAN_MAP, Composite::COMPONENT_CSS_MAP, Composite::CSS_MAP, Composite::VERTICAL

Constants inherited from AbstractComposite

AbstractComposite::CSS_CLASS, AbstractComposite::CSS_ID, AbstractComposite::CSS_ID_MAP, AbstractComposite::CSS_MAP, AbstractComposite::CSS_STYLE_MAP, AbstractComposite::LABELS, AbstractComposite::LEGACY_INTERFACE, AbstractComposite::LOOKANDFEEL_MAP, AbstractComposite::SYMBOL_MAP

Constants inherited from Component

Component::CSS_CLASS, Component::CSS_ID, Component::HTML_ATTRIBUTES, Component::HTTP_HEADERS, Component::LABEL

Instance Attribute Summary

Attributes inherited from Component

#attributes, #dojo_tooltip, #model, #value

Instance Method Summary collapse

Methods inherited from Composite

#compose_colspan, #event, #full_colspan, #insert_row, #to_html

Methods inherited from AbstractComposite

component, #create

Methods inherited from Component

#_to_html, #autofill?, #css_class, #css_class=, #css_id, #css_id=, #dojo_dynamic_html, #dojo_parse_on_load, #dojo_tag, #dojo_title=, #dynamic_html, #escape, #escape_symbols, #formname, #http_headers, #initialize, #label=, #label?, #onclick=, #onload=, #onsubmit=, #set_attribute, #tabindex=, #to_html

Constructor Details

This class inherits a constructor from HtmlGrid::Component

Instance Method Details

#compose(model = @model, offset = [0,0]) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# 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') ⇒ Object



60
61
62
# File 'lib/htmlgrid/list.rb', line 60

def compose_empty_list(offset, klass='list')
    fill_row(offset, self::class::EMPTY_LIST_KEY, klass)
end


58
59
# File 'lib/htmlgrid/list.rb', line 58

def compose_footer(offset=[0,0])
end

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/htmlgrid/list.rb', line 80

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]) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/htmlgrid/list.rb', line 63

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_mapObject



112
113
114
# File 'lib/htmlgrid/list.rb', line 112

def css_head_map
	@css_head_map ||= self::class::CSS_HEAD_MAP.dup
end

#fill_row(offset, key, klass) ⇒ Object



115
116
117
118
119
120
# File 'lib/htmlgrid/list.rb', line 115

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