sproutcore 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +269 -0
  4. data/README.txt +67 -0
  5. data/Rakefile +4 -0
  6. data/app_generators/sproutcore/USAGE +5 -0
  7. data/app_generators/sproutcore/sproutcore_generator.rb +66 -0
  8. data/app_generators/sproutcore/templates/README +77 -0
  9. data/app_generators/sproutcore/templates/environment.yml +4 -0
  10. data/bin/sc-build +145 -0
  11. data/bin/sc-gen +24 -0
  12. data/bin/sc-server +63 -0
  13. data/bin/sproutcore +21 -0
  14. data/clients/sc_docs/controllers/docs.js +118 -0
  15. data/clients/sc_docs/core.js +19 -0
  16. data/clients/sc_docs/english.lproj/body.css +159 -0
  17. data/clients/sc_docs/english.lproj/body.rhtml +33 -0
  18. data/clients/sc_docs/english.lproj/controls.css +0 -0
  19. data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
  20. data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
  21. data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
  22. data/clients/sc_docs/english.lproj/images/indicator.gif +0 -0
  23. data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
  24. data/clients/sc_docs/english.lproj/no_docs.rhtml +7 -0
  25. data/clients/sc_docs/english.lproj/strings.js +14 -0
  26. data/clients/sc_docs/english.lproj/warning.rhtml +6 -0
  27. data/clients/sc_docs/fixtures/doc.js +11 -0
  28. data/clients/sc_docs/main.js +21 -0
  29. data/clients/sc_docs/models/doc.js +9 -0
  30. data/clients/sc_docs/tests/controllers/docs.rhtml +21 -0
  31. data/clients/sc_docs/tests/models/doc.rhtml +21 -0
  32. data/clients/sc_docs/tests/views/doc_frame.rhtml +21 -0
  33. data/clients/sc_docs/tests/views/doc_label_view.rhtml +21 -0
  34. data/clients/sc_docs/views/doc_frame.js +33 -0
  35. data/clients/sc_docs/views/doc_label.js +20 -0
  36. data/clients/sc_test_runner/controllers/runner.js +175 -0
  37. data/clients/sc_test_runner/core.js +19 -0
  38. data/clients/sc_test_runner/english.lproj/body.css +151 -0
  39. data/clients/sc_test_runner/english.lproj/body.rhtml +35 -0
  40. data/clients/sc_test_runner/english.lproj/controls.css +0 -0
  41. data/clients/sc_test_runner/english.lproj/icons/small/next.png +0 -0
  42. data/clients/sc_test_runner/english.lproj/icons/small/reset.png +0 -0
  43. data/clients/sc_test_runner/english.lproj/images/gradients.png +0 -0
  44. data/clients/sc_test_runner/english.lproj/images/indicator.gif +0 -0
  45. data/clients/sc_test_runner/english.lproj/images/toolbar.png +0 -0
  46. data/clients/sc_test_runner/english.lproj/no_tests.rhtml +6 -0
  47. data/clients/sc_test_runner/english.lproj/strings.js +14 -0
  48. data/clients/sc_test_runner/english.lproj/warning.rhtml +6 -0
  49. data/clients/sc_test_runner/fixtures/test.js +12 -0
  50. data/clients/sc_test_runner/main.js +26 -0
  51. data/clients/sc_test_runner/models/test.js +11 -0
  52. data/clients/sc_test_runner/views/runner_frame.js +72 -0
  53. data/clients/sc_test_runner/views/test_label.js +20 -0
  54. data/config/hoe.rb +70 -0
  55. data/config/requirements.rb +17 -0
  56. data/environment.yml +9 -0
  57. data/frameworks/prototype/prototype.js +4186 -0
  58. data/frameworks/sproutcore/Core.js +378 -0
  59. data/frameworks/sproutcore/README +3 -0
  60. data/frameworks/sproutcore/controllers/array.js +236 -0
  61. data/frameworks/sproutcore/controllers/collection.js +305 -0
  62. data/frameworks/sproutcore/controllers/controller.js +323 -0
  63. data/frameworks/sproutcore/controllers/object.js +372 -0
  64. data/frameworks/sproutcore/drag/drag.js +549 -0
  65. data/frameworks/sproutcore/drag/drag_data_source.js +32 -0
  66. data/frameworks/sproutcore/drag/drag_source.js +64 -0
  67. data/frameworks/sproutcore/drag/drop_target.js +153 -0
  68. data/frameworks/sproutcore/english.lproj/blank.gif +0 -0
  69. data/frameworks/sproutcore/english.lproj/buttons.css +589 -0
  70. data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
  71. data/frameworks/sproutcore/english.lproj/inline_text_editor.css +21 -0
  72. data/frameworks/sproutcore/english.lproj/menu.css +121 -0
  73. data/frameworks/sproutcore/english.lproj/panels/background-fat.jpg +0 -0
  74. data/frameworks/sproutcore/english.lproj/panels/background-thin.jpg +0 -0
  75. data/frameworks/sproutcore/english.lproj/panels/bottom-edge.png +0 -0
  76. data/frameworks/sproutcore/english.lproj/panels/bottom-left-corner.png +0 -0
  77. data/frameworks/sproutcore/english.lproj/panels/bottom-right-corner.png +0 -0
  78. data/frameworks/sproutcore/english.lproj/panels/left-edge.png +0 -0
  79. data/frameworks/sproutcore/english.lproj/panels/overlay.png +0 -0
  80. data/frameworks/sproutcore/english.lproj/panels/right-edge.png +0 -0
  81. data/frameworks/sproutcore/english.lproj/panels/top-edge.png +0 -0
  82. data/frameworks/sproutcore/english.lproj/panels/top-left-corner.png +0 -0
  83. data/frameworks/sproutcore/english.lproj/panels/top-right-corner.png +0 -0
  84. data/frameworks/sproutcore/english.lproj/panes.css +155 -0
  85. data/frameworks/sproutcore/english.lproj/picker.css +22 -0
  86. data/frameworks/sproutcore/english.lproj/strings.js +15 -0
  87. data/frameworks/sproutcore/english.lproj/tab.css +23 -0
  88. data/frameworks/sproutcore/english.lproj/tests.css +67 -0
  89. data/frameworks/sproutcore/english.lproj/theme.css +77 -0
  90. data/frameworks/sproutcore/foundation/animator.js +670 -0
  91. data/frameworks/sproutcore/foundation/application.js +199 -0
  92. data/frameworks/sproutcore/foundation/array.js +348 -0
  93. data/frameworks/sproutcore/foundation/benchmark.js +211 -0
  94. data/frameworks/sproutcore/foundation/binding.js +384 -0
  95. data/frameworks/sproutcore/foundation/date.js +357 -0
  96. data/frameworks/sproutcore/foundation/error.js +39 -0
  97. data/frameworks/sproutcore/foundation/input_manager.js +153 -0
  98. data/frameworks/sproutcore/foundation/json.js +296 -0
  99. data/frameworks/sproutcore/foundation/mock.js +42 -0
  100. data/frameworks/sproutcore/foundation/node_descriptor.js +56 -0
  101. data/frameworks/sproutcore/foundation/object.js +777 -0
  102. data/frameworks/sproutcore/foundation/observable.js +451 -0
  103. data/frameworks/sproutcore/foundation/page.js +63 -0
  104. data/frameworks/sproutcore/foundation/path_module.js +413 -0
  105. data/frameworks/sproutcore/foundation/responder.js +310 -0
  106. data/frameworks/sproutcore/foundation/routes.js +371 -0
  107. data/frameworks/sproutcore/foundation/run_loop.js +21 -0
  108. data/frameworks/sproutcore/foundation/server.js +491 -0
  109. data/frameworks/sproutcore/foundation/set.js +96 -0
  110. data/frameworks/sproutcore/foundation/string.js +149 -0
  111. data/frameworks/sproutcore/foundation/undo_manager.js +186 -0
  112. data/frameworks/sproutcore/foundation/unittest.js +622 -0
  113. data/frameworks/sproutcore/foundation/utils.js +61 -0
  114. data/frameworks/sproutcore/globals/panels.js +182 -0
  115. data/frameworks/sproutcore/globals/popups.js +60 -0
  116. data/frameworks/sproutcore/globals/window.js +381 -0
  117. data/frameworks/sproutcore/lib/index.rhtml +66 -0
  118. data/frameworks/sproutcore/models/collection.js +395 -0
  119. data/frameworks/sproutcore/models/record.js +622 -0
  120. data/frameworks/sproutcore/models/store.js +295 -0
  121. data/frameworks/sproutcore/panes/dialog.js +16 -0
  122. data/frameworks/sproutcore/panes/manager.js +164 -0
  123. data/frameworks/sproutcore/panes/menu.js +45 -0
  124. data/frameworks/sproutcore/panes/overlay.js +231 -0
  125. data/frameworks/sproutcore/panes/pane.js +90 -0
  126. data/frameworks/sproutcore/panes/panel.js +19 -0
  127. data/frameworks/sproutcore/panes/picker.js +45 -0
  128. data/frameworks/sproutcore/tests/controllers/array.rhtml +86 -0
  129. data/frameworks/sproutcore/tests/controllers/controller.rhtml +273 -0
  130. data/frameworks/sproutcore/tests/controllers/object.rhtml +327 -0
  131. data/frameworks/sproutcore/tests/foundation/application.rhtml +125 -0
  132. data/frameworks/sproutcore/tests/foundation/array.rhtml +221 -0
  133. data/frameworks/sproutcore/tests/foundation/object.rhtml +69 -0
  134. data/frameworks/sproutcore/tests/globals/window.rhtml +45 -0
  135. data/frameworks/sproutcore/tests/panes/pane.rhtml +88 -0
  136. data/frameworks/sproutcore/tests/views/collection.rhtml +137 -0
  137. data/frameworks/sproutcore/tests/views/popup_button.rhtml +115 -0
  138. data/frameworks/sproutcore/tests/views/text_field.rhtml +37 -0
  139. data/frameworks/sproutcore/validators/credit_card.js +92 -0
  140. data/frameworks/sproutcore/validators/date.js +36 -0
  141. data/frameworks/sproutcore/validators/email.js +29 -0
  142. data/frameworks/sproutcore/validators/not_empty.js +24 -0
  143. data/frameworks/sproutcore/validators/number.js +55 -0
  144. data/frameworks/sproutcore/validators/password.js +78 -0
  145. data/frameworks/sproutcore/validators/validator.js +304 -0
  146. data/frameworks/sproutcore/views/button.js +425 -0
  147. data/frameworks/sproutcore/views/checkbox_field.js +30 -0
  148. data/frameworks/sproutcore/views/collection.js +1521 -0
  149. data/frameworks/sproutcore/views/container.js +62 -0
  150. data/frameworks/sproutcore/views/error_explanation.js +45 -0
  151. data/frameworks/sproutcore/views/field.js +214 -0
  152. data/frameworks/sproutcore/views/filter_button.js +29 -0
  153. data/frameworks/sproutcore/views/form.js +591 -0
  154. data/frameworks/sproutcore/views/image.js +141 -0
  155. data/frameworks/sproutcore/views/inline_text_editor.js +96 -0
  156. data/frameworks/sproutcore/views/label.js +176 -0
  157. data/frameworks/sproutcore/views/menu_item.js +90 -0
  158. data/frameworks/sproutcore/views/pagination.js +54 -0
  159. data/frameworks/sproutcore/views/popup_button.js +86 -0
  160. data/frameworks/sproutcore/views/popup_menu.js +137 -0
  161. data/frameworks/sproutcore/views/progress.js +100 -0
  162. data/frameworks/sproutcore/views/radio_field.js +107 -0
  163. data/frameworks/sproutcore/views/radio_group.js +48 -0
  164. data/frameworks/sproutcore/views/segmented.js +80 -0
  165. data/frameworks/sproutcore/views/select_field.js +272 -0
  166. data/frameworks/sproutcore/views/spinner.js +11 -0
  167. data/frameworks/sproutcore/views/tab.js +126 -0
  168. data/frameworks/sproutcore/views/text_field.js +179 -0
  169. data/frameworks/sproutcore/views/textarea_field.js +14 -0
  170. data/frameworks/sproutcore/views/toolbar.js +29 -0
  171. data/frameworks/sproutcore/views/view.js +1389 -0
  172. data/frameworks/sproutcore/views/workspace.js +170 -0
  173. data/generators/client/README +3 -0
  174. data/generators/client/USAGE +12 -0
  175. data/generators/client/client_generator.rb +53 -0
  176. data/generators/client/templates/core.js +19 -0
  177. data/generators/client/templates/english.lproj/body.css +0 -0
  178. data/generators/client/templates/english.lproj/body.rhtml +3 -0
  179. data/generators/client/templates/english.lproj/controls.css +0 -0
  180. data/generators/client/templates/english.lproj/strings.js +14 -0
  181. data/generators/client/templates/main.js +37 -0
  182. data/generators/controller/USAGE +16 -0
  183. data/generators/controller/controller_generator.rb +51 -0
  184. data/generators/controller/templates/controller.js +21 -0
  185. data/generators/controller/templates/test.rhtml +21 -0
  186. data/generators/framework/README +7 -0
  187. data/generators/framework/USAGE +12 -0
  188. data/generators/framework/framework_generator.rb +53 -0
  189. data/generators/framework/templates/core.js +20 -0
  190. data/generators/framework/templates/english.lproj/body.css +0 -0
  191. data/generators/framework/templates/english.lproj/body.rhtml +3 -0
  192. data/generators/framework/templates/english.lproj/controls.css +0 -0
  193. data/generators/framework/templates/english.lproj/strings.js +14 -0
  194. data/generators/language/USAGE +16 -0
  195. data/generators/language/language_generator.rb +47 -0
  196. data/generators/language/templates/strings.js +10 -0
  197. data/generators/model/USAGE +24 -0
  198. data/generators/model/model_generator.rb +55 -0
  199. data/generators/model/templates/fixture.js +11 -0
  200. data/generators/model/templates/model.js +20 -0
  201. data/generators/model/templates/test.rhtml +21 -0
  202. data/generators/test/USAGE +16 -0
  203. data/generators/test/templates/test.rhtml +21 -0
  204. data/generators/test/test_generator.rb +47 -0
  205. data/generators/view/USAGE +16 -0
  206. data/generators/view/templates/test.rhtml +21 -0
  207. data/generators/view/templates/view.js +20 -0
  208. data/generators/view/view_generator.rb +51 -0
  209. data/jsdoc/README.txt +119 -0
  210. data/jsdoc/app/DocFile.js +137 -0
  211. data/jsdoc/app/DocTag.js +110 -0
  212. data/jsdoc/app/Doclet.js +63 -0
  213. data/jsdoc/app/Dumper.js +143 -0
  214. data/jsdoc/app/JsDoc.js +103 -0
  215. data/jsdoc/app/JsHilite.js +45 -0
  216. data/jsdoc/app/JsIO.js +163 -0
  217. data/jsdoc/app/JsParse.js +385 -0
  218. data/jsdoc/app/JsPlate.js +130 -0
  219. data/jsdoc/app/JsTestrun.js +129 -0
  220. data/jsdoc/app/JsToke.js +564 -0
  221. data/jsdoc/app/Symbol.js +298 -0
  222. data/jsdoc/app/Transformer.js +14 -0
  223. data/jsdoc/app/Util.js +97 -0
  224. data/jsdoc/app/js.jar +0 -0
  225. data/jsdoc/app/run.js +144 -0
  226. data/jsdoc/plugins/min.js +316 -0
  227. data/jsdoc/plugins/strip.js +20 -0
  228. data/jsdoc/templates/sproutcore/class.tmpl +438 -0
  229. data/jsdoc/templates/sproutcore/default.css +241 -0
  230. data/jsdoc/templates/sproutcore/index.html +13 -0
  231. data/jsdoc/templates/sproutcore/index.tmpl +21 -0
  232. data/jsdoc/templates/sproutcore/prototype.js +4186 -0
  233. data/jsdoc/templates/sproutcore/publish.js +236 -0
  234. data/jsdoc/templates/sproutcore/splash.html +7 -0
  235. data/lib/sproutcore/build_tools/html_builder.rb +88 -0
  236. data/lib/sproutcore/build_tools/resource_builder.rb +194 -0
  237. data/lib/sproutcore/build_tools.rb +44 -0
  238. data/lib/sproutcore/bundle.rb +517 -0
  239. data/lib/sproutcore/bundle_manifest.rb +397 -0
  240. data/lib/sproutcore/generator_helper.rb +170 -0
  241. data/lib/sproutcore/helpers/capture_helper.rb +42 -0
  242. data/lib/sproutcore/helpers/static_helper.rb +80 -0
  243. data/lib/sproutcore/helpers/tag_helper.rb +110 -0
  244. data/lib/sproutcore/helpers/text_helper.rb +336 -0
  245. data/lib/sproutcore/helpers.rb +3 -0
  246. data/lib/sproutcore/jsdoc.rb +40 -0
  247. data/lib/sproutcore/jsmin.rb +247 -0
  248. data/lib/sproutcore/library.rb +258 -0
  249. data/lib/sproutcore/merb/bundle_controller.rb +179 -0
  250. data/lib/sproutcore/merb/router.rb +43 -0
  251. data/lib/sproutcore/merb.rb +27 -0
  252. data/lib/sproutcore/version.rb +9 -0
  253. data/lib/sproutcore/view_helpers/button_views.rb +302 -0
  254. data/lib/sproutcore/view_helpers/core_views.rb +284 -0
  255. data/lib/sproutcore/view_helpers/form_views.rb +258 -0
  256. data/lib/sproutcore/view_helpers/menu_views.rb +94 -0
  257. data/lib/sproutcore/view_helpers.rb +628 -0
  258. data/lib/sproutcore.rb +30 -0
  259. data/script/destroy +14 -0
  260. data/script/generate +14 -0
  261. data/script/txt2html +74 -0
  262. data/setup.rb +1585 -0
  263. data/spec/spec.opts +1 -0
  264. data/spec/spec_helper.rb +7 -0
  265. data/spec/sproutcore_spec.rb +11 -0
  266. data/tasks/deployment.rake +34 -0
  267. data/tasks/environment.rake +7 -0
  268. data/tasks/rspec.rake +21 -0
  269. data/tasks/website.rake +17 -0
  270. metadata +365 -0
