sproutcore 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/History.txt +233 -0
  2. data/Manifest.txt +67 -34
  3. data/bin/sc-build +12 -1
  4. data/bin/sc-gen +1 -1
  5. data/bin/sproutcore +14 -0
  6. data/clients/sc_docs/controllers/docs.js +38 -8
  7. data/clients/sc_docs/english.lproj/body.css +80 -127
  8. data/clients/sc_docs/english.lproj/body.rhtml +43 -23
  9. data/clients/sc_docs/english.lproj/no_docs.rhtml +2 -1
  10. data/clients/sc_docs/english.lproj/tabs.rhtml +16 -0
  11. data/clients/sc_docs/main.js +14 -9
  12. data/clients/sc_docs/models/doc.js +1 -1
  13. data/clients/sc_docs/tests/controllers/docs.rhtml +1 -2
  14. data/clients/sc_docs/tests/models/doc.rhtml +1 -2
  15. data/clients/sc_docs/tests/views/doc_frame.rhtml +1 -2
  16. data/clients/sc_docs/tests/views/doc_label_view.rhtml +1 -2
  17. data/clients/sc_docs/views/doc_frame.js +1 -1
  18. data/clients/sc_test_runner/controllers/runner.js +31 -8
  19. data/clients/sc_test_runner/english.lproj/body.css +62 -122
  20. data/clients/sc_test_runner/english.lproj/body.rhtml +62 -26
  21. data/clients/sc_test_runner/main.js +1 -6
  22. data/clients/sc_test_runner/models/test.js +14 -1
  23. data/clients/sc_test_runner/views/runner_frame.js +4 -2
  24. data/clients/view_builder/builders/builder.js +339 -0
  25. data/clients/view_builder/builders/button.js +81 -0
  26. data/clients/view_builder/controllers/document.js +21 -0
  27. data/clients/view_builder/core.js +19 -0
  28. data/clients/view_builder/english.lproj/body.css +77 -0
  29. data/clients/view_builder/english.lproj/body.rhtml +41 -0
  30. data/clients/{sc_docs → view_builder}/english.lproj/controls.css +0 -0
  31. data/clients/view_builder/english.lproj/strings.js +14 -0
  32. data/clients/view_builder/main.js +38 -0
  33. data/clients/view_builder/tests/controllers/document.rhtml +20 -0
  34. data/clients/view_builder/tests/views/builder.rhtml +20 -0
  35. data/clients/view_builder/views/builder.js +23 -0
  36. data/frameworks/prototype/prototype.js +1 -1
  37. data/frameworks/sproutcore/Core.js +32 -7
  38. data/frameworks/sproutcore/README +1 -1
  39. data/frameworks/sproutcore/animation/animation.js +411 -0
  40. data/frameworks/sproutcore/controllers/array.js +17 -9
  41. data/frameworks/sproutcore/controllers/collection.js +9 -110
  42. data/frameworks/sproutcore/controllers/controller.js +1 -1
  43. data/frameworks/sproutcore/controllers/object.js +2 -1
  44. data/frameworks/sproutcore/drag/drag.js +267 -56
  45. data/frameworks/sproutcore/drag/drag_data_source.js +24 -16
  46. data/frameworks/sproutcore/drag/drag_source.js +53 -42
  47. data/frameworks/sproutcore/drag/drop_target.js +2 -2
  48. data/frameworks/sproutcore/english.lproj/buttons.css +337 -236
  49. data/frameworks/sproutcore/english.lproj/core.css +115 -0
  50. data/frameworks/sproutcore/english.lproj/icons.css +227 -0
  51. data/{clients/sc_docs → frameworks/sproutcore}/english.lproj/images/indicator.gif +0 -0
  52. data/frameworks/sproutcore/english.lproj/images/sc-theme-sprite.png +0 -0
  53. data/frameworks/sproutcore/english.lproj/images/sc-theme-ysprite.png +0 -0
  54. data/frameworks/sproutcore/english.lproj/images/shared-icons.png +0 -0
  55. data/frameworks/sproutcore/english.lproj/menu.css +1 -1
  56. data/frameworks/sproutcore/english.lproj/strings.js +1 -1
  57. data/frameworks/sproutcore/english.lproj/theme.css +405 -31
  58. data/frameworks/sproutcore/foundation/application.js +15 -11
  59. data/frameworks/sproutcore/foundation/benchmark.js +1 -1
  60. data/frameworks/sproutcore/foundation/binding.js +2 -2
  61. data/frameworks/sproutcore/foundation/date.js +1 -1
  62. data/frameworks/sproutcore/foundation/error.js +1 -1
  63. data/frameworks/sproutcore/foundation/input_manager.js +32 -21
  64. data/frameworks/sproutcore/foundation/mock.js +1 -1
  65. data/frameworks/sproutcore/foundation/node_descriptor.js +9 -6
  66. data/frameworks/sproutcore/foundation/object.js +249 -177
  67. data/frameworks/sproutcore/foundation/page.js +5 -2
  68. data/frameworks/sproutcore/foundation/path_module.js +11 -10
  69. data/frameworks/sproutcore/foundation/responder.js +5 -2
  70. data/frameworks/sproutcore/foundation/routes.js +17 -13
  71. data/frameworks/sproutcore/foundation/run_loop.js +249 -11
  72. data/frameworks/sproutcore/foundation/server.js +1 -1
  73. data/frameworks/sproutcore/foundation/set.js +3 -3
  74. data/frameworks/sproutcore/foundation/string.js +5 -3
  75. data/frameworks/sproutcore/foundation/timer.js +371 -0
  76. data/frameworks/sproutcore/foundation/undo_manager.js +1 -1
  77. data/frameworks/sproutcore/foundation/unittest.js +3 -3
  78. data/frameworks/sproutcore/foundation/utils.js +161 -2
  79. data/frameworks/sproutcore/globals/panels.js +1 -1
  80. data/frameworks/sproutcore/globals/popups.js +4 -3
  81. data/frameworks/sproutcore/globals/window.js +44 -4
  82. data/frameworks/sproutcore/lib/button_views.rb +328 -0
  83. data/frameworks/sproutcore/lib/collection_view.rb +80 -0
  84. data/frameworks/sproutcore/lib/core_views.rb +281 -0
  85. data/frameworks/sproutcore/lib/form_views.rb +253 -0
  86. data/frameworks/sproutcore/lib/index.rhtml +2 -0
  87. data/frameworks/sproutcore/lib/menu_views.rb +88 -0
  88. data/frameworks/sproutcore/{foundation → mixins}/array.js +60 -29
  89. data/frameworks/sproutcore/mixins/control.js +265 -0
  90. data/frameworks/sproutcore/mixins/delegate_support.js +66 -0
  91. data/frameworks/sproutcore/{foundation → mixins}/observable.js +176 -6
  92. data/frameworks/sproutcore/mixins/scrollable.js +245 -0
  93. data/frameworks/sproutcore/mixins/selection_support.js +148 -0
  94. data/frameworks/sproutcore/mixins/validatable.js +152 -0
  95. data/frameworks/sproutcore/models/collection.js +5 -5
  96. data/frameworks/sproutcore/models/record.js +1 -1
  97. data/frameworks/sproutcore/models/store.js +1 -1
  98. data/frameworks/sproutcore/panes/dialog.js +1 -1
  99. data/frameworks/sproutcore/panes/manager.js +1 -1
  100. data/frameworks/sproutcore/panes/menu.js +1 -1
  101. data/frameworks/sproutcore/panes/overlay.js +2 -2
  102. data/frameworks/sproutcore/panes/panel.js +1 -1
  103. data/frameworks/sproutcore/panes/picker.js +1 -1
  104. data/frameworks/sproutcore/tests/controllers/array.rhtml +44 -4
  105. data/frameworks/sproutcore/tests/foundation/timer/invalidate.rhtml +33 -0
  106. data/frameworks/sproutcore/tests/foundation/timer/invokeLater.rhtml +145 -0
  107. data/frameworks/sproutcore/tests/foundation/timer/isPaused.rhtml +70 -0
  108. data/frameworks/sproutcore/tests/foundation/timer/schedule.rhtml +145 -0
  109. data/frameworks/sproutcore/tests/views/{scroll.rhtml → checkbox.rhtml} +3 -3
  110. data/frameworks/sproutcore/tests/views/{collection.rhtml → collection/base.rhtml} +33 -32
  111. data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +260 -0
  112. data/frameworks/sproutcore/tests/views/image_cell.rhtml +19 -0
  113. data/frameworks/sproutcore/tests/views/label_item.rhtml +2 -4
  114. data/frameworks/sproutcore/tests/views/list.rhtml +2 -3
  115. data/frameworks/sproutcore/tests/views/list_item.rhtml +20 -0
  116. data/frameworks/sproutcore/tests/views/slider.rhtml +20 -0
  117. data/frameworks/sproutcore/tests/views/text_cell.rhtml +19 -0
  118. data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +395 -0
  119. data/frameworks/sproutcore/tests/views/view/frame.rhtml +353 -0
  120. data/frameworks/sproutcore/tests/views/view/innerFrame.rhtml +347 -0
  121. data/frameworks/sproutcore/tests/views/view/isVisibleInWindow.rhtml +148 -0
  122. data/frameworks/sproutcore/tests/views/view/scrollFrame.rhtml +468 -0
  123. data/frameworks/sproutcore/validators/credit_card.js +33 -13
  124. data/frameworks/sproutcore/validators/date.js +26 -6
  125. data/frameworks/sproutcore/validators/email.js +21 -3
  126. data/frameworks/sproutcore/validators/not_empty.js +11 -1
  127. data/frameworks/sproutcore/validators/number.js +18 -4
  128. data/frameworks/sproutcore/validators/password.js +12 -1
  129. data/frameworks/sproutcore/validators/validator.js +204 -194
  130. data/frameworks/sproutcore/views/{button.js → button/button.js} +96 -94
  131. data/frameworks/sproutcore/views/button/checkbox.js +29 -0
  132. data/frameworks/sproutcore/views/button/disclosure.js +42 -0
  133. data/frameworks/sproutcore/views/button/radio.js +29 -0
  134. data/frameworks/sproutcore/views/{collection.js → collection/collection.js} +1373 -1024
  135. data/frameworks/sproutcore/views/collection/grid.js +124 -46
  136. data/frameworks/sproutcore/views/collection/image_cell.js +17 -46
  137. data/frameworks/sproutcore/views/collection/list.js +45 -35
  138. data/frameworks/sproutcore/views/collection/source_list.js +386 -0
  139. data/frameworks/sproutcore/views/collection/table.js +118 -0
  140. data/frameworks/sproutcore/views/container.js +7 -2
  141. data/frameworks/sproutcore/views/error_explanation.js +23 -10
  142. data/frameworks/sproutcore/views/{checkbox_field.js → field/checkbox_field.js} +16 -6
  143. data/frameworks/sproutcore/views/field/field.js +219 -0
  144. data/frameworks/sproutcore/views/{radio_field.js → field/radio_field.js} +27 -12
  145. data/frameworks/sproutcore/views/{select_field.js → field/select_field.js} +116 -90
  146. data/frameworks/sproutcore/views/{text_field.js → field/text_field.js} +57 -8
  147. data/frameworks/sproutcore/views/{textarea_field.js → field/textarea_field.js} +13 -3
  148. data/frameworks/sproutcore/views/filter_button.js +2 -2
  149. data/frameworks/sproutcore/views/form.js +3 -3
  150. data/frameworks/sproutcore/views/image.js +128 -21
  151. data/frameworks/sproutcore/views/inline_text_editor.js +1 -1
  152. data/frameworks/sproutcore/views/label.js +149 -92
  153. data/frameworks/sproutcore/views/list_item.js +225 -0
  154. data/frameworks/sproutcore/views/menu_item.js +10 -4
  155. data/frameworks/sproutcore/views/pagination.js +11 -4
  156. data/frameworks/sproutcore/views/popup_button.js +25 -21
  157. data/frameworks/sproutcore/views/popup_menu.js +10 -4
  158. data/frameworks/sproutcore/views/progress.js +29 -16
  159. data/frameworks/sproutcore/views/radio_group.js +1 -1
  160. data/frameworks/sproutcore/views/scroll.js +60 -20
  161. data/frameworks/sproutcore/views/segmented.js +1 -1
  162. data/frameworks/sproutcore/views/slider.js +132 -0
  163. data/frameworks/sproutcore/views/source_list_group.js +130 -0
  164. data/frameworks/sproutcore/views/spinner.js +1 -1
  165. data/frameworks/sproutcore/views/split.js +292 -0
  166. data/frameworks/sproutcore/views/split_divider.js +109 -0
  167. data/frameworks/sproutcore/views/tab.js +1 -1
  168. data/frameworks/sproutcore/views/toolbar.js +1 -1
  169. data/frameworks/sproutcore/views/view.js +1272 -591
  170. data/generators/client/templates/english.lproj/body.css +1 -1
  171. data/generators/controller/controller_generator.rb +1 -1
  172. data/generators/controller/templates/test.rhtml +2 -1
  173. data/generators/model/templates/test.rhtml +1 -1
  174. data/generators/test/templates/test.rhtml +1 -1
  175. data/generators/view/templates/test.rhtml +1 -1
  176. data/jsdoc/templates/sproutcore/class.tmpl +241 -338
  177. data/jsdoc/templates/sproutcore/default.css +105 -155
  178. data/jsdoc/templates/sproutcore/index.tmpl +43 -8
  179. data/jsdoc/templates/sproutcore/publish.js +9 -4
  180. data/lib/sproutcore/build_tools/html_builder.rb +29 -13
  181. data/lib/sproutcore/build_tools/resource_builder.rb +1 -1
  182. data/lib/sproutcore/bundle.rb +86 -25
  183. data/lib/sproutcore/jsdoc.rb +2 -0
  184. data/lib/sproutcore/version.rb +1 -1
  185. data/lib/sproutcore/view_helpers.rb +36 -3
  186. data/tasks/deployment.rake +1 -1
  187. metadata +69 -36
  188. data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
  189. data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
  190. data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
  191. data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
  192. data/clients/sc_docs/english.lproj/warning.rhtml +0 -6
  193. data/clients/sc_test_runner/english.lproj/warning.rhtml +0 -6
  194. data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
  195. data/frameworks/sproutcore/english.lproj/collections.css +0 -82
  196. data/frameworks/sproutcore/english.lproj/images/buttons-sprite.png +0 -0
  197. data/frameworks/sproutcore/views/collection/collection_item.js +0 -36
  198. data/frameworks/sproutcore/views/collection/text_cell.js +0 -128
  199. data/frameworks/sproutcore/views/field.js +0 -214
  200. data/frameworks/sproutcore/views/workspace.js +0 -170
  201. data/generators/client/templates/english.lproj/controls.css +0 -0
  202. data/generators/framework/templates/english.lproj/body.css +0 -0
  203. data/generators/framework/templates/english.lproj/body.rhtml +0 -3
  204. data/generators/framework/templates/english.lproj/controls.css +0 -0
  205. data/lib/sproutcore/view_helpers/button_views.rb +0 -302
  206. data/lib/sproutcore/view_helpers/core_views.rb +0 -292
  207. data/lib/sproutcore/view_helpers/form_views.rb +0 -258
  208. data/lib/sproutcore/view_helpers/menu_views.rb +0 -94
