sws 0.4

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 (158) hide show
  1. data/doc/DOC.otl +34 -0
  2. data/doc/Makefile +13 -0
  3. data/doc/architecture.dia +0 -0
  4. data/doc/docbook/architecture.png +0 -0
  5. data/doc/docbook/concepts.docbook +474 -0
  6. data/doc/docbook/installation.docbook +57 -0
  7. data/doc/docbook/introduction.docbook +130 -0
  8. data/doc/docbook/sws_manual.docbook +35 -0
  9. data/doc/docbook/todo.docbook +38 -0
  10. data/doc/docbook/tutorial.docbook +594 -0
  11. data/examples/README +1 -0
  12. data/examples/addressbook/CardBrowse/CardBrowse.html +43 -0
  13. data/examples/addressbook/CardBrowse/CardBrowse.rb +65 -0
  14. data/examples/addressbook/CardBrowse/CardBrowse.sws +92 -0
  15. data/examples/addressbook/Login/LoginPage.html +12 -0
  16. data/examples/addressbook/Login/LoginPage.rb +19 -0
  17. data/examples/addressbook/Login/LoginPage.sws +15 -0
  18. data/examples/addressbook/README +1 -0
  19. data/examples/addressbook/addressbook.rb +70 -0
  20. data/examples/addressbook/application.yaml +8 -0
  21. data/examples/addressbook/db.yaml +7 -0
  22. data/examples/component_demo/CheckBoxDemo/CheckBoxDemo.html +11 -0
  23. data/examples/component_demo/CheckBoxDemo/CheckBoxDemo.rb +21 -0
  24. data/examples/component_demo/CheckBoxDemo/CheckBoxDemo.sws +25 -0
  25. data/examples/component_demo/ComponentDemo.rb +21 -0
  26. data/examples/component_demo/ConditionalDemo/ConditionalDemo.html +18 -0
  27. data/examples/component_demo/ConditionalDemo/ConditionalDemo.rb +2 -0
  28. data/examples/component_demo/ConditionalDemo/ConditionalDemo.sws +22 -0
  29. data/examples/component_demo/FileUploadDemo/FileUploadDemo.html +10 -0
  30. data/examples/component_demo/FileUploadDemo/FileUploadDemo.rb +9 -0
  31. data/examples/component_demo/FileUploadDemo/FileUploadDemo.sws +33 -0
  32. data/examples/component_demo/FormFieldsDemo/FormFieldsDemo.html +12 -0
  33. data/examples/component_demo/FormFieldsDemo/FormFieldsDemo.rb +21 -0
  34. data/examples/component_demo/FormFieldsDemo/FormFieldsDemo.sws +40 -0
  35. data/examples/component_demo/FormListsDemo/FormListsDemo.html +11 -0
  36. data/examples/component_demo/FormListsDemo/FormListsDemo.rb +37 -0
  37. data/examples/component_demo/FormListsDemo/FormListsDemo.sws +47 -0
  38. data/examples/component_demo/GenericDemo/GenericDemo.html +4 -0
  39. data/examples/component_demo/GenericDemo/GenericDemo.rb +2 -0
  40. data/examples/component_demo/GenericDemo/GenericDemo.sws +10 -0
  41. data/examples/component_demo/HyperlinkDemo/HyperlinkDemo.html +8 -0
  42. data/examples/component_demo/HyperlinkDemo/HyperlinkDemo.rb +20 -0
  43. data/examples/component_demo/HyperlinkDemo/HyperlinkDemo.sws +19 -0
  44. data/examples/component_demo/ImageLinkDemo/ImageLinkDemo.html +11 -0
  45. data/examples/component_demo/ImageLinkDemo/ImageLinkDemo.rb +2 -0
  46. data/examples/component_demo/ImageLinkDemo/ImageLinkDemo.sws +14 -0
  47. data/examples/component_demo/PageWrapper/PageWrapper.html +23 -0
  48. data/examples/component_demo/PageWrapper/PageWrapper.rb +2 -0
  49. data/examples/component_demo/PageWrapper/PageWrapper.sws +42 -0
  50. data/examples/component_demo/README +1 -0
  51. data/examples/component_demo/RepetitionDemo/RepetitionDemo.html +13 -0
  52. data/examples/component_demo/RepetitionDemo/RepetitionDemo.rb +19 -0
  53. data/examples/component_demo/RepetitionDemo/RepetitionDemo.sws +20 -0
  54. data/examples/component_demo/StringDemo/StringDemo.html +5 -0
  55. data/examples/component_demo/StringDemo/StringDemo.rb +16 -0
  56. data/examples/component_demo/StringDemo/StringDemo.sws +14 -0
  57. data/examples/component_demo/application.yaml +28 -0
  58. data/examples/component_demo/poweredby.jpg +0 -0
  59. data/examples/component_demo/style.css +1 -0
  60. data/examples/movies/Menu/Menu.html +3 -0
  61. data/examples/movies/Menu/Menu.rb +7 -0
  62. data/examples/movies/Menu/Menu.sws +7 -0
  63. data/examples/movies/MovieBrowse/MovieBrowse.html +68 -0
  64. data/examples/movies/MovieBrowse/MovieBrowse.rb +178 -0
  65. data/examples/movies/MovieBrowse/MovieBrowse.sws +127 -0
  66. data/examples/movies/README +1 -0
  67. data/examples/movies/UserBrowse/UserBrowse.html +50 -0
  68. data/examples/movies/UserBrowse/UserBrowse.rb +69 -0
  69. data/examples/movies/UserBrowse/UserBrowse.sws +49 -0
  70. data/examples/movies/application.yaml +11 -0
  71. data/examples/movies/da.rb +36 -0
  72. data/examples/movies/dbmovies.rb +44 -0
  73. data/examples/movies/frameworks/TestFramework/framework.yaml +4 -0
  74. data/examples/movies/frameworks/TestFramework/resources/im1.jpg +0 -0
  75. data/examples/movies/images/pbr1b.jpg +0 -0
  76. data/examples/movies/movies.rb +28 -0
  77. data/examples/movies/movies.sds +119 -0
  78. data/examples/movies/movies.sqlite +0 -0
  79. data/examples/movies/movies_mysql.sql +28 -0
  80. data/examples/movies/movies_postgres.sql +27 -0
  81. data/examples/movies/movies_sqlite.sql +28 -0
  82. data/lib/sws.rb +89 -0
  83. data/lib/sws/Core/components/CheckBox/CheckBox.api +5 -0
  84. data/lib/sws/Core/components/CheckBox/CheckBox.rb +45 -0
  85. data/lib/sws/Core/components/CheckBoxList/CheckBoxList.api +13 -0
  86. data/lib/sws/Core/components/CheckBoxList/CheckBoxList.rb +54 -0
  87. data/lib/sws/Core/components/Conditional/Conditional.api +3 -0
  88. data/lib/sws/Core/components/Conditional/Conditional.html +1 -0
  89. data/lib/sws/Core/components/Conditional/Conditional.rb +39 -0
  90. data/lib/sws/Core/components/Conditional/Conditional.sws +2 -0
  91. data/lib/sws/Core/components/Content/Content.rb +18 -0
  92. data/lib/sws/Core/components/ExceptionPage/ExceptionPage.html +13 -0
  93. data/lib/sws/Core/components/ExceptionPage/ExceptionPage.rb +18 -0
  94. data/lib/sws/Core/components/ExceptionPage/ExceptionPage.sws +16 -0
  95. data/lib/sws/Core/components/FileUpload/FileUpload.api +16 -0
  96. data/lib/sws/Core/components/FileUpload/FileUpload.rb +62 -0
  97. data/lib/sws/Core/components/Form/Form.api +9 -0
  98. data/lib/sws/Core/components/Form/Form.html +3 -0
  99. data/lib/sws/Core/components/Form/Form.rb +55 -0
  100. data/lib/sws/Core/components/Form/Form.sws +12 -0
  101. data/lib/sws/Core/components/GenericContainer/GenericContainer.api +10 -0
  102. data/lib/sws/Core/components/GenericContainer/GenericContainer.html +1 -0
  103. data/lib/sws/Core/components/GenericContainer/GenericContainer.rb +39 -0
  104. data/lib/sws/Core/components/GenericContainer/GenericContainer.sws +12 -0
  105. data/lib/sws/Core/components/GenericElement/GenericElement.api +10 -0
  106. data/lib/sws/Core/components/GenericElement/GenericElement.rb +34 -0
  107. data/lib/sws/Core/components/HiddenField/HiddenField.api +7 -0
  108. data/lib/sws/Core/components/HiddenField/HiddenField.rb +37 -0
  109. data/lib/sws/Core/components/Hyperlink/Hyperlink.api +13 -0
  110. data/lib/sws/Core/components/Hyperlink/Hyperlink.html +1 -0
  111. data/lib/sws/Core/components/Hyperlink/Hyperlink.rb +102 -0
  112. data/lib/sws/Core/components/Hyperlink/Hyperlink.sws +12 -0
  113. data/lib/sws/Core/components/Image/Image.api +11 -0
  114. data/lib/sws/Core/components/Image/Image.rb +49 -0
  115. data/lib/sws/Core/components/ImageButton/ImageButton.api +16 -0
  116. data/lib/sws/Core/components/ImageButton/ImageButton.rb +76 -0
  117. data/lib/sws/Core/components/Link/Link.api +11 -0
  118. data/lib/sws/Core/components/Link/Link.rb +39 -0
  119. data/lib/sws/Core/components/PasswordField/PasswordField.api +7 -0
  120. data/lib/sws/Core/components/PasswordField/PasswordField.rb +41 -0
  121. data/lib/sws/Core/components/RadioButton/RadioButton.api +7 -0
  122. data/lib/sws/Core/components/RadioButton/RadioButton.rb +44 -0
  123. data/lib/sws/Core/components/RadioButtonList/RadioButtonList.api +20 -0
  124. data/lib/sws/Core/components/RadioButtonList/RadioButtonList.rb +76 -0
  125. data/lib/sws/Core/components/Repetition/Repetition.api +10 -0
  126. data/lib/sws/Core/components/Repetition/Repetition.html +1 -0
  127. data/lib/sws/Core/components/Repetition/Repetition.rb +137 -0
  128. data/lib/sws/Core/components/Repetition/Repetition.sws +2 -0
  129. data/lib/sws/Core/components/ResetButton/ResetButton.api +5 -0
  130. data/lib/sws/Core/components/ResetButton/ResetButton.rb +28 -0
  131. data/lib/sws/Core/components/Select/Select.api +24 -0
  132. data/lib/sws/Core/components/Select/Select.rb +57 -0
  133. data/lib/sws/Core/components/String/String.api +5 -0
  134. data/lib/sws/Core/components/String/String.rb +28 -0
  135. data/lib/sws/Core/components/SubmitButton/SubmitButton.api +6 -0
  136. data/lib/sws/Core/components/SubmitButton/SubmitButton.rb +53 -0
  137. data/lib/sws/Core/components/TextArea/TextArea.api +9 -0
  138. data/lib/sws/Core/components/TextArea/TextArea.rb +28 -0
  139. data/lib/sws/Core/components/TextField/TextField.api +9 -0
  140. data/lib/sws/Core/components/TextField/TextField.rb +46 -0
  141. data/lib/sws/Core/framework.yaml +25 -0
  142. data/lib/sws/JSComponents/components/JSMenu/JSMenu.api +5 -0
  143. data/lib/sws/JSComponents/components/JSMenu/JSMenu.html +58 -0
  144. data/lib/sws/JSComponents/components/JSMenu/JSMenu.rb +34 -0
  145. data/lib/sws/JSComponents/components/JSMenu/JSMenu.sws +37 -0
  146. data/lib/sws/JSComponents/framework.yaml +3 -0
  147. data/lib/sws/adaptor.rb +334 -0
  148. data/lib/sws/application.rb +604 -0
  149. data/lib/sws/component.rb +656 -0
  150. data/lib/sws/cookie.rb +27 -0
  151. data/lib/sws/direct_action.rb +38 -0
  152. data/lib/sws/extensions.rb +49 -0
  153. data/lib/sws/parsers.rb +374 -0
  154. data/lib/sws/request.rb +308 -0
  155. data/lib/sws/response.rb +70 -0
  156. data/lib/sws/session.rb +195 -0
  157. data/lib/sws/slot.rb +198 -0
  158. metadata +263 -0
