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,39 @@
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
+ # DateValue -- htmlgrid -- 10.03.2003 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/namedcomponent'
28
+
29
+ module HtmlGrid
30
+ class DateValue < NamedComponent
31
+ LABEL = true
32
+ def to_html(context)
33
+ date = @model.send(@name)
34
+ if(date.respond_to?(:strftime))
35
+ date.strftime(@lookandfeel.lookup(:date_format))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
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
+ # Div -- oddb -- 12.11.2004 -- jlang@ywesee.com, usenguel@ywesee.com
26
+
27
+ require 'htmlgrid/component'
28
+
29
+ module HtmlGrid
30
+ class Div < Component
31
+ def to_html(context)
32
+ context.div(@attributes) {
33
+ super << dynamic_html(context)
34
+ }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # DivComposite -- HtmlGrid -- 19.04.2005 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/composite'
6
+
7
+ module HtmlGrid
8
+ class DivComposite < TagComposite
9
+ def compose(model=@model)
10
+ ypos = -1
11
+ xpos = 0
12
+ div = nil
13
+ components.sort_by { |matrix, component|
14
+ [matrix.at(1), matrix.at(0), matrix[2..-1]]
15
+ }.each { |matrix, component|
16
+ if((mpos = matrix.at(1).to_i) > ypos)
17
+ xpos = 0
18
+ ypos = mpos
19
+ div = []
20
+ @grid.push(div)
21
+ css = {}
22
+ if(klass = css_map[ypos])
23
+ css.store('class', klass)
24
+ end
25
+ if(id = css_id_map[ypos])
26
+ css.store('id', id)
27
+ end
28
+ if(style = css_style_map[ypos])
29
+ css.store('style', style)
30
+ end
31
+ @css_grid.push(css.empty? ? nil : css)
32
+ end
33
+ div.push(label(create(component, model), component))
34
+ }
35
+ end
36
+ def to_html(context)
37
+ res = ''
38
+ @grid.each_with_index { |div, idx|
39
+ res << context.div(tag_attributes(idx)) {
40
+ div.flatten.inject('') { |html, item|
41
+ html << if(item.respond_to?(:to_html))
42
+ item.to_html(context)
43
+ else
44
+ item.to_s
45
+ end
46
+ }
47
+ }
48
+ }
49
+ res
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,35 @@
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
+ # Form -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/form'
28
+ require 'htmlgrid/divcomposite'
29
+ require 'htmlgrid/submit'
30
+
31
+ module HtmlGrid
32
+ class DivForm < DivComposite
33
+ include FormMethods
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # HtmlGrid::DivList -- davaz.com -- 20.09.2005 -- mhuggler@ywesee.com
4
+
5
+ require 'htmlgrid/divcomposite'
6
+
7
+ module HtmlGrid
8
+ class DivList < HtmlGrid::DivComposite
9
+ def compose
10
+ @model.each_with_index { |item, idx|
11
+ @list_index = idx
12
+ super(item)
13
+ }
14
+ =begin
15
+ if(header = self.class.const_get(:HEADER))
16
+ @grid.push(create(header, @model, @session))
17
+ @css_grid.push(nil)
18
+ end
19
+ if(footer = self.class.const_get(:FOOTER))
20
+ @grid.push(create(footer, @model, @session))
21
+ @css_grid.push(nil)
22
+ end
23
+ =end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # DivTemplate -- htmlgrid -- 04.05.2005 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/divcomposite'
6
+ require 'htmlgrid/template'
7
+
8
+ module HtmlGrid
9
+ class DivTemplate < DivComposite
10
+ include TemplateMethods
11
+ end
12
+ end
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # HtmlGrid::DojoToolkit -- davaz.com -- 14.03.2006 -- mhuggler@ywesee.com
4
+
5
+ require 'htmlgrid/component'
6
+ require 'htmlgrid/div'
7
+
8
+ module HtmlGrid
9
+ class Component
10
+ @@msie_ptrn = /MSIE\s*(\d)/
11
+ attr_accessor :dojo_tooltip
12
+ def dojo_9?
13
+ defined?(::DOJO_VERSION) && ::DOJO_VERSION >= '0.9'
14
+ end
15
+ def dojo_tag(widget, args={}, inner_html='')
16
+ # <dojo:#{widget} ...> does not work on konqueror as of
17
+ # 02.06.2006. In combination with DOJO_DEBUG = true it even
18
+ # hangs konqueror.
19
+ =begin
20
+ dojo_tag = "<div dojoType=\"#{widget}\""
21
+ args.each { |key, value|
22
+ if(value.is_a?(Array))
23
+ dojo_tag << " #{key}=\"#{value.join(';')}\""
24
+ else
25
+ dojo_tag << " #{key}=\"#{value}\""
26
+ end
27
+ }
28
+ dojo_tag << "></div>"
29
+ =end
30
+ div = HtmlGrid::Div.new(@model, @session, self)
31
+ div.set_attribute('dojoType', widget)
32
+ lim = dojo_9? ? "," : ";"
33
+ args.each { |key, value|
34
+ if(value.is_a?(Array))
35
+ value = value.join(lim)
36
+ end
37
+ div.set_attribute(key, value)
38
+ }
39
+ div.value = inner_html
40
+ div
41
+ end
42
+ def dojo_title=(value)
43
+ tooltip = HtmlGrid::Div.new(@model, @session, self)
44
+ tooltip.value = value
45
+ self.dojo_tooltip = tooltip
46
+ end
47
+ def dojo_parse_widgets
48
+ if(@container.respond_to?(:dojo_parse_widgets))
49
+ @container.dojo_parse_widgets
50
+ end
51
+ end
52
+ unless(method_defined?(:dojo_dynamic_html))
53
+ alias :dojo_dynamic_html :dynamic_html
54
+ def dynamic_html(context)
55
+ html = ''
56
+ attrs = {
57
+ 'dojoType' => dojo_9? ? 'ywesee.widget.Tooltip' : 'tooltip',
58
+ 'connectId' => css_id,
59
+ 'id' => "#{css_id}_widget",
60
+ 'style' => 'display: none',
61
+ }
62
+ unless((match = @@msie_ptrn.match(@session.user_agent)) \
63
+ && match[1].to_i < 7)
64
+ attrs.update({
65
+ 'toggle' => 'fade',
66
+ 'toggleDuration' => '500',
67
+ })
68
+ end
69
+ if(@dojo_tooltip.is_a?(String))
70
+ attrs.store('href', dojo_9? ? "'#@dojo_tooltip'" : @dojo_tooltip)
71
+ html << context.div(attrs)
72
+ elsif(@dojo_tooltip.respond_to?(:to_html))
73
+ @dojo_tooltip.attributes.update(attrs)
74
+ html << @dojo_tooltip.to_html(context)
75
+ end
76
+ unless(html.empty? || dojo_parse_widgets)
77
+ html << context.script('type' => 'text/javascript') {
78
+ "djConfig.searchIds.push('#{css_id}')"
79
+ }
80
+ end
81
+ dojo_dynamic_html(context) << html
82
+ end
83
+ end
84
+ end
85
+ module DojoToolkit
86
+ module DojoTemplate
87
+ DOJO_DEBUG = false
88
+ DOJO_BACK_BUTTON = false
89
+ DOJO_ENCODING = nil
90
+ DOJO_PARSE_WIDGETS = true
91
+ DOJO_PREFIX = []
92
+ DOJO_REQUIRE = []
93
+ def dynamic_html_headers(context)
94
+ headers = super
95
+ encoding = self.class::DOJO_ENCODING
96
+ encoding ||= if RUBY_VERSION >= '1.9'
97
+ Encoding.default_external
98
+ else
99
+ $KCODE == 'UTF8' ? 'UTF-8' : 'ISO-8859-1'
100
+ end
101
+ dojo_path = @lookandfeel.resource_global(:dojo_js)
102
+ args = {
103
+ 'type' => 'text/javascript',
104
+ }
105
+ headers << context.script(args.dup) {
106
+ "djConfig = {
107
+ isDebug: #{self.class::DOJO_DEBUG},
108
+ parseWidgets: #{dojo_parse_widgets},
109
+ preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON},
110
+ bindEncoding: '#{encoding}',
111
+ searchIds: [],
112
+ urchin: ''
113
+ };"
114
+ }
115
+ if(dojo_9?)
116
+ dojo_path ||= '/resources/dojo/dojo/dojo.js'
117
+ config = [ "parseOnLoad:true",
118
+ "isDebug:#{self.class::DOJO_DEBUG}",
119
+ "preventBackButtonFix:#{!self.class::DOJO_BACK_BUTTON}",
120
+ "bindEncoding:'#{encoding}'",
121
+ "searchIds:[]",
122
+ "urchin:''" ].join(',')
123
+ args.store('djConfig', config)
124
+ else
125
+ dojo_path ||= '/resources/dojo/dojo.js'
126
+ end
127
+ args.store('src', dojo_path)
128
+ headers << context.script(args)
129
+ unless(self.class::DOJO_PREFIX.empty?)
130
+ register = dojo_9? ? 'registerModulePath' : 'setModulePrefix'
131
+ args = {
132
+ 'type' => 'text/javascript',
133
+ }
134
+ headers << context.script(args) {
135
+ self.class::DOJO_PREFIX.collect { |prefix, path|
136
+ "dojo.#{register}('#{prefix}', '#{path}');"
137
+ }.join
138
+ }
139
+ end
140
+ args = {
141
+ 'type' => 'text/javascript',
142
+ }
143
+ headers << context.script(args) {
144
+ script = ''
145
+ self.class::DOJO_REQUIRE.each { |req|
146
+ script << "dojo.require('#{req}');"
147
+ }
148
+ if(@dojo_onloads)
149
+ @dojo_onloads.each { |onload|
150
+ script << "dojo.addOnLoad(function() { #{onload} });"
151
+ }
152
+ end
153
+ script
154
+ }
155
+ if(dojo_9?)
156
+ dojo_dir = File.dirname(dojo_path)
157
+ headers << context.style(:type => "text/css") { <<-EOS
158
+ @import "#{File.join(dojo_dir, "/resources/dojo.css")}";
159
+ @import "#{File.join(dojo_dir, "../dijit/themes/tundra/tundra.css")}";
160
+ EOS
161
+ }
162
+ end
163
+ headers
164
+ end
165
+ def dojo_parse_widgets
166
+ self.class::DOJO_PARSE_WIDGETS
167
+ end
168
+ def onload=(script)
169
+ (@dojo_onloads ||= []).push(script)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,70 @@
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
+ # ErrorMessage -- htmlgrid -- 10.04.2003 -- benfay@ywesee.com
26
+
27
+ module HtmlGrid
28
+ module ErrorMessage
29
+ private
30
+ def error_message(ypos = 0)
31
+ @displayed_messages = []
32
+ if(@session.warning?)
33
+ __messages(@session.warnings, 'warning', ypos)
34
+ end
35
+ if(@session.error?)
36
+ __messages(@session.errors, 'processingerror', ypos)
37
+ end
38
+ end
39
+ def error_text(obj)
40
+ message = obj.message
41
+ txt = HtmlGrid::Text.new(message, @model, @session, self)
42
+ if(txt.value.nil?)
43
+ txt.value = @lookandfeel.lookup(message, escape(obj.value))
44
+ end
45
+ if(txt.value.nil? && (match = /^(._[^_]+)_(.*)$/.match(message.to_s)) \
46
+ && (label = @lookandfeel.lookup(match[2])))
47
+ txt.value = @lookandfeel.lookup(match[1], label)
48
+ end
49
+ txt
50
+ end
51
+ def __message(obj, css_class, ypos=0)
52
+ @displayed_messages ||= []
53
+ message = obj.message
54
+ unless(@displayed_messages.include?(message))
55
+ @displayed_messages.push(message)
56
+ txt = error_text(obj)
57
+ unless(txt.value.nil?)
58
+ insert_row(ypos, txt, css_class)
59
+ end
60
+ end
61
+ end
62
+ def __messages(ary, css_class, ypos=0)
63
+ ary.sort_by { |item|
64
+ (components.index(item.key) || [-1,-1]).reverse
65
+ }.reverse.each { |item|
66
+ __message(item, css_class, ypos)
67
+ }
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,93 @@
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
+ # Form -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
26
+
27
+ require 'htmlgrid/composite'
28
+ require 'htmlgrid/submit'
29
+
30
+ module HtmlGrid
31
+ module FormMethods
32
+ AUTOFILL = false
33
+ if RUBY_VERSION >= '1.9'
34
+ ACCEPT_CHARSET = Encoding.default_external || 'UTF-8'
35
+ else
36
+ ACCEPT_CHARSET = $KCODE == 'UTF8' ? 'UTF-8' : 'ISO-8859-1'
37
+ end
38
+ EVENT = nil
39
+ FORM_ACTION = nil
40
+ FORM_METHOD = 'POST'
41
+ FORM_NAME = 'stdform'
42
+ TAG_METHOD = :form
43
+ def autofill?
44
+ self.class.const_get(:AUTOFILL)
45
+ end
46
+ def event
47
+ self::class::EVENT
48
+ end
49
+ def formname
50
+ if(defined? self::class::FORM_NAME)
51
+ self::class::FORM_NAME
52
+ end
53
+ end
54
+ def onsubmit=(onsubmit)
55
+ @form_properties["onSubmit"] = onsubmit
56
+ end
57
+ def to_html(context)
58
+ context.send(self::class::TAG_METHOD, @form_properties) {
59
+ super << context.div('style'=>'display:none') { hidden_fields(context) }
60
+ }
61
+ end
62
+ private
63
+ def hidden_fields(context)
64
+ '' <<
65
+ context.hidden('flavor', @lookandfeel.flavor) <<
66
+ context.hidden('language', @lookandfeel.language) <<
67
+ context.hidden({'NAME' => 'event', 'ID' => 'event',
68
+ 'VALUE' => event.to_s}) <<
69
+ context.hidden('state_id', @session.state.object_id.to_s)
70
+ end
71
+ def init
72
+ @form_properties = {}
73
+ if(defined? self::class::FORM_CSS_CLASS)
74
+ @form_properties.store('class', self::class::FORM_CSS_CLASS)
75
+ end
76
+ if(defined? self::class::FORM_NAME)
77
+ @form_properties.store('NAME', self::class::FORM_NAME)
78
+ end
79
+ if(defined? self::class::FORM_ID)
80
+ @form_properties.store('ID', self::class::FORM_ID)
81
+ end
82
+ super
83
+ @form_properties.update({
84
+ 'METHOD' => self::class::FORM_METHOD.dup,
85
+ 'ACTION' => (self::class::FORM_ACTION || @lookandfeel.base_url),
86
+ 'ACCEPT-CHARSET' => self::class::ACCEPT_CHARSET,
87
+ })
88
+ end
89
+ end
90
+ class Form < Composite
91
+ include FormMethods
92
+ end
93
+ end
@@ -0,0 +1,42 @@
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
+ # FormList -- htmlgrid -- 25.03.2003 -- aschrafl@ywesee.com
26
+
27
+ require 'htmlgrid/list'
28
+ require 'htmlgrid/form'
29
+ require 'htmlgrid/value'
30
+ require 'htmlgrid/button'
31
+
32
+ module HtmlGrid
33
+ class FormList < List
34
+ include FormMethods
35
+ DEFAULT_CLASS = Value
36
+ EVENT = :new_item
37
+ def compose_footer(matrix)
38
+ @grid.add(submit(), *matrix)
39
+ @grid.set_colspan(*matrix)
40
+ end
41
+ end
42
+ end