@@ -0,0 +1,281 @@
1
+ ############################################################
2
+ # CORE VIEW HELPERS
3
+ # These view helpers create simple views based on the options
4
+ # you pass in. More complex components can be found in the
5
+ # view_kit.
6
+
7
+ # Render an SC.View. This is also the base for all other view helpers.
8
+ #
9
+ # :tag the wrapper tag. default: 'div'
10
+ # :class css class names. maybe a string or array.
11
+ # :panel if true, view will display as a panel. default: false
12
+ # :visible (bindable) if false, view will be hidden on page load.
13
+ # default: true
14
+ #
15
+ view_helper :view do
16
+ var :inner_html
17
+ var :tag, 'div'
18
+ var :panel, false
19
+ var :animate
20
+
21
+ # passing in :field is like passing in :outlet but it also adds a
22
+ # property called fieldType
23
+ var :field
24
+ if @field
25
+ @outlet = "#{@field.to_s}_field"
26
+ property :field_key, @field.to_s.camelize(:lower), :constant => true
27
+ end
28
+
29
+ attribute :title
30
+
31
+ # there are some standard JS properties
32
+ bind :enabled, :key => 'isEnabled'
33
+ bind :visible, :key => 'isVisible'
34
+
35
+ property :enabled, :key => 'isEnabled'
36
+ property :modal, :key => 'isModal'
37
+ property :custom_panel, :key => 'hasCustomPanelWrapper'
38
+ property :localize
39
+ property :validator
40
+ property :field_label
41
+ property :accepts_first_responder
42
+ property :content
43
+ property :value
44
+ property :content_value_key
45
+
46
+ # For SC.SplitView support
47
+ property :max_thickness
48
+ property :min_thickness
49
+ property :can_collapse
50
+ property :collapsed, :key => 'isCollapsed'
51
+
52
+
53
+ # set panel type
54
+ var :panel
55
+ var :dialog
56
+ var :picker
57
+ pane_def = (@panel) ? 'panel' : (@dialog ? 'dialog' : (@picker ? 'picker' : nil))
58
+ if pane_def.nil?
59
+ property :pane, :key => 'paneType'
60
+ else
61
+ property :pane, pane_def, :key => 'paneType'
62
+ end
63
+
64
+ # pass in a hash of properties and they will be added to the JS:
65
+ # :properties => { :prop_a => '1', :prop_b => '2' }
66
+ var :properties
67
+ if @properties
68
+ @properties.each { | k, v | property(k,v) { |b| b } }
69
+ end
70
+
71
+ if @animate
72
+ property :visible_animation, '', :constant => true do
73
+ key_map = { 'complete' => 'onComplete' }
74
+ animation_values = @animate.map do | k,v |
75
+ normalized_key = k.to_s.downcase
76
+ unless ['complete'].include?(normalized_key)
77
+ v = prepare_for_javascript(v)
78
+ end
79
+ k = key_map[normalized_key] || k
80
+ "#{k}: #{v}"
81
+ end
82
+ %({ #{ animation_values * ',' } })
83
+ end
84
+ end
85
+
86
+ view('SC.View') { properties }
87
+
88
+ # deal with css classnames and styles.
89
+ # Note that you can append either arrays or single strings or symbols
90
+ # here. When the class names and styles are combined the ary will be
91
+ # flattened
92
+ var :class, :key => :class_names
93
+ css_class_names << @class_names if @class_names
94
+
95
+ var :enabled, true
96
+ css_class_names << 'disabled' if @enabled == false
97
+
98
+ var :style
99
+ css_styles << @style unless @style.nil?
100
+
101
+ # Standard CSS attributes you can pass as attributes to standard view helpers.
102
+ common_css_keys = [:width, :height, :min_height, :max_height, :min_width, :max_width]
103
+
104
+ common_css_keys.each do | key |
105
+ value = var key
106
+ if value
107
+ value = "#{value.to_i}px" if value.kind_of?(Numeric)
108
+ key = key.to_s.gsub('_','-')
109
+ css_styles << "#{key}: #{value};"
110
+ end
111
+ end
112
+
113
+ # render the basic content
114
+ content { (@tag == 'img') ? ot : %(#{ot}#{@inner_html}#{ct}) }
115
+
116
+ end
117
+
118
+ # Render an SC.LabelView. Inherits from SC.View
119
+ #
120
+ # :formatter Name of a formatter.
121
+ # :localize (bindable) localize string
122
+ # :escape_html (bindable) escapeHTML property
123
+ view_helper :label_view do
124
+ property(:formatter) { |v| v }
125
+ property :localize, false
126
+ property :escape_html, true, :key => 'escapeHTML'
127
+
128
+ var :label, nil
129
+ view 'SC.LabelView'
130
+
131
+ css_class_names << 'sc-label-view'
132
+ @inner_html = @label unless @label.nil?
133
+ end
134
+
135
+ # Render an SC.SpinnerView. Inherits from SC.View. You should bind
136
+ # :visible usually.
137
+ #
138
+ # :src Set the src of the spinner img. Defaults to
139
+ # "/images/spinner.gif"
140
+ view_helper :spinner_view do
141
+ var :form, false
142
+ var :src, '/images/spinner.gif'
143
+
144
+ view 'SC.SpinnerView'
145
+ if @form
146
+ bind(:visible, ".owner.isCommitting", :key => 'isVisible')
147
+ self.outlet = 'commitSpinner'
148
+ end
149
+
150
+ unless @inner_html
151
+ @inner_html = %(<img src="#{@src}" />)
152
+ end
153
+ attribute :class, 'spinner'
154
+
155
+ end
156
+
157
+ # Renders an SC.ProgressView. Includes the default HTML structure.
158
+ #
159
+ # :enabled (bindable) isEnabled property
160
+ # :indeterminate (bindable) isIndeterminate property
161
+ # :value (bindable) default value - float
162
+ # :maximum (bindable) maximum value - float
163
+ # :minimum (bindable) minimum value - float
164
+ view_helper :progress_view do
165
+ property :enabled, :key => 'isEnabled'
166
+ property :indeterminate, :key => 'isIndeterminate'
167
+ property :value
168
+ property :maximum
169
+ property :minimum
170
+ view 'SC.ProgressView'
171
+
172
+ attribute :class, 'progress outer'
173
+ unless @inner_html
174
+ @inner_html = <<EOF
175
+ <div class="outer-head"></div>
176
+ <div class="inner">
177
+ <div class="inner-head"></div>
178
+ <div class="inner-tail"></div>
179
+ </div>
180
+ <div class="outer-tail"></div>
181
+ EOF
182
+ end
183
+ end
184
+
185
+ view_helper :image_view do
186
+ view 'SC.ImageView'
187
+ property :content
188
+ property :value
189
+
190
+ var :tag, 'img'
191
+ css_class_names << 'sc-image-view'
192
+ end
193
+
194
+ view_helper :container_view do
195
+ view 'SC.ContainerView'
196
+ property :content
197
+ end
198
+
199
+ view_helper :scroll_view do
200
+ view 'SC.ScrollView'
201
+ css_class_names << 'sc-scroll-view'
202
+ end
203
+
204
+ view_helper :segmented_view do
205
+ property :value
206
+ property :selection, :key => 'value'
207
+ property :enabled, :key => 'isEnabled'
208
+ property :allows_empty_selection
209
+
210
+ # :segments should contains an array of symbols or a hash of
211
+ # key => name pairs to be used to render the segment. Or you can
212
+ # just create your own button views.
213
+ var :segments
214
+ var :theme, 'regular'
215
+ if @segments
216
+ @segments = [@segments].flatten unless @segments.instance_of?(Array)
217
+ result = []
218
+ first = true
219
+ while seg = @segments.shift
220
+ class_names = [@theme,'segment']
221
+ class_names << ((first) ? 'segment-left' : ((@segments.size == 0) ? 'segment-right' : 'segment-inner'))
222
+ first = false
223
+
224
+ seg = [seg].flatten
225
+ key = seg.first || ''
226
+ label = seg.size > 1 ? seg.last : key.to_s.humanize.split.map { |x| x.capitalize }.join(' ')
227
+
228
+ result << render_source.button_view(:outlet => "#{key}_button", :label => label, :tag => 'a', :class => class_names )
229
+ end
230
+ @inner_html = result * ''
231
+ end
232
+
233
+ view 'SC.SegmentedView'
234
+ css_class_names << 'segments'
235
+
236
+ end
237
+
238
+ # Renders an SC.TabView. Name outlets you want flipped *_tab
239
+ # If you want, you can also pass a set of segments to be displayed
240
+ # above the tab view
241
+ view_helper :tab_view do
242
+ var :segments
243
+
244
+ property :now_showing
245
+ property :lazy_tabs
246
+
247
+ view 'SC.TabView'
248
+ css_class_names << "tab"
249
+
250
+ if @segments
251
+ # if this tab view has segments automatically attached, add class
252
+ # name.
253
+ css_class_names << 'segmented'
254
+ result = []
255
+ result << render_source.segmented_view(:outlet => :segmented_view, :segments => @segments, :bind => { :value => '*owner.nowShowing' })
256
+ result << render_source.view({:outlet => :root_view, :class => 'root'})
257
+ @inner_html = [(result * ""), %(<div style="display:none;">), (@inner_html || ''), %(</div>)] * ""
258
+ end
259
+
260
+ end
261
+
262
+ view_helper :scroll_view do
263
+ view 'SC.ScrollView'
264
+ css_class_names << 'sc-scroll-view'
265
+ end
266
+
267
+ view_helper :split_view do
268
+ view 'SC.SplitView'
269
+ property :direction, :key => 'layoutDirection'
270
+ property :can_collapse_views
271
+
272
+ var :direction, 'horizontal'
273
+ css_class_names << 'sc-split-view'
274
+ css_class_names << @direction
275
+ end
276
+
277
+ view_helper :split_divider_view do
278
+ view 'SC.SplitDividerView'
279
+ css_class_names << 'sc-split-divider-view'
280
+ end
281
+
@@ -0,0 +1,253 @@
1
+ ############################################################
2
+ # FORM VIEW HELPERS
3
+ #
4
+ # These view helpers make it easy to create input forms. You should wrap
5
+ # your form in the form_view tag and include your fields inside.
6
+ #
7
+
8
+ require_helpers 'core_views'
9
+
10
+ # Defines a form view. Note that you can make this form into a panel
11
+ # by passing :panel => true
12
+ view_helper :form_view do
13
+
14
+ property :content
15
+ property :enabled, :key => 'isEnabled'
16
+ property :valid, :key => 'isValid'
17
+ property :commiting, :key => 'isCommitting'
18
+ property :dirty, :key => 'isDirty'
19
+ property :errors
20
+ property :error_count, :key => 'errorCount'
21
+ property :autocommit
22
+ property :prompt, :key => 'commitPrompt'
23
+ view 'SC.FormView'
24
+
25
+ attribute :action, ''
26
+ attribute :method, 'post'
27
+ var :tag, 'form'
28
+ end
29
+
30
+ view_helper :error_explanation_view do
31
+
32
+ # JavaScript
33
+ view 'SC.ErrorExplanationView'
34
+
35
+ # HTML
36
+ var :tag, 'ul'
37
+ css_class_names << 'errors'
38
+ end
39
+
40
+ view_helper :checkbox_field_view do
41
+
42
+ # JavaScript
43
+ property :value
44
+ property :enabled, :key => 'isEnabled'
45
+ view 'SC.CheckboxFieldView'
46
+
47
+ # HTML
48
+ var :tag, 'input'
49
+ var :label
50
+
51
+ attribute :type, 'checkbox'
52
+ attribute :name, @item_id
53
+
54
+ # if a label is passed, then wrap the checkbox in a label tag and
55
+ # place the label text next to it.
56
+ if @label
57
+ content { %(<label><#{@tag} #{attributes} /> <span class="label">#{@label}</span></label>) }
58
+ else
59
+ content { "<#{@tag} #{attributes} />" }
60
+ end
61
+ end
62
+
63
+ # This renders a list of radio buttons.
64
+ #
65
+ # :values => [REQ]
66
+ # Set this to the values you want displayed in the radio buttons. You
67
+ # can pass an array here of strings or symbols, in which case these will
68
+ # be used as the values for the buttons and the names will be created
69
+ # from them. Or you can pass an array of arrays. The first items is
70
+ # the key value, the second item is the human readable value.
71
+ #
72
+ # :layout => :horizontal | :vertical
73
+ # This will write out horizontal or vertical to the CSS class names so
74
+ # you can control the layout of your radio buttons.
75
+ #
76
+ # :width =>
77
+ # This will set the width of each item in the view.
78
+ #
79
+ # BINDABLE OPTIONS
80
+ #
81
+ # :objects =>
82
+ # This can point to a hash of objects which will be used to convert the
83
+ # key values you set into JS objects.
84
+ #
85
+ # :value =>
86
+ # The current value of the radio buttons.
87
+ #
88
+ view_helper :radio_field_view do
89
+
90
+ #JavaScript
91
+ bind :objects
92
+ property :value
93
+ view 'SC.RadioFieldView'
94
+
95
+ # HTML
96
+
97
+ # Get the width styles out of the main style to put into the individual
98
+ # radio items.
99
+ css_styles.flatten!
100
+ @label_styles = css_styles.reject { |p| !(p =~ /width:/) }
101
+ css_styles.reject! { |p| @label_styles.include?(p) }
102
+
103
+ if @label_styles.size > 0
104
+ @label_styles = %( style="#{@label_styles * ' '}" )
105
+ else
106
+ @label_styles = ''
107
+ end
108
+
109
+ # get the layout mode.
110
+ var :layout, :vertical
111
+ css_class_names << 'radio' # default class
112
+ css_class_names << @layout if @layout
113
+
114
+ var :tag, 'div'
115
+
116
+ # generate the inner-html
117
+ var :values
118
+ html = @values.map do | v |
119
+ v = [v].flatten
120
+ key = v.first
121
+ label = (v.size > 1) ? v[1] : key.to_s.humanize
122
+ %(<label><input type="radio" name="#{item_id}" value="#{key}" #{@label_styles} /><span class="label">#{label}</span></label>)
123
+ end
124
+ @inner_html = html * "\n"
125
+
126
+ end
127
+
128
+
129
+
130
+ view_helper :text_field_view do
131
+ var :tag, 'input'
132
+
133
+ view 'SC.TextFieldView'
134
+ property :field_value
135
+ property :value, :key => :field_value
136
+ property :hint
137
+ property :validate, :key => :validator
138
+ property :label, :key => 'fieldLabel'
139
+
140
+ attribute :size
141
+ attribute :type, 'text'
142
+ attribute :label
143
+ attribute :name
144
+ content { "<#{@tag} #{attributes} />" }
145
+ end
146
+
147
+ view_helper :password_field_view, :extends => :text_field_view do
148
+ attribute :type, 'password'
149
+ end
150
+
151
+ view_helper :text_area_view do
152
+ var :form, false
153
+ var :tag, 'textarea'
154
+ var :value, @inner_html
155
+
156
+ if @form
157
+ view nil
158
+ else
159
+ view 'SC.TextareaFieldView'
160
+ property :hint
161
+ property :field_value
162
+ property :value
163
+ end
164
+
165
+ attribute :cols
166
+ attribute :rows
167
+ attribute :validate
168
+ attribute :label
169
+ attribute :name
170
+ attribute :form, :key => :name
171
+ content { "#{ot}#{@value}#{ct}" }
172
+ end
173
+
174
+ # This view renders a browser-native popup menu.
175
+ #
176
+ # :field =>
177
+ # pass a name to make this part of the enclosing form.
178
+ #
179
+ # :options =>
180
+ # This will statically generate the HTML for the options menu. The
181
+ # value of this property should be an array of items containing strings
182
+ # or symbols, which will form both the item names and values or you can
183
+ # pass an array of arrays. The first item should be the value of the
184
+ # object, then second item should be the name of the menu.
185
+ #
186
+ # Note that if you bind to the :objects property, then that binding
187
+ # will override this code.
188
+ #
189
+ # :name_key =>
190
+ # Specifies the key to use to get the name of a menu item from the
191
+ # array of objects. This is only used if the menu items are generated
192
+ # dynamically.
193
+ #
194
+ # :sort_key =>
195
+ # Optional sort key to use to order the menu. If the sort key is not
196
+ # passed, the name of the menu items will be used. This is only used
197
+ # if the menu items are generated dynamically.
198
+ #
199
+ # :value_key =>
200
+ # Optional key used to get the value for each menu item from the
201
+ # array of objects. Only used if the menu items are generated
202
+ # dynamically.
203
+ #
204
+ # :empty =>
205
+ # Optional. Pass the string name of the "Empty" menu item. This item
206
+ # will appear at the top of the menu and its value will be a null
207
+ # object. The value you pass here will be localized by default. Only
208
+ # used if the menu items are generated dynamically.
209
+ #
210
+ # :localize =>
211
+ # Optional. If true, the names of the menu items and the empty menu
212
+ # item will be passed through the localization system. Defaults to
213
+ # false.
214
+ #
215
+ # :validator =>
216
+ # Optional. Pass the name of a validator and it will be used for this
217
+ # control.
218
+ #
219
+ # BINDABLE PROPERTIES
220
+ #
221
+ # :objects =>
222
+ # bind to an array of objects used to generate the menu item. This will
223
+ # override any hard-coded options you pass through the :options param.
224
+ #
225
+ # :value =>
226
+ # bind to the current value to show in the pop-up menu.
227
+ #
228
+ # :enabled =>
229
+ # bind or pass to set the control to enabled or disabled.
230
+ #
231
+ view_helper :select_field_view do
232
+ # JavaScript
233
+ property :name_key
234
+ property :sort_key
235
+ property :value_key
236
+ property :empty, :key => 'emptyName'
237
+ property :enabled, :key => 'isEnabled'
238
+ bind :objects
239
+ view 'SC.SelectFieldView'
240
+
241
+ # HTML
242
+ var :tag, 'select'
243
+ var :options
244
+ if @options
245
+ html = @options.map do |opt|
246
+ opt = [opt].flatten
247
+ key = opt.first
248
+ name = (opt.size > 1) ? opt[1] : key.to_s.titleize
249
+ %(<option value="#{key}">#{name}</option>)
250
+ end
251
+ @inner_html = html * "\n"
252
+ end
253
+ end