sproutcore 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +233 -0
- data/Manifest.txt +67 -34
- data/bin/sc-build +12 -1
- data/bin/sc-gen +1 -1
- data/bin/sproutcore +14 -0
- data/clients/sc_docs/controllers/docs.js +38 -8
- data/clients/sc_docs/english.lproj/body.css +80 -127
- data/clients/sc_docs/english.lproj/body.rhtml +43 -23
- data/clients/sc_docs/english.lproj/no_docs.rhtml +2 -1
- data/clients/sc_docs/english.lproj/tabs.rhtml +16 -0
- data/clients/sc_docs/main.js +14 -9
- data/clients/sc_docs/models/doc.js +1 -1
- data/clients/sc_docs/tests/controllers/docs.rhtml +1 -2
- data/clients/sc_docs/tests/models/doc.rhtml +1 -2
- data/clients/sc_docs/tests/views/doc_frame.rhtml +1 -2
- data/clients/sc_docs/tests/views/doc_label_view.rhtml +1 -2
- data/clients/sc_docs/views/doc_frame.js +1 -1
- data/clients/sc_test_runner/controllers/runner.js +31 -8
- data/clients/sc_test_runner/english.lproj/body.css +62 -122
- data/clients/sc_test_runner/english.lproj/body.rhtml +62 -26
- data/clients/sc_test_runner/main.js +1 -6
- data/clients/sc_test_runner/models/test.js +14 -1
- data/clients/sc_test_runner/views/runner_frame.js +4 -2
- data/clients/view_builder/builders/builder.js +339 -0
- data/clients/view_builder/builders/button.js +81 -0
- data/clients/view_builder/controllers/document.js +21 -0
- data/clients/view_builder/core.js +19 -0
- data/clients/view_builder/english.lproj/body.css +77 -0
- data/clients/view_builder/english.lproj/body.rhtml +41 -0
- data/clients/{sc_docs → view_builder}/english.lproj/controls.css +0 -0
- data/clients/view_builder/english.lproj/strings.js +14 -0
- data/clients/view_builder/main.js +38 -0
- data/clients/view_builder/tests/controllers/document.rhtml +20 -0
- data/clients/view_builder/tests/views/builder.rhtml +20 -0
- data/clients/view_builder/views/builder.js +23 -0
- data/frameworks/prototype/prototype.js +1 -1
- data/frameworks/sproutcore/Core.js +32 -7
- data/frameworks/sproutcore/README +1 -1
- data/frameworks/sproutcore/animation/animation.js +411 -0
- data/frameworks/sproutcore/controllers/array.js +17 -9
- data/frameworks/sproutcore/controllers/collection.js +9 -110
- data/frameworks/sproutcore/controllers/controller.js +1 -1
- data/frameworks/sproutcore/controllers/object.js +2 -1
- data/frameworks/sproutcore/drag/drag.js +267 -56
- data/frameworks/sproutcore/drag/drag_data_source.js +24 -16
- data/frameworks/sproutcore/drag/drag_source.js +53 -42
- data/frameworks/sproutcore/drag/drop_target.js +2 -2
- data/frameworks/sproutcore/english.lproj/buttons.css +337 -236
- data/frameworks/sproutcore/english.lproj/core.css +115 -0
- data/frameworks/sproutcore/english.lproj/icons.css +227 -0
- data/{clients/sc_docs → frameworks/sproutcore}/english.lproj/images/indicator.gif +0 -0
- data/frameworks/sproutcore/english.lproj/images/sc-theme-sprite.png +0 -0
- data/frameworks/sproutcore/english.lproj/images/sc-theme-ysprite.png +0 -0
- data/frameworks/sproutcore/english.lproj/images/shared-icons.png +0 -0
- data/frameworks/sproutcore/english.lproj/menu.css +1 -1
- data/frameworks/sproutcore/english.lproj/strings.js +1 -1
- data/frameworks/sproutcore/english.lproj/theme.css +405 -31
- data/frameworks/sproutcore/foundation/application.js +15 -11
- data/frameworks/sproutcore/foundation/benchmark.js +1 -1
- data/frameworks/sproutcore/foundation/binding.js +2 -2
- data/frameworks/sproutcore/foundation/date.js +1 -1
- data/frameworks/sproutcore/foundation/error.js +1 -1
- data/frameworks/sproutcore/foundation/input_manager.js +32 -21
- data/frameworks/sproutcore/foundation/mock.js +1 -1
- data/frameworks/sproutcore/foundation/node_descriptor.js +9 -6
- data/frameworks/sproutcore/foundation/object.js +249 -177
- data/frameworks/sproutcore/foundation/page.js +5 -2
- data/frameworks/sproutcore/foundation/path_module.js +11 -10
- data/frameworks/sproutcore/foundation/responder.js +5 -2
- data/frameworks/sproutcore/foundation/routes.js +17 -13
- data/frameworks/sproutcore/foundation/run_loop.js +249 -11
- data/frameworks/sproutcore/foundation/server.js +1 -1
- data/frameworks/sproutcore/foundation/set.js +3 -3
- data/frameworks/sproutcore/foundation/string.js +5 -3
- data/frameworks/sproutcore/foundation/timer.js +371 -0
- data/frameworks/sproutcore/foundation/undo_manager.js +1 -1
- data/frameworks/sproutcore/foundation/unittest.js +3 -3
- data/frameworks/sproutcore/foundation/utils.js +161 -2
- data/frameworks/sproutcore/globals/panels.js +1 -1
- data/frameworks/sproutcore/globals/popups.js +4 -3
- data/frameworks/sproutcore/globals/window.js +44 -4
- data/frameworks/sproutcore/lib/button_views.rb +328 -0
- data/frameworks/sproutcore/lib/collection_view.rb +80 -0
- data/frameworks/sproutcore/lib/core_views.rb +281 -0
- data/frameworks/sproutcore/lib/form_views.rb +253 -0
- data/frameworks/sproutcore/lib/index.rhtml +2 -0
- data/frameworks/sproutcore/lib/menu_views.rb +88 -0
- data/frameworks/sproutcore/{foundation → mixins}/array.js +60 -29
- data/frameworks/sproutcore/mixins/control.js +265 -0
- data/frameworks/sproutcore/mixins/delegate_support.js +66 -0
- data/frameworks/sproutcore/{foundation → mixins}/observable.js +176 -6
- data/frameworks/sproutcore/mixins/scrollable.js +245 -0
- data/frameworks/sproutcore/mixins/selection_support.js +148 -0
- data/frameworks/sproutcore/mixins/validatable.js +152 -0
- data/frameworks/sproutcore/models/collection.js +5 -5
- data/frameworks/sproutcore/models/record.js +1 -1
- data/frameworks/sproutcore/models/store.js +1 -1
- data/frameworks/sproutcore/panes/dialog.js +1 -1
- data/frameworks/sproutcore/panes/manager.js +1 -1
- data/frameworks/sproutcore/panes/menu.js +1 -1
- data/frameworks/sproutcore/panes/overlay.js +2 -2
- data/frameworks/sproutcore/panes/panel.js +1 -1
- data/frameworks/sproutcore/panes/picker.js +1 -1
- data/frameworks/sproutcore/tests/controllers/array.rhtml +44 -4
- data/frameworks/sproutcore/tests/foundation/timer/invalidate.rhtml +33 -0
- data/frameworks/sproutcore/tests/foundation/timer/invokeLater.rhtml +145 -0
- data/frameworks/sproutcore/tests/foundation/timer/isPaused.rhtml +70 -0
- data/frameworks/sproutcore/tests/foundation/timer/schedule.rhtml +145 -0
- data/frameworks/sproutcore/tests/views/{scroll.rhtml → checkbox.rhtml} +3 -3
- data/frameworks/sproutcore/tests/views/{collection.rhtml → collection/base.rhtml} +33 -32
- data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +260 -0
- data/frameworks/sproutcore/tests/views/image_cell.rhtml +19 -0
- data/frameworks/sproutcore/tests/views/label_item.rhtml +2 -4
- data/frameworks/sproutcore/tests/views/list.rhtml +2 -3
- data/frameworks/sproutcore/tests/views/list_item.rhtml +20 -0
- data/frameworks/sproutcore/tests/views/slider.rhtml +20 -0
- data/frameworks/sproutcore/tests/views/text_cell.rhtml +19 -0
- data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +395 -0
- data/frameworks/sproutcore/tests/views/view/frame.rhtml +353 -0
- data/frameworks/sproutcore/tests/views/view/innerFrame.rhtml +347 -0
- data/frameworks/sproutcore/tests/views/view/isVisibleInWindow.rhtml +148 -0
- data/frameworks/sproutcore/tests/views/view/scrollFrame.rhtml +468 -0
- data/frameworks/sproutcore/validators/credit_card.js +33 -13
- data/frameworks/sproutcore/validators/date.js +26 -6
- data/frameworks/sproutcore/validators/email.js +21 -3
- data/frameworks/sproutcore/validators/not_empty.js +11 -1
- data/frameworks/sproutcore/validators/number.js +18 -4
- data/frameworks/sproutcore/validators/password.js +12 -1
- data/frameworks/sproutcore/validators/validator.js +204 -194
- data/frameworks/sproutcore/views/{button.js → button/button.js} +96 -94
- data/frameworks/sproutcore/views/button/checkbox.js +29 -0
- data/frameworks/sproutcore/views/button/disclosure.js +42 -0
- data/frameworks/sproutcore/views/button/radio.js +29 -0
- data/frameworks/sproutcore/views/{collection.js → collection/collection.js} +1373 -1024
- data/frameworks/sproutcore/views/collection/grid.js +124 -46
- data/frameworks/sproutcore/views/collection/image_cell.js +17 -46
- data/frameworks/sproutcore/views/collection/list.js +45 -35
- data/frameworks/sproutcore/views/collection/source_list.js +386 -0
- data/frameworks/sproutcore/views/collection/table.js +118 -0
- data/frameworks/sproutcore/views/container.js +7 -2
- data/frameworks/sproutcore/views/error_explanation.js +23 -10
- data/frameworks/sproutcore/views/{checkbox_field.js → field/checkbox_field.js} +16 -6
- data/frameworks/sproutcore/views/field/field.js +219 -0
- data/frameworks/sproutcore/views/{radio_field.js → field/radio_field.js} +27 -12
- data/frameworks/sproutcore/views/{select_field.js → field/select_field.js} +116 -90
- data/frameworks/sproutcore/views/{text_field.js → field/text_field.js} +57 -8
- data/frameworks/sproutcore/views/{textarea_field.js → field/textarea_field.js} +13 -3
- data/frameworks/sproutcore/views/filter_button.js +2 -2
- data/frameworks/sproutcore/views/form.js +3 -3
- data/frameworks/sproutcore/views/image.js +128 -21
- data/frameworks/sproutcore/views/inline_text_editor.js +1 -1
- data/frameworks/sproutcore/views/label.js +149 -92
- data/frameworks/sproutcore/views/list_item.js +225 -0
- data/frameworks/sproutcore/views/menu_item.js +10 -4
- data/frameworks/sproutcore/views/pagination.js +11 -4
- data/frameworks/sproutcore/views/popup_button.js +25 -21
- data/frameworks/sproutcore/views/popup_menu.js +10 -4
- data/frameworks/sproutcore/views/progress.js +29 -16
- data/frameworks/sproutcore/views/radio_group.js +1 -1
- data/frameworks/sproutcore/views/scroll.js +60 -20
- data/frameworks/sproutcore/views/segmented.js +1 -1
- data/frameworks/sproutcore/views/slider.js +132 -0
- data/frameworks/sproutcore/views/source_list_group.js +130 -0
- data/frameworks/sproutcore/views/spinner.js +1 -1
- data/frameworks/sproutcore/views/split.js +292 -0
- data/frameworks/sproutcore/views/split_divider.js +109 -0
- data/frameworks/sproutcore/views/tab.js +1 -1
- data/frameworks/sproutcore/views/toolbar.js +1 -1
- data/frameworks/sproutcore/views/view.js +1272 -591
- data/generators/client/templates/english.lproj/body.css +1 -1
- data/generators/controller/controller_generator.rb +1 -1
- data/generators/controller/templates/test.rhtml +2 -1
- data/generators/model/templates/test.rhtml +1 -1
- data/generators/test/templates/test.rhtml +1 -1
- data/generators/view/templates/test.rhtml +1 -1
- data/jsdoc/templates/sproutcore/class.tmpl +241 -338
- data/jsdoc/templates/sproutcore/default.css +105 -155
- data/jsdoc/templates/sproutcore/index.tmpl +43 -8
- data/jsdoc/templates/sproutcore/publish.js +9 -4
- data/lib/sproutcore/build_tools/html_builder.rb +29 -13
- data/lib/sproutcore/build_tools/resource_builder.rb +1 -1
- data/lib/sproutcore/bundle.rb +86 -25
- data/lib/sproutcore/jsdoc.rb +2 -0
- data/lib/sproutcore/version.rb +1 -1
- data/lib/sproutcore/view_helpers.rb +36 -3
- data/tasks/deployment.rake +1 -1
- metadata +69 -36
- data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
- data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
- data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
- data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
- data/clients/sc_docs/english.lproj/warning.rhtml +0 -6
- data/clients/sc_test_runner/english.lproj/warning.rhtml +0 -6
- data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
- data/frameworks/sproutcore/english.lproj/collections.css +0 -82
- data/frameworks/sproutcore/english.lproj/images/buttons-sprite.png +0 -0
- data/frameworks/sproutcore/views/collection/collection_item.js +0 -36
- data/frameworks/sproutcore/views/collection/text_cell.js +0 -128
- data/frameworks/sproutcore/views/field.js +0 -214
- data/frameworks/sproutcore/views/workspace.js +0 -170
- data/generators/client/templates/english.lproj/controls.css +0 -0
- data/generators/framework/templates/english.lproj/body.css +0 -0
- data/generators/framework/templates/english.lproj/body.rhtml +0 -3
- data/generators/framework/templates/english.lproj/controls.css +0 -0
- data/lib/sproutcore/view_helpers/button_views.rb +0 -302
- data/lib/sproutcore/view_helpers/core_views.rb +0 -292
- data/lib/sproutcore/view_helpers/form_views.rb +0 -258
- data/lib/sproutcore/view_helpers/menu_views.rb +0 -94
@@ -1,24 +1,45 @@
|
|
1
1
|
// ========================================================================
|
2
2
|
// SproutCore
|
3
|
-
// copyright 2006-
|
3
|
+
// copyright 2006-2008 Sprout Systems, Inc.
|
4
4
|
// ========================================================================
|
5
5
|
|
6
6
|
require('validators/validator') ;
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
/**
|
9
|
+
Validate a field value as a credit card number.
|
10
10
|
|
11
|
-
|
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
|
-
|
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(
|
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-
|
3
|
+
// copyright 2006-2008 Sprout Systems, Inc.
|
4
4
|
// ========================================================================
|
5
5
|
|
6
6
|
require('validators/validator') ;
|
7
7
|
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
24
|
-
|
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
|
-
|
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-
|
3
|
+
// copyright 2006-2008 Sprout Systems, Inc.
|
4
4
|
// ========================================================================
|
5
5
|
|
6
6
|
require('validators/validator') ;
|
7
7
|
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
240
|
+
* 'key' or 'multiple_words' will find validators Key and MultipleWords
|
234
241
|
|
235
|
-
|
236
|
-
|
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
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
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
|
+
|