sproutcore 0.9.1 → 0.9.2

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 (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
@@ -1,24 +1,45 @@
1
1
  // ========================================================================
2
2
  // SproutCore
3
- // copyright 2006-2007 Sprout Systems, Inc.
3
+ // copyright 2006-2008 Sprout Systems, Inc.
4
4
  // ========================================================================
5
5
 
6
6
  require('validators/validator') ;
7
7
 
8
- // Force to be a valid credit card number.
9
- SC.Validator.CreditCard = SC.Validator.extend({
8
+ /**
9
+ Validate a field value as a credit card number.
10
10
 
11
- // expects a string of 16 digits. split into groups of 4
11
+ This validator will perform a basic check to ensure the credit card number
12
+ is mathematically valid. It will also accept numbers with spaces, dashes
13
+ or other punctuation.
14
+
15
+ Converted credit card numbers are broken into units of 4.
16
+
17
+ Basic credit card validation courtesy David Leppek
18
+ (https://www.azcode.com/Mod10)
19
+
20
+ @class
21
+ @extends SC.Validator
22
+ @author Charles Jolley
23
+ @version 1.0
24
+ */
25
+ SC.Validator.CreditCard = SC.Validator.extend(
26
+ /** @scope SC.Validator.CreditCard.prototype */ {
27
+
28
+ /**
29
+ Expects a string of 16 digits. Will split into groups of 4 for display.
30
+ */
12
31
  fieldValueForObject: function(object, form, field) {
13
32
  if (typeof(object) == "string" && object.length == 16) {
14
33
  object = [object.slice(0,4),object.slice(4,8),object.slice(8,12),object.slice(12,16)].join(' ') ;
15
34
  }
16
35
  return object ;
17
36
  },
18
-
19
- // remove all whitespace to make a single number.
37
+
38
+ /**
39
+ Removes all whitespace or dashes to make a single string.
40
+ */
20
41
  objectForFieldValue: function(value, form, field) {
21
- return value.replace(/^\s+|\s+$/g,'') ;
42
+ return value.replace(/[\s-\.\:]/g,'') ;
22
43
  },
23
44
 
24
45
  validate: function(form, field) {
@@ -30,11 +51,10 @@ SC.Validator.CreditCard = SC.Validator.extend({
30
51
  return $error("Invalid.CreditCard(%@)".loc(label), label);
31
52
  },
32
53
 
33
- // Borrowed from: David Leppek :: https://www.azcode.com/Mod10
34
54
  checkNumber: function(ccNumb) {
35
- var valid = "0123456789" // Valid digits in a credit card number
55
+ var valid = "0123456789"; // Valid digits in a credit card number
36
56
  var len = ccNumb.length; // The length of the submitted cc number
37
- var iCCN = parseInt(ccNumb); // integer of ccNumb
57
+ var iCCN = parseInt(ccNumb,0); // integer of ccNumb
38
58
  var sCCN = ccNumb.toString(); // string of ccNumb
39
59
  sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces
40
60
  var iTotal = 0; // integer total set at zero
@@ -59,12 +79,12 @@ SC.Validator.CreditCard = SC.Validator.extend({
59
79
  } else{ // ccNumb is a number and the proper length - let's see if it is a valid card number
60
80
  if(len >= 15){ // 15 or 16 for Amex or V/MC
61
81
  for(var i=len;i>0;i--){ // LOOP throught the digits of the card
62
- calc = parseInt(iCCN) % 10; // right most digit
63
- calc = parseInt(calc); // assure it is an integer
82
+ calc = parseInt(iCCN,0) % 10; // right most digit
83
+ calc = parseInt(calc,0); // assure it is an integer
64
84
  iTotal += calc; // running total of the card number as we loop - Do Nothing to first digit
65
85
  i--; // decrement the count - move to the next digit in the card
66
86
  iCCN = iCCN / 10; // subtracts right most digit from ccNumb
67
- calc = parseInt(iCCN) % 10 ; // NEXT right most digit
87
+ calc = parseInt(iCCN,0) % 10 ; // NEXT right most digit
68
88
  calc = calc *2; // multiply the digit by two
69
89
  // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
70
90
  // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
@@ -1,17 +1,35 @@
1
1
  // ========================================================================
2
2
  // SproutCore
3
- // copyright 2006-2007 Sprout Systems, Inc.
3
+ // copyright 2006-2008 Sprout Systems, Inc.
4
4
  // ========================================================================
5
5
 
6
6
  require('validators/validator') ;
7
7
 
8
- // Handle the parsing and display of dates.
9
- SC.Validator.Date = SC.Validator.extend({
8
+ /**
9
+ Handle parsing and display of dates.
10
+
11
+ @class
12
+ @extends SC.Validator
13
+ @author Charles Jolley
14
+ @version 1.0
15
+ */
16
+ SC.Validator.Date = SC.Validator.extend(
17
+ /** @scope SC.Validator.Date.prototype */ {
10
18
 
19
+ /**
20
+ The standard format you want the validator to convert dates to.
21
+ */
11
22
  format: 'NNN d, yyyy h:mm:ss a',
23
+
24
+ /**
25
+ If true, dates will be converted to a natural language format if
26
+ possible such as "Tomorrow" or "Today".
27
+ */
12
28
  naturalLanguage: true,
13
29
 
14
- // if we have a number, then convert to a date object.
30
+ /**
31
+ if we have a number, then convert to a date object.
32
+ */
15
33
  fieldValueForObject: function(object, form, field) {
16
34
  var date ;
17
35
  if (typeof(object) == "number") {
@@ -23,8 +41,10 @@ SC.Validator.Date = SC.Validator.extend({
23
41
  return object ;
24
42
  },
25
43
 
26
- // try to pase value as a date. convert into a number, or return null if
27
- // it could not be parsed.
44
+ /**
45
+ Try to pase value as a date. convert into a number, or return null if
46
+ it could not be parsed.
47
+ */
28
48
  objectForFieldValue: function(value, form, field) {
29
49
  if (value) {
30
50
  var date = Date.parseDate(value) ;
@@ -7,7 +7,17 @@
7
7
  // ==========================================================================
8
8
 
9
9
  require('validators/validator') ;
10
- SC.Validator.Email = SC.Validator.extend({
10
+
11
+ /**
12
+ Requires a valid email format.
13
+
14
+ @class
15
+ @extends SC.Validator
16
+ @author Charles Jolley
17
+ @version 1.0
18
+ */
19
+ SC.Validator.Email = SC.Validator.extend(
20
+ /** @scope SC.Validator.Email.prototype */ {
11
21
 
12
22
  validate: function(form, field) {
13
23
  return (field.get('fieldValue') || '').match(/.+@.+\...+/) ;
@@ -20,8 +30,16 @@ SC.Validator.Email = SC.Validator.extend({
20
30
 
21
31
  }) ;
22
32
 
23
- // this variant allows an email to be empty.
24
- SC.Validator.EmailOrEmpty = SC.Validator.Email.extend({
33
+ /**
34
+ This variant allows an empty field as well as an email address.
35
+
36
+ @class
37
+ @extends SC.Validator.Email
38
+ @author Charles Jolley
39
+ @version 1.0
40
+ */
41
+ SC.Validator.EmailOrEmpty = SC.Validator.Email.extend(
42
+ /** @scope SC.Validator.EmailOrEmpty.prototype */ {
25
43
  validate: function(form, field) {
26
44
  var value = field.get('fieldValue') ;
27
45
  return (value && value.length > 0) ? value.match(/.+@.+\...+/) : true ;
@@ -7,7 +7,17 @@
7
7
  // ==========================================================================
8
8
 
9
9
  require('validators/validator') ;
10
- SC.Validator.NotEmpty = SC.Validator.extend({
10
+
11
+ /**
12
+ Requires some content in field, but does not check the specific content.
13
+
14
+ @class
15
+ @extends SC.Validator
16
+ @author Charles Jolley
17
+ @version 1.0
18
+ */
19
+ SC.Validator.NotEmpty = SC.Validator.extend(
20
+ /** @scope SC.Validator.NotEmpty.prototype */ {
11
21
 
12
22
  validate: function(form, field) {
13
23
  var value = field.get('fieldValue');
@@ -1,14 +1,28 @@
1
1
  // ========================================================================
2
2
  // SproutCore
3
- // copyright 2006-2007 Sprout Systems, Inc.
3
+ // copyright 2006-2008 Sprout Systems, Inc.
4
4
  // ========================================================================
5
5
 
6
6
  require('validators/validator') ;
7
7
 
8
- // Handle the parsing and display of numbers.
9
- SC.Validator.Number = SC.Validator.extend({
8
+ /**
9
+ Handles parsing and validating of numbers.
10
+
11
+ @extends SC.Validator
12
+ @author Charles Jolley
13
+ @version 1.0
14
+ @class
15
+ */
16
+ SC.Validator.Number = SC.Validator.extend(
17
+ /** @scope SC.Validator.Number.prototype */ {
10
18
 
11
- places: 0, // 0 to force int. otherwise fixed.
19
+ /**
20
+ Number of decimal places to show.
21
+
22
+ If 0, then numbers will be treated as integers. Otherwise, numbers will
23
+ show with a fixed number of decimals.
24
+ */
25
+ places: 0,
12
26
 
13
27
  fieldValueForObject: function(object, form, field) {
14
28
  switch($type(object)) {
@@ -9,7 +9,18 @@
9
9
  // ==========================================================================
10
10
 
11
11
  require('validators/validator') ;
12
- SC.Validator.Password = SC.Validator.extend({
12
+
13
+ /**
14
+ Ensures all fields with the Password validator attached in the same form
15
+ contain the same value.
16
+
17
+ @class
18
+ @extends SC.Validator
19
+ @author Charles Jolley
20
+ @version 1.0
21
+ */
22
+ SC.Validator.Password = SC.Validator.extend(
23
+ /** @scope SC.Validator.Password.prototype */ {
13
24
 
14
25
  attachTo: function(form,field) {
15
26
  argments.callee.base.call(this,form,field) ;
@@ -3,30 +3,41 @@
3
3
  // Author: Charles Jolley
4
4
  // ==========================================================================
5
5
 
6
- //
7
- // Validators provide a way for you to implement simple form field validation
8
- // and transformation. To use a validator, simply name the validator in the
9
- // "validate" attribute in your text field. For example, if you want to
10
- // validate a field using the PhoneNumberValidator use this:
11
- //
12
- // <input value="1234567890" validate="phone-number" />
13
- //
14
- // Validators get notified at three points. You can implement one or all
15
- // of these methods to support validation. All of the validate methods except
16
- // for validateKeypress behave the same way. You are passed a form, field,
17
- // and possibly the oldValue. You are expected to return Validator.OK or
18
- // an error string. Inside this method you typically do one of all of the
19
- // following:
20
- //
21
- // 1. You can simply validate the field value and return OK or an error str.
22
- // 2. You can modify the field value (for example, you could format the
23
- // string to match some predefined format).
24
- // 3. If you need to roundtrip the server first to perform validation, you can
25
- // return Validator.OK, then save the form and field info until after the
26
- // roundtrip. On return, if there is a problem, first verify the field
27
- // value has not changed and then call form.errorFor(field,str) ;
28
- //
29
- SC.Validator = SC.Object.extend({
6
+ require('foundation/object');
7
+
8
+ /**
9
+ @class
10
+
11
+ Validators provide a way for you to implement simple form field validation
12
+ and transformation. To use a validator, simply name the validator in the
13
+ "validate" attribute in your text field. For example, if you want to
14
+ validate a field using the PhoneNumberValidator use this:
15
+
16
+ <input value="1234567890" validate="phone-number" />
17
+
18
+ Validators get notified at three points. You can implement one or all
19
+ of these methods to support validation. All of the validate methods except
20
+ for validateKeypress behave the same way. You are passed a form, field,
21
+ and possibly the oldValue. You are expected to return Validator.OK or
22
+ an error string. Inside this method you typically do one of all of the
23
+ following:
24
+
25
+ 1. You can simply validate the field value and return OK or an error str
26
+
27
+ 2. You can modify the field value (for example, you could format the
28
+ string to match some predefined format).
29
+
30
+ 3. If you need to roundtrip the server first to perform validation, you can
31
+ return Validator.OK, then save the form and field info until after the
32
+ roundtrip. On return, if there is a problem, first verify the field
33
+ value has not changed and then call form.errorFor(field,str) ;
34
+
35
+ @extends SC.Object
36
+ @author Charles Jolley
37
+ @version 1.0
38
+ */
39
+ SC.Validator = SC.Object.extend(
40
+ /** @scope SC.Validator.prototype */ {
30
41
 
31
42
  // ..........................................
32
43
  // OBJECT VALUE CONVERSION
@@ -37,44 +48,66 @@ SC.Validator = SC.Object.extend({
37
48
  // For example, you might add or remove a dollar sign or convert the
38
49
  // value to a number.
39
50
 
40
- // This method should return the value to set in the field for the passed
41
- // object value. The form and field to be set MAY (but will not always)
42
- // be passed also.
43
- fieldValueForObject: function(object, form, field) { return object; },
51
+ /**
52
+ Returns the value to set in the field for the passed object value.
44
53
 
45
- // This method should return the object value for the string passed. The
46
- // form and field the value came from MAY (but will not always) be passed
47
- // also.
48
- objectForFieldValue: function(value, form, field) { return value; },
54
+ The form and view to be set MAY (but will not always) be passed also. You
55
+ should override this method to help convert an input object into a value
56
+ that can be displayed by the field. For example, you might convert a
57
+ date to a property formatted string or a number to a properly formatted
58
+ value.
59
+
60
+ @param {Object} object The object to transform
61
+ @param {SC.FormView} form The form this field belongs to. (optional)
62
+ @param {SC.View} view The view the value is required for.
63
+ @returns {Object} a value (usually a string) suitable for display
64
+ */
65
+ fieldValueForObject: function(object, form, view) { return object; },
66
+
67
+ /**
68
+ Returns the object value for the passed string.
69
+
70
+ The form and view MAY (but wil not always) be passed also. You should
71
+ override this method to convert a field value, such as string, into an
72
+ object value suitable for consumption by the rest of the app. For example
73
+ you may convert a string into a date or a number.
74
+
75
+ @param {String} value the field value. (Usually a String).
76
+ @param {SC.FormView} form The form this field belongs to. (optional)
77
+ @param {SC.View} view The view this value was pulled from.
78
+ @returns {Object} an object suitable for consumption by the app.
79
+ */
80
+ objectForFieldValue: function(value, form, view) { return value; },
49
81
 
50
82
  // ..........................................
51
83
  // VALIDATION PRIMITIVES
52
84
  //
53
- // You can implement standard behavior for your validator by using the
54
- // vaidate and validateError methods. validate() should return false
55
- // if the field is not valid.
56
- //
57
- // Expects:
58
- // form: the form
59
- // field: the field to validate
60
- //
61
- // Returns:
62
- // true if the field is valid, otherwise not.
63
- //
85
+
86
+ /**
87
+ Validate the field value.
88
+
89
+ You can implement standard behavior for your validator by using the
90
+ vaidate and validateError methods. validate() should return false
91
+ if the field is not valid.
92
+
93
+ @param {SC.FormView} form the form this view belongs to
94
+ @param {SC.View} field the field to validate. Responds to fieldValue.
95
+ @returns {Boolean} YES if field is valid.
96
+ */
64
97
  validate: function(form, field) { return true; },
65
98
 
66
- // This is the other standard validator method that can be used to impement
67
- // basic validation. This should return an error object explaining why
68
- // the field is not valid. It will only be called if validate() returned
69
- // false.
70
- //
71
- // Expects:
72
- // form: the form
73
- // field: the field that is no valid.
74
- //
75
- // Returns:
76
- // Error string.
77
- //
99
+ /**
100
+ Returns an error object if the field is invalid.
101
+
102
+ This is the other standard validator method that can be used to impement
103
+ basic validation. This should return an error object explaining why
104
+ the field is not valid. It will only be called if validate() returned
105
+ false.
106
+
107
+ @param {SC.FormView} form the form this view belongs to
108
+ @param {SC.View} field the field to validate. Responds to fieldValue.
109
+ @returns {SC.Error} an error object
110
+ */
78
111
  validateError: function(form, field) {
79
112
  return $error(
80
113
  "Invalid.General(%@)".loc(field.get('fieldValue')),
@@ -85,169 +118,137 @@ SC.Validator = SC.Object.extend({
85
118
  // VALIDATION API
86
119
  //
87
120
 
88
- // this method gets invoked just before the user ends editing of the field.
89
- //
90
- // Expects;
91
- // field: the field that was changed.
92
- // oldValue: the value of the field before the user changed it.
93
- //
94
- // Return:
95
- // SC.Validator.OK if the item was valid, an error object if the item is
96
- // not valid.
97
- //
121
+ /**
122
+ Invoked just before the user ends editing of the field.
123
+
124
+ The default implementation calls your validate() method and then
125
+ validateError() if valiate() returns NO. This method should return
126
+ SC.Validator.OK if validation succeeded or an error object if it fails.
127
+
128
+ @param {SC.FormView} form the form for the field
129
+ @param {SC.View} field the field to validate
130
+ @param {Object} oldValue: the value of the field before the change
131
+
132
+ @returns SC.Validator.OK or an error object.
133
+
134
+ */
98
135
  validateChange: function(form, field, oldValue) {
99
136
  return (this.validate(form,field)) ? SC.Validator.OK : this.validateError(form, field);
100
137
  },
101
138
 
102
- // this method is called for the field just before the form is submitted.
103
- //
104
- // Expects:
105
- // form: the form the field belongs to
106
- // field: the field to validate.
107
- //
108
- // Returns:
109
- // An error string of SC.Validator.OK if the field is valid. If you return
110
- // an error string, form submission will be cancelled.
111
- //
139
+ /**
140
+ Invoked just before the form is submitted.
141
+
142
+ This method gives your validators one last chance to perform validation
143
+ on the form as a whole. The default version does the same thing as the
144
+ validateChange() method.
145
+
146
+ @param {SC.FormView} form the form for the field
147
+ @param {SC.View} field the field to validate
148
+
149
+ @returns SC.Validator.OK or an error object.
150
+
151
+ */
112
152
  validateSubmit: function(form, field) {
113
153
  return (this.validate(form,field)) ? SC.Validator.OK : this.validateError(form, field);
114
154
  },
115
155
 
116
- // this method gets called 1ms after the user types a key (if a change is
117
- // allowed). You can use this validate the new partial string and return
118
- // an error if needed.
119
- //
120
- // The default will validate a partial only if there was already an error.
121
- // this allows the user to try to get it right before you bug them.
122
- //
123
- // Expects:
124
- // form: the form the field belongs to
125
- // field: the field to validate.
126
- //
127
- // Returns:
128
- // An error string if there was a problem, SC.Validator.OK if you checked
129
- // the field and it was valid or SC.Validator.NO_CHANGE if you did not
130
- // check the field. (Passing back OK will hide any showing errors.)
131
- //
156
+ /**
157
+ Invoked 1ms after the user types a key (if a change is allowed).
158
+
159
+ You can use this validate the new partial string and return an error if
160
+ needed. The default will validate a partial only if there was already an
161
+ error. This allows the user to try to get it right before you bug them.
162
+
163
+ Unlike the other methods, you should return SC.Validator.NO_CHANGE if you
164
+ did not actually validate the partial string. If you return
165
+ SC.Validator.OK then any showing errors will be hidden.
166
+
167
+ @param {SC.FormView} form the form for the field
168
+ @param {SC.View} field the field to validate
169
+
170
+ @returns SC.Validator.OK, SC.Validator.NO_CHANGE or an error object.
171
+ */
132
172
  validatePartial: function(form, field) {
133
173
  if (!field.get('isValid')) {
134
174
  return (this.validate(form,field)) ? SC.Validator.OK : this.validateError(form, field);
135
175
  } else return SC.Validator.NO_CHANGE ;
136
176
  },
137
177
 
138
- // this method gets called when the user types a key. It's useful to
139
- // restrict the letters and numbers the user is allowed to enter. Return
140
- // true/false to allow the keypress or not.
141
- //
142
- // Expects:
143
- // form: the form the field belongs to
144
- // field: the field in focus.
145
- // char: a string with the characters being added.
146
- //
147
- // Returns:
148
- // true to allow the keypress, false otherwise.
149
- //
178
+ /**
179
+ Invoked when the user presses a key.
180
+
181
+ This method is used to restrict the letters and numbers the user is
182
+ allowed to enter. You should not use this method to perform full
183
+ validation on the field. Instead use validatePartial().
184
+
185
+ @param {SC.FormView} form the form for the field
186
+ @param {SC.View} field the field to validate
187
+ @param {String} char the characters being added
188
+
189
+ @returns {Boolean} YES if allowed, NO otherwise
190
+ */
150
191
  validateKeypress: function(form, field,charStr) { return true; },
151
192
 
152
193
  // .....................................
153
194
  // OTHER METHODS
154
195
 
155
- // this method will be called on all validators when they are attached to
156
- // a field. You can use this to do any setup that you need.
157
- attachTo: function(form,field) {
158
- // this._form = form ;
159
- // this._field = field ;
160
- // var that = this ;
161
- // ['focus','change','blur','keypress'].each(function(key) {
162
- // var f = that['_'+key].bindAsEventListener(that) ;
163
- // Event.observe(field,key,f) ;
164
- // }) ;
165
- //
166
- // if (!this._boundPartial) this._boundPartial = this._partial.bind(this) ;
167
- // if (field.addObserver) field.addObserver('fieldValue',this._boundPartial);
168
- // return this ;
169
- },
196
+ /**
197
+ Called on all validators when they are attached to a field.
198
+
199
+ You can use this to do any setup that you need. The default does nothing.
200
+
201
+ @param {SC.FormView} form the form for the field
202
+ @param {SC.View} field the field to validate
203
+ */
204
+ attachTo: function(form,field) { },
170
205
 
171
- // this method is called on a validator just before it is removed from a
172
- // field. You can tear down any setup you did for the attachTo() method.
173
- detachFrom: function(form, field) {
206
+ /**
207
+ Called on a validator just before it is removed from a field. You can
208
+ tear down any setup you did for the attachTo() method.
174
209
 
175
- }
210
+ @param {SC.FormView} form the form for the field
211
+ @param {SC.View} field the field to validate
212
+ */
213
+ detachFrom: function(form, field) {}
214
+
215
+ }) ;
216
+
217
+ SC.Validator.mixin(/** @scope SC.Validator */ {
218
+
219
+ /**
220
+ Return value when validation was performed and value is OK.
221
+ */
222
+ OK: true,
176
223
 
177
- // detach: function() {
178
- // var that = this ;
179
- // ['focus','change','blur', 'keypress'].each(function(key) {
180
- // var f = that['_'+key].bindAsEventListener(that) ;
181
- // Event.stopObserving(that._field,key,f) ;
182
- // }) ;
183
- // if (this._field.removeObserver) {
184
- // this._field.removeObserver('fieldValue',this._boundPartial) ;
185
- // }
186
- // return this ;
187
- // },
188
- //
189
- // // save the old value before the user makes changes
190
- // _focus: function(ev) {
191
- // this._oldValue = this._field.get('fieldValue');
192
- // },
193
- //
194
- // _blur: function(ev) {
195
- // if (this._oldValue != this._field.get('fieldValue')) this._change(ev) ;
196
- // this._oldValue = null ;
197
- // },
198
- //
199
- // // invoked whenever the field value changes.
200
- // _change: function(ev) {
201
- // var err = this.validateChange(this._form,this._field,this._oldValue) ;
202
- // this._oldValue = null ;
203
- // if (err == SC.Validator.NO_CHANGE) return ; // nothing to do.
204
- // if (err == SC.Validator.OK) err = null ;
205
- // this._form.setErrorFor(this._field,err) ; // also clears error.
206
- // },
207
- //
208
- // _keypress: function(ev) {
209
- // var str = Event.getCharString(ev) ;
210
- // var allow = this.validateKeypress(this._form,this._field,str) ;
211
- // return allow ;
212
- // },
213
- //
214
- // _partial: function() {
215
- // var err = this.validatePartial(this._form,this._field) ;
216
- // if (err == SC.Validator.NO_CHANGE) return ; // nothing to do
217
- // if (err == SC.Validator.OK) err = null ;
218
- // if (this._field.set) this._field.set('isValid', err == null)
219
- // this._form.setErrorFor(this._field,err) ;
220
- // },
221
- //
222
- // // invoked by form.
223
- // _validate: function() {
224
- // var err = this.validateSubmit(this._form,this._field) ;
225
- // if (err == SC.Validator.NO_CHANGE) return true ; // nothing to do.
226
- // if (err == SC.Validator.OK) err = null ;
227
- // this._form.setErrorFor(this._field,err) ;
228
- // return (err == null) ; // true = ok to submit.
229
- // }
224
+ /**
225
+ Return value when validation was not performed.
226
+ */
227
+ NO_CHANGE: false,
228
+
229
+ /**
230
+ Invoked by a field whenever a validator is attached to the field.
231
+
232
+ The passed validatorKey can be a validator instance, a validator class
233
+ or a string naming a validator. To make your validator
234
+ visible, you should name your validator under the SC.Validator base.
235
+ for example SC.Validator.Number would get used for the 'number'
236
+ validator key.
230
237
 
231
- }) ;
238
+ This understands validatorKey strings in the following format:
232
239
 
233
- SC.Validator.mixin({
240
+ * 'key' or 'multiple_words' will find validators Key and MultipleWords
234
241
 
235
- // CONSTANTS
236
- OK: true, NO_CHANGE: false,
242
+ * if you want to share a single validator among multiple fields (for
243
+ example to validate that two passwords are the same) set a name inside
244
+ brackets. i.e. 'password[pwd]'.
237
245
 
238
- // this is invoked by a field whenever a validator is attached to the field.
239
- // The passed validatorKey can be a validator instance, a validator class
240
- // or a string naming a validator. To make your validator
241
- // visible, you should name your validator under the SC.Validator base.
242
- // for example SC.Validator.Number would get used for the 'number'
243
- // validator key.
244
- //
245
- // This understands validatorKey strings in the following format:
246
- // * 'key' or 'multiple_words' will find validators Key and MultipleWords
247
- // * if you want to share a single validator among multiple fields (for
248
- // example to validate that two passwords are the same) set a name inside
249
- // brackets. i.e. 'password[pwd]'.
250
- //
246
+ @param {SC.FormView} form the form for the field
247
+ @param {SC.View} field the field to validate
248
+ @param {Object} validatorKey the key to validate
249
+
250
+ @returns {SC.Validaotr} validator instance or null
251
+ */
251
252
  findFor: function(form,field, validatorKey) {
252
253
 
253
254
  // Convert the validator into a validator instance.
@@ -293,12 +294,21 @@ SC.Validator.mixin({
293
294
  return validator ;
294
295
  },
295
296
 
297
+ /**
298
+ Convenience class method to call the fieldValueForObject() instance
299
+ method you define in your subclass.
300
+ */
296
301
  fieldValueForObject: function(object, form, field) {
297
302
  return this.prototype.fieldValueForObject(object,form,field) ;
298
303
  },
299
-
304
+
305
+ /**
306
+ Convenience class method to call the objectForFieldValue() instance
307
+ method you define in your subclass.
308
+ */
300
309
  objectForFieldValue: function(value, form, field) {
301
310
  return this.prototype.objectForFieldValue(value,form,field) ;
302
311
  }
303
312
 
304
- })
313
+ }) ;
314
+