@@ -0,0 +1,27 @@
1
+ create table "rental" (
2
+ "id_movie" integer NOT NULL,
3
+ "id_user" integer NOT NULL,
4
+ "return_date" date,
5
+ "rental_date" date NOT NULL,
6
+ primary key ( "id_movie","id_user" )
7
+ ) ;
8
+ create table "user" (
9
+ "name" varchar(100) NOT NULL,
10
+ "id" integer NOT NULL,
11
+ primary key ( "id" )
12
+ ) ;
13
+ create sequence "user_seq";
14
+ create table "movie" (
15
+ "id" integer NOT NULL,
16
+ "english_title" varchar(50) NOT NULL,
17
+ "rented" integer NOT NULL,
18
+ "description" varchar(250) NOT NULL,
19
+ "cd_count" integer NOT NULL,
20
+ "polish_title" varchar(50) NOT NULL,
21
+ primary key ( "id" )
22
+ ) ;
23
+ create sequence "movie_seq";
24
+ create index "rental_user" on "rental" ("id_user");
25
+ alter table "rental" add constraint "fk_rental_user" foreign key ("id_user") references "user" ("id");
26
+ create index "rental_movie" on "rental" ("id_movie");
27
+ alter table "rental" add constraint "fk_rental_movie" foreign key ("id_movie") references "movie" ("id");
@@ -0,0 +1,28 @@
1
+ create table _pk_support (table_name varchar(250), pk integer(10));
2
+ create table "rental" (
3
+ "id_movie" integer NOT NULL,
4
+ "id_user" integer NOT NULL,
5
+ "return_date" date,
6
+ "rental_date" date NOT NULL,
7
+ primary key ( "id_movie","id_user" )
8
+ ) ;
9
+ create table "user" (
10
+ "name" varchar(100) NOT NULL,
11
+ "id" integer NOT NULL,
12
+ primary key ( "id" )
13
+ ) ;
14
+ insert into _pk_support (table_name,pk) values ('user',1);
15
+ create table "movie" (
16
+ "id" integer NOT NULL,
17
+ "english_title" varchar(50) NOT NULL,
18
+ "rented" integer NOT NULL,
19
+ "description" varchar(250) NOT NULL,
20
+ "cd_count" integer NOT NULL,
21
+ "polish_title" varchar(50) NOT NULL,
22
+ primary key ( "id" )
23
+ ) ;
24
+ insert into _pk_support (table_name,pk) values ('movie',1);
25
+ create index "rental_user" on "rental" ("id_user");
26
+
27
+ create index "rental_movie" on "rental" ("id_movie");
28
+
@@ -0,0 +1,89 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+ require 'sws/application'
4
+ require 'sws/extensions'
5
+ require 'sws/parsers'
6
+ require 'sws/component'
7
+ require 'sws/request'
8
+ require 'sws/response'
9
+ require 'sws/adaptor'
10
+ require 'sws/cookie'
11
+ require 'sws/session'
12
+ require 'sws/slot'
13
+ require 'sws/direct_action'
14
+
15
+ begin
16
+ require 'rubygems'
17
+ require_gem( 'log4r', '>= 1.0.4' )
18
+ rescue LoadError
19
+ require 'log4r'
20
+ end
21
+
22
+
23
+
24
+ module SWS
25
+
26
+ Framework = Struct.new( :path, :components, :resources )
27
+ ComponentInfo = Struct.new( :component_class, :definition, :template, :api )
28
+
29
+ # Initializes log4r. Called when loading SWS.
30
+ def SWS.init_log4r()
31
+
32
+ $log_sws = Log4r::Logger.new( "sws" )
33
+ # $log_sws.level = Log4r::INFO
34
+ $log_sws.outputters = Log4r::Outputter.stderr
35
+ $log_sws_component = Log4r::Logger.new( "sws::component", Log4r::INFO )
36
+ $log_sws_parser = Log4r::Logger.new( "sws::parser", Log4r::INFO )
37
+ $log_sws_request = Log4r::Logger.new( "sws::request", Log4r::INFO )
38
+ $log_sws_profile = Log4r::Logger.new( "sws::profile", Log4r::INFO )
39
+ $log_sws_handle = Log4r::Logger.new( "sws::handle", Log4r::INFO )
40
+ $log_sws_mc = Log4r::Logger.new( "sws::mc", Log4r::INFO )
41
+
42
+ end
43
+
44
+
45
+ # Retrieves const by its name - in opposition to Object.const_get() works for
46
+ # const contained within modules
47
+ def SWS.get_const( name )
48
+
49
+ const = ::Object
50
+ name.split( /::/ ).each do |name_elem|
51
+ begin
52
+ const = const.const_get( name_elem )
53
+ rescue NameError
54
+ return nil
55
+ end
56
+ end
57
+
58
+ # Necessary to avoid finding const in parent namespace (eg. SWS::String and
59
+ # String)
60
+ return const.name == name ? const : nil
61
+
62
+ end
63
+
64
+
65
+ def SWS.get_class (name)
66
+
67
+ klass = SWS.get_const( name )
68
+ unless ( klass.is_a?( Class ) )
69
+ raise TypeError.new( "Constant #{name} is not a Class" )
70
+ end
71
+ return klass
72
+
73
+ end
74
+
75
+
76
+ def SWS.get_module (name)
77
+
78
+ mod = SWS.get_const( name )
79
+ unless ( mod.is_a?( Module ) )
80
+ raise TypeError.new( "Constant #{name} is not a Module" )
81
+ end
82
+ return mod
83
+
84
+ end
85
+
86
+ end
87
+
88
+
89
+ SWS.init_log4r()
@@ -0,0 +1,5 @@
1
+ checked:
2
+ required: true
3
+ settable: true
4
+ disabled:
5
+ other_tag_string:
@@ -0,0 +1,45 @@
1
+ module SWS
2
+
3
+ # Represents <INPUT type=checkbox tag.
4
+ # Bindings:
5
+ # - checked (settable, required) - if true, the checkbox will be checked. If
6
+ # checked, the value bound will be set to true.
7
+ # - disabled - if true, the checkbox will be rendered inactive.
8
+ # - other_tag_string - generic string to add to the HTML tag
9
+ class CheckBox < FormElement
10
+
11
+
12
+ def process_bindings ()
13
+
14
+ if ( @parameters["checked"] == "on" )
15
+ @slots["checked"].value = true
16
+ else
17
+ @slots["checked"].value = false
18
+ end
19
+
20
+ end
21
+
22
+
23
+ def append_to_response ( response )
24
+ response << generate_html()
25
+ end
26
+
27
+
28
+ # Generates HTML code for the HTML checkbox form element
29
+ def generate_html ()
30
+
31
+ string = "<INPUT type=\"checkbox\" name=\"#{element_name()}.checked\""
32
+ if ( @slots["checked"].value() )
33
+ string << " checked"
34
+ end
35
+ if ( slot_bound?( "disabled" ) && @slots["disabled"] )
36
+ string << " disabled"
37
+ end
38
+ string << generic_attr_string() << ">"
39
+ return string
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,13 @@
1
+ list:
2
+ required: true
3
+ item:
4
+ required: true
5
+ settable: true
6
+ display_string:
7
+ selections:
8
+ required: true
9
+ settable: true
10
+ prefix:
11
+ suffix:
12
+ disabled:
13
+ other_tag_string:
@@ -0,0 +1,54 @@
1
+ module SWS
2
+
3
+ # Represents a list of checkboxes with the same name.
4
+ # Bindings:
5
+ # - list (required) - array of object to iterate in the checkboxes
6
+ # - item (required, settable) - an object to use as iterator
7
+ # - display_string - use it if the string to display at a checkbox is not the
8
+ # item itself
9
+ # - selections (required,settable) - the array of selected items (not the
10
+ # displayed strings, but the objects)
11
+ # - prefix - HTML code to add before each checkbox
12
+ # - suffix - HTML code to add after each checkbox
13
+ # - disabled - if true, the list will be rendered inactive
14
+ # - other_tag_string - generic string to add to the end of each <INPUT
15
+ # type=checkbox tag
16
+ class CheckBoxList < MultipleSelectionList
17
+
18
+
19
+ # Generates the HTML code for the component.
20
+ def generate_html ()
21
+
22
+ string = ""
23
+ generic_string = generic_attr_string()
24
+ list().each_index do |index|
25
+ item = list[index]
26
+ @slots["item"].value = item
27
+ if ( slot_bound?( "display_string" ))
28
+ display_string = @slots["display_string"].value()
29
+ else
30
+ display_string = item
31
+ end
32
+ if ( slot_bound?( "prefix" ))
33
+ string << @slots["prefix"].value()
34
+ end
35
+ string << "<INPUT type=\"checkbox\" name=\"#{element_name()}.selections\" value=#{index}"
36
+ if ( slot_bound?( "disabled" ) && @slots["disabled"].value() == true )
37
+ string << " disabled"
38
+ end
39
+ if ( selections().include?( item ) )
40
+ string << " checked"
41
+ end
42
+ string << generic_string << ">\n"
43
+ string << display_string
44
+ if ( slot_bound?( "suffix" ) )
45
+ string << @slots["suffix"].value()
46
+ end
47
+ end
48
+ return string
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,3 @@
1
+ condition:
2
+ required: true
3
+ negate:
@@ -0,0 +1 @@
1
+ <span sws="content"/>
@@ -0,0 +1,39 @@
1
+ module SWS
2
+
3
+ # Represents content that is rendered conditionally.
4
+ # Bindings:
5
+ # - condition (required) - if true, the content will be rendered
6
+ # - negate - if true, the condition is reversed
7
+ class Conditional < Component
8
+
9
+
10
+ def process_bindings ()
11
+ if ( render_content? ) then super end
12
+ end
13
+
14
+
15
+ def create_component_tree ()
16
+ if ( render_content? ) then super end
17
+ end
18
+
19
+
20
+ # The content of this component is appended to response only if value of
21
+ # only one of "condition" and "negate" slots evaluates to true.
22
+ def append_to_response ( response )
23
+ if ( render_content? ) then super end
24
+ end
25
+
26
+
27
+ private
28
+ def render_content? ()
29
+
30
+ condition = @slots["condition"].value()
31
+ negate = @slots["negate"].value()
32
+
33
+ return( (condition && ! negate) || (!condition && negate) )
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,2 @@
1
+ content:
2
+ _class: SWS::Content
@@ -0,0 +1,18 @@
1
+ module SWS
2
+
3
+ # Represents content that has been wrapped in another Component - eg. the
4
+ # Form usually has some fields like TextField or SubmitButton contained
5
+ # within. This is very special component.
6
+ class Content < Component
7
+
8
+ def content? ()
9
+ return true
10
+ end
11
+
12
+ def container? ()
13
+ return false
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head><title>Exception raised!</title></head>
3
+ <body>
4
+ <h3><span sws="string_exception_class"></span>:
5
+ <span sws="string_exception_message"></span>
6
+ </h3>
7
+ Backtrace:<br>
8
+ <span sws="repetition_backtrace">
9
+ <span sws="string_backtrace_element"></span><br>
10
+ </span>
11
+ </body>
12
+ </html>
13
+
@@ -0,0 +1,18 @@
1
+ module SWS
2
+
3
+ # Default exception page - displays exception message and the backtrace
4
+ class ExceptionPage < Component
5
+
6
+ # Exception to be displayed.
7
+ attr_accessor :exception
8
+
9
+ # Cursor to iterate through backtrace elements
10
+ attr_accessor :backtrace_cursor
11
+
12
+ def initialize( *args )
13
+ super
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ string_exception_class:
2
+ _class: SWS::String
3
+ value: exception.class.name
4
+
5
+ string_exception_message:
6
+ _class: SWS::String
7
+ value: exception.to_s
8
+
9
+ repetition_backtrace:
10
+ _class: SWS::Repetition
11
+ list: exception.backtrace
12
+ item: backtrace_cursor
13
+
14
+ string_backtrace_element:
15
+ _class: SWS::String
16
+ value: backtrace_cursor
@@ -0,0 +1,16 @@
1
+ filename:
2
+ settable: true
3
+
4
+ data:
5
+ settable: true
6
+
7
+ content_type:
8
+ settable: true
9
+
10
+ charset:
11
+ settable: true
12
+
13
+ disabled:
14
+ default: false
15
+
16
+ other_tag_string:
@@ -0,0 +1,62 @@
1
+ module SWS
2
+
3
+ # Represents a <INPUT type=file... field HTML tag.
4
+ # Bindings:
5
+ # - filename (settable) - name of the uploaded file
6
+ # - data (settable) - contents of the uploaded file
7
+ # - content_type (settable) - content type of the uploaded file
8
+ # - charset (settable) - charset of the uploaded file
9
+ # - disabled (default: false) - if true, the component will be rendered
10
+ # inactive
11
+ # - other_tag_string - generic string to add to the HTML tag
12
+ class FileUpload < FormElement
13
+
14
+
15
+ # This component cannot be a container, so this method returns false.
16
+ def container? ()
17
+ return false
18
+ end
19
+
20
+
21
+ def process_bindings ()
22
+
23
+ file_data = @parameters["file_data"]
24
+
25
+ if ( file_data )
26
+
27
+ if ( file_data.is_a?( FileData ) )
28
+ if ( slot_bound?( "data" ) ) then @slots["data"].value = file_data.contents end
29
+ # .sub is a workaround for stupid IE behaviour (sending FULL filename
30
+ # path, so the application developer knows exactly where on your disk
31
+ # you took the file from)
32
+ if ( slot_bound?( "filename" ) ) then @slots["filename"].value = file_data.filename.sub( /^.*\\/,"" ) end
33
+ if ( slot_bound?( "content_type" ) ) then @slots["content_type"].value = file_data.content_type end
34
+ if ( slot_bound?( "charset" ) ) then @slots["charset"].value = file_data.charset end
35
+ elsif ( file_data.is_a?( ::String ) )
36
+ @slots["filename"].value = file_data
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+
44
+ def append_to_response ( response )
45
+ response << generate_html()
46
+ end
47
+
48
+
49
+ def generate_html ()
50
+
51
+ string = "<INPUT type=\"file\" name=\"#{element_name()}.file_data\""
52
+ if ( slot_bound?( "disabled" ) && @slots["disabled"].value() == true )
53
+ string << " disabled"
54
+ end
55
+ string << generic_attr_string() << ">"
56
+ return string
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end