@@ -0,0 +1,137 @@
1
+ // ========================================================================
2
+ // SproutCore
3
+ // copyright 2006-2007 Sprout Systems, Inc.
4
+ // ========================================================================
5
+
6
+ require('views/view') ;
7
+
8
+ // This is a basic popup menu. You can show the popup menu by calling the
9
+ // view's popup() method. Pass in the root element and event so that is can
10
+ // be positioned.
11
+ SC.PopupMenuView = SC.View.extend({
12
+ emptyElement: "<ul></ul>",
13
+
14
+ acceptsFirstResponder: true,
15
+
16
+
17
+ keyDown: function(evt)
18
+ {
19
+ return this.interpretKeyEvents(evt);
20
+ },
21
+
22
+ // interpretKeyEvents callbacks...
23
+ cancel: function()
24
+ {
25
+ this.set('currentSelectedMenuItem', null);
26
+ this.set('isVisible', false);
27
+ },
28
+ moveUp: function()
29
+ {
30
+ this.selectPreviousMenuItem();
31
+ },
32
+ moveDown: function()
33
+ {
34
+ this.selectNextMenuItem();
35
+ },
36
+
37
+ _currentSelectedMenuItem: null,
38
+ currentSelectedMenuItem: function( key, value )
39
+ {
40
+ if (value !== undefined)
41
+ {
42
+ if (this._currentSelectedMenuItem) this._currentSelectedMenuItem.set('isDefault', false);
43
+ this._currentSelectedMenuItem = value;
44
+ if (this._currentSelectedMenuItem) this._currentSelectedMenuItem.set('isDefault', true);
45
+ }
46
+ return this._currentSelectedMenuItem;
47
+ }.property(),
48
+
49
+ selectPreviousMenuItem: function()
50
+ {
51
+ var item = this.previousValidMenuItem();
52
+ if (!item) return false;
53
+ this.set('currentSelectedMenuItem', item);
54
+ },
55
+
56
+ selectNextMenuItem: function()
57
+ {
58
+ var item = this.nextValidMenuItem();
59
+ if (!item) return false;
60
+ this.set('currentSelectedMenuItem', item);
61
+ },
62
+
63
+ previousValidMenuItem: function()
64
+ {
65
+ return this._validMenuItemInDirection('previousSibling', 'lastChild');
66
+ },
67
+ nextValidMenuItem: function()
68
+ {
69
+ return this._validMenuItemInDirection('nextSibling', 'firstChild');
70
+ },
71
+ _validMenuItemInDirection: function( direction, begin )
72
+ {
73
+ var curr = this.get('currentSelectedMenuItem');
74
+ var view = curr ? curr.get(direction) : this.get(begin);
75
+ if (!view) return null;
76
+ do {
77
+ if (view.get('isEnabled')) return view;
78
+ } while (view = view.get(direction));
79
+ return null;
80
+ },
81
+
82
+
83
+ _show: function()
84
+ {
85
+ // clear out any previously used selection value...
86
+ this.set('currentSelectedMenuItem', null);
87
+
88
+ var menuItems = this.get('childNodes');
89
+ for (var i=0, n=menuItems.length; i < n; i++)
90
+ {
91
+ // for each menu item, get the action that it performs and the current target for that action
92
+ var sender = menuItems[i];
93
+
94
+ // old function style actions... skip validating and let them be
95
+ if (sender._hasLegacyActionHandler()) continue;
96
+
97
+ var action = sender.get('action');
98
+ var target = SC.app.targetForAction(action, sender.get('target'), sender);
99
+
100
+ //console.log( "action: %s, target: %o", action, target );
101
+
102
+ // found a target and the target validates, menu item is enabled if the validator returns true
103
+ if (target && target.respondsTo('validateMenuItem')) sender.set('isEnabled', target.validateMenuItem(sender));
104
+ // found a target and it chooses not to validate, menu item is enabled
105
+ if (target && !target.respondsTo('validateMenuItem')) sender.set('isEnabled', true);
106
+ // unable to resolve a target for this action, therefor disable the menu item
107
+ if (!target) sender.set('isEnabled', false);
108
+ }
109
+ // call the superclasses _show method to make the menu visible
110
+ arguments.callee.base.apply(this, arguments);
111
+ },
112
+
113
+ resizeWithOldParentSize: function() {
114
+
115
+ // loop through child views (which should be menu items), and get their
116
+ // required widths. Use the maximum returned width.
117
+ var requiredWidth = 0;
118
+ var child = this.get('firstChild') ;
119
+ while(child) {
120
+ var w = (child.computedRequiredWidth) ? child.computedRequiredWidth():0;
121
+ if (w > requiredWidth) requiredWidth = w ;
122
+ child = child.get('nextSibling') ;
123
+ }
124
+
125
+ // loop through children again, set their widths to the required with.
126
+ var size = { width: requiredWidth } ;
127
+ var child = this.get('firstChild') ;
128
+ while(child) {
129
+ child.set('size',size) ;
130
+ child = child.get('nextSibling') ;
131
+ }
132
+
133
+ // set this view to the same size.
134
+ this.set('size',size) ;
135
+ }
136
+
137
+ });
@@ -0,0 +1,100 @@
1
+ // ========================================================================
2
+ // SproutCore
3
+ // copyright 2006-2007 Sprout Systems, Inc.
4
+ // ========================================================================
5
+
6
+ require('views/view') ;
7
+
8
+ // ProgressView displays a progress bar. It does this mostly through CSS classes
9
+ // so that you can style them however you want. A progress bar must have the
10
+ // following structure:
11
+ //
12
+ // <div class="outer progress"><div class="inner"></div></div>
13
+ //
14
+ // The outer can form the boundary of the bar while the inner will be adjusted
15
+ // to fit the percentage of the progress.
16
+ //
17
+ // Style the progress bar with the following CSS classes:
18
+ //
19
+ // .progress.indeterminate = to show an indeterminate progress. inner will hide.
20
+ // .progress.disabled = show as disabled.
21
+
22
+ SC.ProgressView = SC.View.extend({
23
+
24
+ // ........................................
25
+ // PROPERTIES
26
+ //
27
+
28
+ minimum: 0, // the minimum value of the progress
29
+ maximum: 1.0, // the maximum value of the progress bar.
30
+
31
+ // Bind this to the current value of the progress bar. Note that by default an
32
+ // empty value will disable the progress bar and a multiple value too make it
33
+ // indeterminate.
34
+ value: 0.50,
35
+ valueBindingDefault: SC.Binding.SingleNotEmpty,
36
+
37
+ // set to true if the item in progress is indeterminate. This may be overridden
38
+ // by the actual value.
39
+ isIndeterminate: function(key,value) {
40
+ if (value !== undefined) {
41
+ this._isIndeterminate = value ;
42
+ }
43
+ return this._isIndeterminate && (this.value != SC.Binding.EMPTY_PLACEHOLDER) ;
44
+ }.property(),
45
+
46
+ // set to false to disable the progress bar
47
+ isEnabled: function(key, value) {
48
+ if (value !== undefined) {
49
+ this._isEnabled = value ;
50
+ }
51
+ return this._isEnabled && (this.value != SC.Binding.MULTIPLE_PLACEHOLDER) ;
52
+ }.property(),
53
+
54
+ _isIndeterminate: false, _isEnabled: true,
55
+
56
+ // ........................................
57
+ // STRUCTURE
58
+ //
59
+
60
+ emptyElement: '<div class="progress outer"><div class="outer-head"></div><div class="inner"><div class="inner-head"></div><div class="inner-tail"></div></div><div class="outer-tail"></div></div>',
61
+
62
+ outlets: ['innerView'],
63
+ innerView: SC.View.outletFor('.inner?'),
64
+
65
+ // ........................................
66
+ // INTERNAL SUPPORT
67
+ //
68
+
69
+ propertyObserver: function(observing,target,key,value) {
70
+ // collect new settings.
71
+ if (['value','minimum','maximum','isIndeterminate','isEnabled'].include(key)) {
72
+ var isIndeterminate = this.get('isIndeterminate') ;
73
+ var isEnabled = this.get('isEnabled') ;
74
+
75
+ Element.setClassName(this,'indeterminate',isIndeterminate) ;
76
+ Element.setClassName(this,'disabled',!isEnabled) ;
77
+
78
+ // compute value
79
+ var value ;
80
+ if (isIndeterminate || !isEnabled) {
81
+ value = 0.0 ;
82
+ } else {
83
+ var minimum = this.get('minimum') || 0.0 ;
84
+ var maximum = this.get('maximum') || 1.0 ;
85
+ value = this.get('value') || 0.0 ;
86
+ value = (value - minimum) / (maximum - minimum) ;
87
+ if (value > 1.0) value = 1.0 ;
88
+ }
89
+ value = value * 100 ;
90
+ if (this.innerView) this.innerView.setStyle({ width: (value + '%') }) ;
91
+ }
92
+ }
93
+ }) ;
94
+
95
+
96
+
97
+
98
+
99
+
100
+
@@ -0,0 +1,107 @@
1
+ // ========================================================================
2
+ // SproutCore
3
+ // copyright 2006-2007 Sprout Systems, Inc.
4
+ // ========================================================================
5
+
6
+ require('views/field') ;
7
+
8
+ // A RadioFieldView can be used to wrap a series of radio inputs. The value
9
+ // of this field will be the selected radio. To use this, you really need to
10
+ // provide some preformatted HTML that already contains the radio buttons with
11
+ // matching name attributes. If you use the form_view helpers, this will be
12
+ // handled for you.
13
+ SC.RadioFieldView = SC.FieldView.extend({
14
+
15
+ emptyElement: '<div></div>',
16
+
17
+ // RO - returns the list of values allowed by these radio buttons.
18
+ values: function() {
19
+ if (!this._fields) return [] ;
20
+ return Object.keys(this._fields) ;
21
+ }.property(),
22
+
23
+ // If you would like your radio buttons to map to actual object values,
24
+ // then set this to a hash with keys matching values found in the radio
25
+ // buttons.
26
+ objects: null,
27
+
28
+ // INTERNAL SUPPORT METHODS
29
+ setFieldValue: function(value) {
30
+ if (!this._fields) return ;
31
+
32
+ // map object value to radio button value if set.
33
+ var objects = this.get('objects') ;
34
+ if (objects) {
35
+ for(var key in objects) {
36
+ if (!objects.hasOwnProperty(key)) continue ;
37
+ if (objects[key] == value) {
38
+ value = key ; break ;
39
+ }
40
+ }
41
+ }
42
+
43
+ // set value.
44
+ var field = this._fields[value] ;
45
+ if (field) {
46
+ field.checked = true ;
47
+ } else {
48
+ for(var key in this._fields) {
49
+ if (!this._fields.hasOwnProperty(key)) continue ;
50
+ this._fields[key].checked = false ;
51
+ }
52
+ }
53
+ },
54
+
55
+ getFieldValue: function() {
56
+ if (!this._fields) return null;
57
+
58
+ var ret = null;
59
+ for(var key in this._fields) {
60
+ if (!this._fields.hasOwnProperty(key)) continue ;
61
+ if (this._fields[key].checked == true) {
62
+ ret = key ; break ;
63
+ } ;
64
+ }
65
+
66
+ // map to object value if set.
67
+ var objects = this.get('objects') ;
68
+ if (objects && ret) ret = objects[ret] ;
69
+ return ret ;
70
+ },
71
+
72
+ enableField: function() {
73
+ if (!this._fields) return ;
74
+ for(var key in this._fields) {
75
+ if (!this._fields.hasOwnProperty(key)) continue ;
76
+ Form.Element.enable(this._fields[key]) ;
77
+ }
78
+ },
79
+
80
+ // override to disable editing of this field.
81
+ disableField: function() {
82
+ if (!this._fields) return ;
83
+ for(var key in this._fields) {
84
+ if (!this._fields.hasOwnProperty(key)) continue ;
85
+ Form.Element.disable(this._fields[key]) ;
86
+ }
87
+ },
88
+
89
+ init: function() {
90
+ arguments.callee.base.apply(this,arguments) ;
91
+
92
+ // find all inputs.
93
+ this._fields = {} ;
94
+
95
+ var inputFields = this.$$tag('input') ;
96
+ var f = this.fieldValueDidChange.bind(this, false) ;
97
+ var loc = inputFields.length ;
98
+
99
+ this._fields = {} ;
100
+ while(--loc >= 0) {
101
+ var field = inputFields[loc] ;
102
+ this._fields[field.value] = field ;
103
+ Event.observe(field,'change', f) ;
104
+ }
105
+ }
106
+
107
+ }) ;
@@ -0,0 +1,48 @@
1
+ // ========================================================================
2
+ // SproutCore
3
+ // copyright 2006-2007 Sprout Systems, Inc.
4
+ // ========================================================================
5
+
6
+ require('views/view') ;
7
+
8
+ // RadioGroupView manages a collection of buttons as a single value. To
9
+ // use this view, just assign your buttons as outlets. This will use the
10
+ // toggleOnValue you have already set.
11
+ SC.RadioGroupView = SC.View.extend({
12
+
13
+ // this is the current value or values of the radio group view. The
14
+ // items in the radio group will be selected based on this value.
15
+ value: null,
16
+
17
+ // enable/disable the views in this group view.
18
+ isEnabled: true,
19
+
20
+ // PRIVATE METHODS
21
+ init: function() {
22
+ arguments.callee.base.apply(this, arguments) ;
23
+
24
+ // find the list of buttons to update and set them up.
25
+ var loc = this.outlets.length ;
26
+ var ret = [] ;
27
+ var valuePropertyPath = [this,'value'];
28
+ while(--loc >= 0) {
29
+ var key = this.outlets[loc] ;
30
+ var button = this[key] ;
31
+ if (button && (button.toggleOnValue !== undefined)) {
32
+ button.bind('value', valuePropertyPath) ;
33
+ ret.push(button);
34
+ }
35
+ }
36
+ this._radioButtons = ret ;
37
+ },
38
+
39
+ // forward changes to the isEnabled property to children.
40
+ _isEnabledObserver: function() {
41
+ var newFlag = this.get('isEnabled') ;
42
+ if (!this.didChangeFor('_isEnabled','isEnabled')) return ;
43
+ if (this.radioButtons) {
44
+ this.radioButtons.invoke('set','isEnabled',newFlag) ;
45
+ }
46
+ }.observes('isEnabled')
47
+
48
+ }) ;
@@ -0,0 +1,80 @@
1
+ // ========================================================================
2
+ // SproutCore
3
+ // copyright 2006-2007 Sprout Systems, Inc.
4
+ // ========================================================================
5
+
6
+ require('views/view') ;
7
+
8
+ // SegmentView shows an array of buttons that can have mutually exclusive
9
+ // select states. You can change the value property to the state you
10
+ // want to reflect and a button with the matching name 'xxxButton' will have
11
+ // its select state set.
12
+ //
13
+ // Also, on configure, if the buttons in the segment view do not have actions
14
+ // set, then the button will be configured to change the select state.
15
+ SC.SegmentedView = SC.View.extend({
16
+
17
+ value: null, // set to the currently value button.
18
+
19
+ segments: null, // contains the array of buttons after init.
20
+
21
+ // changes all buttons to enabled/disabled. You can also change buttons
22
+ // individually.
23
+ isEnabled: true,
24
+
25
+ // if true, clicking on a button again will deselect it (using the
26
+ // standard action)
27
+ allowsEmptySelection: false,
28
+
29
+ init: function() {
30
+ arguments.callee.base.call(this) ;
31
+
32
+ // find all segment outlets. If they don't have any action already, set
33
+ // them up.
34
+ if (!this.segments) this.segments = this.outlets.slice() ;
35
+ var view = this ;
36
+ this.segments.each(function(key) {
37
+ var seg = view[key] ;
38
+ var selectKey = key.slice(0,-6) ;
39
+ if (seg && (seg.action == SC.ButtonView.prototype.action)) seg.action = function() {
40
+ if (this.owner.get('allowsEmptySelection')) {
41
+ newKey = (this.owner.get('value') == selectKey) ? null : selectKey;
42
+ } else newKey = selectKey;
43
+ this.owner.set('value',newKey) ;
44
+ } ;
45
+ }) ;
46
+
47
+ this._enabledObserver() ;
48
+ this._valueObserver() ;
49
+ },
50
+
51
+ // OBSERVERS
52
+ _valueObserver: function() {
53
+ var value = this.get('value') ;
54
+ if (value != this._lastSelected) {
55
+ this._lastSelected = value ;
56
+ var view = this ;
57
+ this.segments.each(function(key) {
58
+ var isSelected = (value) ? (key.slice(0,-6) == value) : false;
59
+ var button = view[key] ;
60
+ if (button) button.set('isSelected',isSelected) ;
61
+ }) ;
62
+ }
63
+ }.observes('value'),
64
+
65
+ _enabledObserver: function() {
66
+ var isEnabled = this.get('isEnabled') ;
67
+ if (isEnabled != this._lastEnabled) {
68
+ var view = this ;
69
+ this.segments.each(function(key) {
70
+ view[key].set('isEnabled',isEnabled) ;
71
+ }) ;
72
+ }
73
+ }.observes('isEnabled')
74
+
75
+ }) ;
76
+
77
+
78
+
79
+
80
+