htmlgrid 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/History.txt +6 -0
  2. data/LICENCE.txt +515 -0
  3. data/Manifest.txt +82 -0
  4. data/README.txt +30 -0
  5. data/Rakefile +28 -0
  6. data/ext/htmlgrid/MANIFEST +3 -0
  7. data/ext/htmlgrid/Makefile +150 -0
  8. data/ext/htmlgrid/extconf.rb +33 -0
  9. data/ext/htmlgrid/grid.c +881 -0
  10. data/ext/htmlgrid/grid.o +0 -0
  11. data/ext/htmlgrid/htmlgrid.c +30 -0
  12. data/ext/htmlgrid/htmlgrid.o +0 -0
  13. data/ext/htmlgrid/htmlgrid.so +0 -0
  14. data/ext/htmlgrid/include/grid.h +79 -0
  15. data/ext/htmlgrid/include/htmlgrid.h +33 -0
  16. data/install.rb +1098 -0
  17. data/lib/htmlgrid/booleanvalue.rb +41 -0
  18. data/lib/htmlgrid/button.rb +36 -0
  19. data/lib/htmlgrid/centeredcomposite.rb +47 -0
  20. data/lib/htmlgrid/component.rb +232 -0
  21. data/lib/htmlgrid/composite.rb +350 -0
  22. data/lib/htmlgrid/datevalue.rb +39 -0
  23. data/lib/htmlgrid/div.rb +37 -0
  24. data/lib/htmlgrid/divcomposite.rb +52 -0
  25. data/lib/htmlgrid/divform.rb +35 -0
  26. data/lib/htmlgrid/divlist.rb +26 -0
  27. data/lib/htmlgrid/divtemplate.rb +12 -0
  28. data/lib/htmlgrid/dojotoolkit.rb +173 -0
  29. data/lib/htmlgrid/errormessage.rb +70 -0
  30. data/lib/htmlgrid/form.rb +93 -0
  31. data/lib/htmlgrid/formlist.rb +42 -0
  32. data/lib/htmlgrid/grid.rb +286 -0
  33. data/lib/htmlgrid/image.rb +43 -0
  34. data/lib/htmlgrid/infomessage.rb +41 -0
  35. data/lib/htmlgrid/input.rb +59 -0
  36. data/lib/htmlgrid/inputcheckbox.rb +41 -0
  37. data/lib/htmlgrid/inputcurrency.rb +36 -0
  38. data/lib/htmlgrid/inputdate.rb +38 -0
  39. data/lib/htmlgrid/inputfile.rb +40 -0
  40. data/lib/htmlgrid/inputradio.rb +37 -0
  41. data/lib/htmlgrid/inputtext.rb +37 -0
  42. data/lib/htmlgrid/javascript.rb +22 -0
  43. data/lib/htmlgrid/label.rb +90 -0
  44. data/lib/htmlgrid/labeltext.rb +35 -0
  45. data/lib/htmlgrid/link.rb +54 -0
  46. data/lib/htmlgrid/list.rb +170 -0
  47. data/lib/htmlgrid/namedcomponent.rb +52 -0
  48. data/lib/htmlgrid/pass.rb +38 -0
  49. data/lib/htmlgrid/passthru.rb +44 -0
  50. data/lib/htmlgrid/popuplink.rb +66 -0
  51. data/lib/htmlgrid/reset.rb +36 -0
  52. data/lib/htmlgrid/richtext.rb +26 -0
  53. data/lib/htmlgrid/select.rb +53 -0
  54. data/lib/htmlgrid/span.rb +37 -0
  55. data/lib/htmlgrid/spancomposite.rb +45 -0
  56. data/lib/htmlgrid/spanlist.rb +15 -0
  57. data/lib/htmlgrid/staticinput.rb +40 -0
  58. data/lib/htmlgrid/submit.rb +36 -0
  59. data/lib/htmlgrid/template.rb +130 -0
  60. data/lib/htmlgrid/text.rb +36 -0
  61. data/lib/htmlgrid/textarea.rb +49 -0
  62. data/lib/htmlgrid/ulcomposite.rb +49 -0
  63. data/lib/htmlgrid/ullist.rb +15 -0
  64. data/lib/htmlgrid/urllink.rb +65 -0
  65. data/lib/htmlgrid/value.rb +36 -0
  66. data/test/rebuild.rb +39 -0
  67. data/test/stub/cgi.rb +44 -0
  68. data/test/suite.rb +32 -0
  69. data/test/test_component.rb +138 -0
  70. data/test/test_composite.rb +201 -0
  71. data/test/test_datevalue.rb +60 -0
  72. data/test/test_form.rb +123 -0
  73. data/test/test_formlist.rb +111 -0
  74. data/test/test_grid.rb +395 -0
  75. data/test/test_input.rb +70 -0
  76. data/test/test_label.rb +116 -0
  77. data/test/test_list.rb +146 -0
  78. data/test/test_select.rb +78 -0
  79. data/test/test_template.rb +97 -0
  80. data/test/test_text.rb +63 -0
  81. data/usage-en.txt +112 -0
  82. data/widget/Tooltip.js +85 -0
  83. metadata +180 -0
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
5
+ # Copyright (C) 2003 ywesee - intellectual capital connected
6
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
7
+ #
8
+ # This library is free software; you can redistribute it and/or
9
+ # modify it under the terms of the GNU Lesser General Public
10
+ # License as published by the Free Software Foundation; either
11
+ # version 2.1 of the License, or (at your option) any later version.
12
+ #
13
+ # This library is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public
19
+ # License along with this library; if not, write to the Free Software
20
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ #
22
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
+ # htmlgrid@ywesee.com, www.ywesee.com
24
+ #
25
+ # BooleanValue -- oddb -- 28.07.2003 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/namedcomponent'
28
+
29
+ module HtmlGrid
30
+ class BooleanValue < NamedComponent
31
+ LABEL = true
32
+ def init
33
+ bool = if(@model.respond_to?(@name) && @model.send(@name))
34
+ :true
35
+ else
36
+ :false
37
+ end
38
+ @value = @lookandfeel.lookup(bool)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
5
+ # Copyright (C) 2003 ywesee - intellectual capital connected
6
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
7
+ #
8
+ # This library is free software; you can redistribute it and/or
9
+ # modify it under the terms of the GNU Lesser General Public
10
+ # License as published by the Free Software Foundation; either
11
+ # version 2.1 of the License, or (at your option) any later version.
12
+ #
13
+ # This library is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public
19
+ # License along with this library; if not, write to the Free Software
20
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ #
22
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
+ #
25
+ # Button -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/staticinput'
28
+
29
+ module HtmlGrid
30
+ class Button < StaticInput
31
+ def init
32
+ super
33
+ @attributes['type'] = 'button'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
5
+ # Copyright (C) 2003 ywesee - intellectual capital connected
6
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
7
+ #
8
+ # This library is free software; you can redistribute it and/or
9
+ # modify it under the terms of the GNU Lesser General Public
10
+ # License as published by the Free Software Foundation; either
11
+ # version 2.1 of the License, or (at your option) any later version.
12
+ #
13
+ # This library is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public
19
+ # License along with this library; if not, write to the Free Software
20
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ #
22
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
+ #
25
+ # CenteredComposite -- htmlgrid -- 7.1.2003 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/composite'
28
+
29
+ module HtmlGrid
30
+ class CenteredComposite < Composite
31
+ TABLE_ATTRIBUTES = {
32
+ "style" => "margin-left:auto;margin-right:auto;text-align:left",
33
+ }
34
+ DIV_ATTRIBUTES = {
35
+ "style" => "text-align:center;margin-left:auto;margin-right:auto;text-align:left",
36
+ }
37
+ def to_html(context)
38
+ context.div(self::class::DIV_ATTRIBUTES) {
39
+ super
40
+ }
41
+ end
42
+ def init
43
+ super
44
+ @attributes.update(self::class::TABLE_ATTRIBUTES)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #--
4
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
5
+ # Copyright (C) 2003 ywesee - intellectual capital connected
6
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
7
+ #
8
+ # This library is free software; you can redistribute it and/or
9
+ # modify it under the terms of the GNU Lesser General Public
10
+ # License as published by the Free Software Foundation; either
11
+ # version 2.1 of the License, or (at your option) any later version.
12
+ #
13
+ # This library is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public
19
+ # License along with this library; if not, write to the Free Software
20
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ #
22
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
+ #
25
+ # Component -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
26
+ #++
27
+
28
+ module HtmlGrid
29
+ class Component
30
+ # sets the 'class' html-attribute
31
+ CSS_CLASS = nil
32
+ # sets the 'id' html-attribute
33
+ CSS_ID = nil
34
+ # other html-attributes
35
+ HTML_ATTRIBUTES = {}
36
+ # default http-headers
37
+ HTTP_HEADERS = {
38
+ "Content-Type" => "text/html",
39
+ "Cache-Control" => "no-cache, max-age=3600, must-revalidate",
40
+ }
41
+ # precede instances of this class with a label?
42
+ LABEL = false
43
+ @@html_entities = [
44
+ ['&', 'amp'],
45
+ ['<', 'lt'],
46
+ ['>', 'gt'],
47
+ ] # :nodoc:
48
+ @@symbol_entities = {
49
+ 34 => "forall",
50
+ 36 => "exist",
51
+ 42 => "lowast",
52
+ 45 => "minus",
53
+ 64 => "cong",
54
+ 65 => "Alpha", 97 => "alpha",
55
+ 66 => "Beta", 98 => "beta",
56
+ 67 => "Chi", 99 => "chi",
57
+ 68 => "Delta", 100 => "delta",
58
+ 69 => "Epsilon", 101 => "epsilon",
59
+ 70 => "Phi", 102 => "phi",
60
+ 71 => "Gamma", 103 => "gamma",
61
+ 72 => "Eta", 104 => "eta",
62
+ 73 => "Iota", 105 => "iota",
63
+ 75 => "Kappa", 107 => "kappa",
64
+ 76 => "Lambda", 108 => "lambda",
65
+ 77 => "Mu", 109 => "mu",
66
+ 78 => "Nu", 110 => "nu",
67
+ 79 => "Omicron", 111 => "omicron",
68
+ 80 => "Pi", 112 => "pi",
69
+ 81 => "Theta", 113 => "theta",
70
+ 82 => "Rho", 114 => "rho",
71
+ 83 => "Sigma", 115 => "sigma",
72
+ 84 => "Tau", 116 => "tau",
73
+ 85 => "Upsilon", 117 => "upsilon",
74
+ 86 => "sigmaf",
75
+ 87 => "Omega", 119 => "omega",
76
+ 88 => "Xi", 120 => "xi",
77
+ 89 => "Psi", 121 => "psi",
78
+ 90 => "Zeta", 122 => "zeta",
79
+ 94 => "perp", 126 => "sim",
80
+ 163 => "le",
81
+ 165 => "infin",
82
+ 166 => "fnof",
83
+ 171 => "harr",
84
+ 172 => "larr",
85
+ 173 => "uarr",
86
+ 174 => "rarr",
87
+ 175 => "darr",
88
+ 179 => "ge",
89
+ 181 => "prop",
90
+ 182 => "part",
91
+ 185 => "ne",
92
+ 186 => "equiv",
93
+ 187 => "asymp",
94
+ 191 => "crarr",
95
+ 196 => "otimes",
96
+ 197 => "oplus",
97
+ 198 => "empty",
98
+ 199 => "cap",
99
+ 200 => "cup",
100
+ 201 => "sup",
101
+ 202 => "supe",
102
+ 203 => "nsub",
103
+ 204 => "sub",
104
+ 205 => "sube",
105
+ 206 => "isin",
106
+ 207 => "notin",
107
+ 208 => "ang",
108
+ 209 => "nabla",
109
+ 213 => "prod",
110
+ 214 => "radic",
111
+ 215 => "sdot",
112
+ 217 => "and",
113
+ 218 => "or",
114
+ 219 => "hArr",
115
+ 220 => "lArr",
116
+ 221 => "uArr",
117
+ 222 => "rArr",
118
+ 223 => "dArr",
119
+ 229 => "sum",
120
+ 242 => "int",
121
+ } # :nodoc:
122
+ attr_reader :attributes, :model
123
+ attr_accessor :value
124
+ def initialize(model, session=nil, container=nil)
125
+ @model = model
126
+ @session = session
127
+ @lookandfeel = session.lookandfeel if session.respond_to?(:lookandfeel)
128
+ @container = container
129
+ @attributes = self::class::HTML_ATTRIBUTES.dup
130
+ if(css_class())
131
+ @attributes.store("class", css_class())
132
+ end
133
+ if(css_id())
134
+ @attributes.store("id", css_id())
135
+ end
136
+ @value = nil
137
+ @label = self::class::LABEL
138
+ init()
139
+ end
140
+ # delegator to @container, default definition in Form
141
+ def autofill?
142
+ @container.autofill? if @container.respond_to?(:autofill?)
143
+ end
144
+ # gets the 'class' html-attribute if defined
145
+ def css_class
146
+ @css_class ||= self::class::CSS_CLASS
147
+ end
148
+ # sets the 'class' html-attribute
149
+ def css_class=(css_class)
150
+ @css_class = @attributes['class'] = css_class
151
+ end
152
+ # gets the 'id' html-attribute if defined
153
+ def css_id
154
+ @css_id ||= self::class::CSS_ID
155
+ end
156
+ # sets the 'id' html-attribute
157
+ def css_id=(css_id)
158
+ @css_id = @attributes['id'] = css_id
159
+ end
160
+ def dynamic_html(context)
161
+ ''
162
+ end
163
+ # escape '&', '<' and '>' characters in txt
164
+ def escape(txt)
165
+ @@html_entities.inject(txt.to_s.dup) { |str, map|
166
+ char, entity = map
167
+ str.gsub!(char, '&' << entity << ';')
168
+ str
169
+ }
170
+ end
171
+ # escape symbol-font strings
172
+ def escape_symbols(txt)
173
+ esc = ''
174
+ txt.to_s.each_byte { |byte|
175
+ esc << if(entity = @@symbol_entities[byte])
176
+ '&' << entity << ';'
177
+ else
178
+ byte.chr
179
+ end
180
+ }
181
+ esc
182
+ end
183
+ # delegator to @container, default definition in Form
184
+ def formname
185
+ @container.formname if @container.respond_to?(:formname)
186
+ end
187
+ def http_headers
188
+ self::class::HTTP_HEADERS.dup
189
+ end
190
+ # precede this instance with a label?
191
+ def label?
192
+ @label
193
+ end
194
+ def label=(boolean)
195
+ @label = boolean
196
+ end
197
+ def onclick=(onclick)
198
+ @attributes['onclick'] = onclick
199
+ end
200
+ # delegator to @container, default definition in Template
201
+ def onload=(onload)
202
+ @container.onload = onload if(@container.respond_to? :onload=)
203
+ end
204
+ # delegator to @container, default definition in Form
205
+ def onsubmit=(onsubmit)
206
+ @container.onsubmit = onsubmit if(@container.respond_to? :onsubmit=)
207
+ end
208
+ # set a html attribute
209
+ def set_attribute(key, value)
210
+ @attributes.store(key, value)
211
+ end
212
+ def tabindex=(tab)
213
+ @attributes.store('tabIndex', tab.to_s)
214
+ end
215
+ def to_html(context)
216
+ _to_html(context, @value).to_s
217
+ end
218
+ @@nl2br_ptrn = /(\r\n)|(\n)|(\r)/
219
+ def _to_html(context, value=@value)
220
+ if(value.is_a?(Array))
221
+ value.collect { |item| _to_html(context, item) }.join(' ')
222
+ elsif(value.respond_to?(:to_html))
223
+ value.to_html(context).to_s
224
+ else
225
+ value.to_s.gsub(@@nl2br_ptrn, '<br>')
226
+ end
227
+ end
228
+ private
229
+ def init
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,350 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
5
+ # Copyright (C) 2003 ywesee - intellectual capital connected
6
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
7
+ #
8
+ # This library is free software; you can redistribute it and/or
9
+ # modify it under the terms of the GNU Lesser General Public
10
+ # License as published by the Free Software Foundation; either
11
+ # version 2.1 of the License, or (at your option) any later version.
12
+ #
13
+ # This library is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public
19
+ # License along with this library; if not, write to the Free Software
20
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ #
22
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
+ #
25
+ # Template -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/grid'
28
+ require 'htmlgrid/component'
29
+ require 'htmlgrid/value'
30
+ require 'htmlgrid/inputtext'
31
+ require 'htmlgrid/label'
32
+ require 'htmlgrid/text'
33
+
34
+ if RUBY_VERSION < '1.9'
35
+ class Hash
36
+ alias :key :index
37
+ end
38
+ end
39
+
40
+ module HtmlGrid
41
+ class AbstractComposite < Component
42
+ LABELS = false
43
+ LEGACY_INTERFACE = true
44
+ SYMBOL_MAP = {}
45
+ CSS_MAP = {}
46
+ CSS_ID_MAP = {}
47
+ CSS_STYLE_MAP = {}
48
+ CSS_CLASS = nil
49
+ CSS_ID = nil
50
+ DEFAULT_CLASS = Value
51
+ LOOKANDFEEL_MAP = {}
52
+ def init
53
+ super
54
+ setup_grid()
55
+ compose()
56
+ end
57
+ def create(component, model=@model)
58
+ if(component.is_a? Class)
59
+ component.new(model, @session, self)
60
+ elsif(component.is_a? Symbol)
61
+ if(self.respond_to?(component, true))
62
+ args = [model]
63
+ if(self::class::LEGACY_INTERFACE)
64
+ args.push(@session)
65
+ end
66
+ self.send(component, *args)
67
+ elsif(klass = symbol_map[component])
68
+ klass.new(component, model, @session, self)
69
+ else
70
+ self::class::DEFAULT_CLASS.new(component, model, @session, self)
71
+ end
72
+ elsif(component.is_a? String)
73
+ val = @lookandfeel.lookup(component) { component.to_s }
74
+ val.gsub(@@nl2br_ptrn, '<br>')
75
+ end
76
+ rescue StandardError => exc
77
+ exc.backtrace.push(sprintf("%s::COMPONENTS[%s] in create(%s)",
78
+ self.class, components.key(component).inspect, component))
79
+ raise exc
80
+ end
81
+ private
82
+ def components
83
+ @components ||= self::class::COMPONENTS.dup
84
+ end
85
+ def css_id_map
86
+ @css_id_map ||= self::class::CSS_ID_MAP.dup
87
+ end
88
+ def css_map
89
+ @css_map ||= self::class::CSS_MAP.dup
90
+ end
91
+ def css_style_map
92
+ @css_style_map ||= self::class::CSS_STYLE_MAP.dup
93
+ end
94
+ def labels?
95
+ self::class::LABELS
96
+ end
97
+ def lookandfeel_map
98
+ @lookandfeel_map ||= self::class::LOOKANDFEEL_MAP.dup
99
+ end
100
+ def symbol_map
101
+ @symbol_map ||= self::class::SYMBOL_MAP.dup
102
+ end
103
+ def AbstractComposite.component(klass, key, name=nil)
104
+ methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
105
+ define_method(methname) { |*args|
106
+ model, session = args
107
+ args = [model.send(key), @session, self]
108
+ if(name)
109
+ args.unshift(name)
110
+ lookandfeel_map.store(methname.to_sym, name.to_sym)
111
+ end
112
+ klass.new(*args)
113
+ }
114
+ methname.to_sym
115
+ end
116
+ end
117
+ class TagComposite < AbstractComposite
118
+ def compose(model=@model)
119
+ components.sort { |a, b|
120
+ a <=> b
121
+ }.each { |pos, component|
122
+ @grid.push(label(create(component, model), component))
123
+ css = {}
124
+ if(klass = css_map[pos])
125
+ css.store('class', klass)
126
+ end
127
+ if(id = css_id_map[pos])
128
+ css.store('id', id)
129
+ end
130
+ if(style = css_style_map[pos])
131
+ css.store('style', style)
132
+ end
133
+ @css_grid.push(css.empty? ? nil : css)
134
+ }
135
+ end
136
+ def create(component, model=@model)
137
+ if(component.is_a? Class)
138
+ component.new(model, @session, self)
139
+ elsif(component.is_a? Symbol)
140
+ if(self.respond_to?(component, true))
141
+ self.send(component, model)
142
+ elsif(klass = symbol_map[component])
143
+ klass.new(component, model, @session, self)
144
+ else
145
+ self::class::DEFAULT_CLASS.new(component, model, @session, self)
146
+ end
147
+ elsif(component.is_a? String)
148
+ val = @lookandfeel.lookup(component) { component.to_s }
149
+ val.gsub(@@nl2br_ptrn, '<br>')
150
+ end
151
+ rescue StandardError => exc
152
+ exc.backtrace.push(sprintf("%s::COMPONENTS[%s] in create(%s)",
153
+ self.class, components.index(component).inspect, component))
154
+ raise exc
155
+ end
156
+ def insert_row(ypos, txt, css_class=nil)
157
+ @grid[ypos, 0] = [[txt]]
158
+ @css_grid[ypos, 0] = [css_class ? {'class' => css_class} : nil]
159
+ end
160
+ def label(component, key)
161
+ if(labels? \
162
+ && (!component.respond_to?(:label?) || component.label?))
163
+ label = SimpleLabel.new(key, component, @session, self)
164
+ [label, component]
165
+ else
166
+ component
167
+ end
168
+ end
169
+ def setup_grid
170
+ @grid = []
171
+ @css_grid = []
172
+ end
173
+ def submit(model=@model, name=event())
174
+ Submit.new(name, model, @session, self)
175
+ end
176
+ def tag_attributes(idx=nil)
177
+ attr = {}
178
+ if(klass = self.class.const_get(:CSS_CLASS))
179
+ attr.store('class', klass)
180
+ end
181
+ if(id = self.class.const_get(:CSS_ID))
182
+ attr.store('id', id)
183
+ end
184
+ if(idx && (css = @css_grid.at(idx)))
185
+ attr.update(css)
186
+ end
187
+ attr
188
+ end
189
+ end
190
+ class Composite < AbstractComposite
191
+ COLSPAN_MAP = {}
192
+ COMPONENT_CSS_MAP = {}
193
+ CSS_MAP = {}
194
+ DEFAULT_CLASS = InputText
195
+ VERTICAL = false
196
+ def compose(model=@model, offset=[0,0], bg_flag=false)
197
+ comps = components
198
+ css = css_map
199
+ cids = css_id_map
200
+ ccss = component_css_map
201
+ colsp = colspan_map
202
+ suffix = resolve_suffix(model, bg_flag)
203
+ comps.keys.concat(css.keys).concat(colsp.keys).uniq.sort_by { |key|
204
+ [-key.size, key]
205
+ }.each { |key|
206
+ nkey = key[0,2]
207
+ matrix = resolve_offset(key, offset)
208
+ nmatrix = resolve_offset(nkey, offset)
209
+ comp = compose_component(model, comps[key], matrix)
210
+ if(style = css[key])
211
+ @grid.add_style(style + suffix, *matrix)
212
+ elsif(style = css[nkey])
213
+ @grid.add_style(style + suffix, *nmatrix)
214
+ end
215
+ if(id = cids[key] || cids[nkey])
216
+ comp.css_id = id
217
+ end
218
+ if(span = colsp[key])
219
+ @grid.set_colspan(matrix.at(0), matrix.at(1), span)
220
+ end
221
+ }
222
+ # component-styles depend on components having been initialized
223
+ # -> separate iteration
224
+ ccss.each { |key, cstyle|
225
+ matrix = resolve_offset(key, offset)
226
+ @grid.add_component_style(cstyle + suffix, *matrix)
227
+ }
228
+ =begin
229
+ compose_components(model, offset)
230
+ compose_css(offset)
231
+ compose_colspan(offset)
232
+ =end
233
+ end
234
+ alias :_compose :compose
235
+ def compose_colspan(offset)
236
+ colspan_map.each { |matrix, span|
237
+ res = resolve_offset(matrix, offset)
238
+ @grid.set_colspan(res.at(0), res.at(1), span)
239
+ }
240
+ end
241
+ def event
242
+ @container.event if @container.respond_to?(:event)
243
+ end
244
+ =begin
245
+ def explode!
246
+ @grid.explode!
247
+ super
248
+ end
249
+ =end
250
+ def full_colspan
251
+ raw_span = components.keys.collect{ |key|
252
+ key.at(0)
253
+ }.max.to_i
254
+ (raw_span > 0) ? raw_span + 1 : nil
255
+ end
256
+ def insert_row(ypos, txt, css_class=nil)
257
+ @grid.insert_row(ypos, txt)
258
+ @grid.set_colspan(0,ypos)
259
+ @grid.add_style(css_class, 0, ypos) if(css_class)
260
+ end
261
+ def to_html(context)
262
+ @grid.set_attributes(@attributes)
263
+ super << @grid.to_html(context)
264
+ end
265
+ private
266
+ def back(model=@model, session=@session)
267
+ bak = HtmlGrid::Button.new(:back, model, session, self)
268
+ url = @lookandfeel.event_url(:back)
269
+ bak.set_attribute("onClick","document.location.href='#{url}';")
270
+ bak
271
+ end
272
+ def colspan_map
273
+ @colspan_map ||= self::class::COLSPAN_MAP.dup
274
+ end
275
+ def component_css_map
276
+ @component_css_map ||= self::class::COMPONENT_CSS_MAP.dup
277
+ end
278
+ def compose_component(model, component, matrix)
279
+ if(component)
280
+ comp = create(component, model)
281
+ if((tab = matrix.at(3)) && comp.respond_to?(:tabindex=))
282
+ comp.tabindex = tab
283
+ end
284
+ @grid.add(label(comp, component), matrix.at(0), matrix.at(1),
285
+ self::class::VERTICAL)
286
+ comp
287
+ end
288
+ end
289
+ ## compose_components: legacy-code
290
+ def compose_components(model=@model, offset=[0,0])
291
+ warn "HtmlGrid::List#compose_components is deprecated"
292
+ each_component { |matrix, component|
293
+ res = resolve_offset(matrix, offset)
294
+ comp = create(component, model)
295
+ if((tab = matrix.at(3)) && comp.respond_to?(:tabindex=))
296
+ comp.tabindex = tab
297
+ end
298
+ @grid.add(label(comp, component), res.at(0), res.at(1),
299
+ self::class::VERTICAL)
300
+ }
301
+ end
302
+ ## compose_css: legacy-code
303
+ def compose_css(offset=[0,0], suffix='')
304
+ warn "HtmlGrid::List#compose_css is deprecated"
305
+ each_css { |matrix, style|
306
+ @grid.add_style(style + suffix, *resolve_offset(matrix, offset))
307
+ }
308
+ each_component_css { |matrix, style|
309
+ @grid.add_component_style(style + suffix, *resolve_offset(matrix, offset))
310
+ }
311
+ end
312
+ def each_component(&block)
313
+ (@sorted_components ||= components.sort).each(&block)
314
+ end
315
+ def each_component_css(&block)
316
+ (@sorted_component_css_map ||= component_css_map.sort).each(&block)
317
+ end
318
+ def each_css(&block)
319
+ (@sorted_css_map ||= css_map.sort).each(&block)
320
+ end
321
+ def label(component, key=nil)
322
+ if labels?
323
+ HtmlGrid::Label.new(component, @session, lookandfeel_key(key))
324
+ else
325
+ component
326
+ end
327
+ end
328
+ def lookandfeel_key(component)
329
+ lookandfeel_map.fetch(component) {
330
+ component
331
+ }
332
+ end
333
+ def setup_grid
334
+ @grid = Grid.new
335
+ end
336
+ def submit(model=@model, session=@session, name=event())
337
+ Submit.new(name, model, session, self)
338
+ end
339
+ def resolve_offset(matrix, offset=[0,0])
340
+ result = []
341
+ matrix.each_with_index{ |value, index|
342
+ result.push(value+offset.at(index).to_i)
343
+ }
344
+ result
345
+ end
346
+ def resolve_suffix(model, bg_flag=false)
347
+ bg_flag ? self::class::BACKGROUND_SUFFIX : ''
348
+ end
349
+ end
350
+ end