extjs-mvc 0.4.0.j → 0.4.0.k

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/Rakefile +1 -1
  2. data/VERSION +1 -1
  3. data/lib/extjs-mvc.rb +0 -14
  4. data/lib/extjs-mvc/api.rb +14 -27
  5. data/lib/extjs-mvc/src/App.js +219 -0
  6. data/lib/extjs-mvc/src/MVC.js +260 -0
  7. data/lib/extjs-mvc/src/Presenter.js +52 -0
  8. data/lib/extjs-mvc/src/README.rdoc +69 -0
  9. data/lib/extjs-mvc/src/controller/Controller.js +278 -0
  10. data/lib/extjs-mvc/src/controller/CrudController.js +460 -0
  11. data/lib/extjs-mvc/src/lib/Array.js +26 -0
  12. data/lib/extjs-mvc/src/lib/Booter.js +417 -0
  13. data/lib/extjs-mvc/src/lib/ClassManager.js +191 -0
  14. data/lib/extjs-mvc/src/lib/ControllerClassManager.js +95 -0
  15. data/lib/extjs-mvc/src/lib/Dependencies.js +44 -0
  16. data/lib/extjs-mvc/src/lib/DispatchMatcher.js +98 -0
  17. data/lib/extjs-mvc/src/lib/Dispatcher.js +129 -0
  18. data/lib/extjs-mvc/src/lib/Environment.js +43 -0
  19. data/lib/extjs-mvc/src/lib/Inflector.js +155 -0
  20. data/lib/extjs-mvc/src/lib/ModelClassManager.js +19 -0
  21. data/lib/extjs-mvc/src/lib/Route.js +139 -0
  22. data/lib/extjs-mvc/src/lib/Router.js +282 -0
  23. data/lib/extjs-mvc/src/lib/String.js +94 -0
  24. data/lib/extjs-mvc/src/lib/ViewClassManager.js +229 -0
  25. data/lib/extjs-mvc/src/lib/notes.txt +32 -0
  26. data/lib/extjs-mvc/src/model/AdapterManager.js +30 -0
  27. data/lib/extjs-mvc/src/model/Association.js +26 -0
  28. data/lib/extjs-mvc/src/model/Base.js +63 -0
  29. data/lib/extjs-mvc/src/model/BelongsToAssociation.js +116 -0
  30. data/lib/extjs-mvc/src/model/Cache.js +131 -0
  31. data/lib/extjs-mvc/src/model/HasManyAssociation.js +160 -0
  32. data/lib/extjs-mvc/src/model/Model.js +331 -0
  33. data/lib/extjs-mvc/src/model/UrlBuilder.js +106 -0
  34. data/lib/extjs-mvc/src/model/adapters/AbstractAdapter.js +296 -0
  35. data/lib/extjs-mvc/src/model/adapters/MemoryAdapter.js +103 -0
  36. data/lib/extjs-mvc/src/model/adapters/RESTAdapter.js +345 -0
  37. data/lib/extjs-mvc/src/model/adapters/RESTJSONAdapter.js +68 -0
  38. data/lib/extjs-mvc/src/model/adapters/notes.txt +42 -0
  39. data/lib/extjs-mvc/src/model/associations/Association.js +192 -0
  40. data/lib/extjs-mvc/src/model/associations/notes.txt +87 -0
  41. data/lib/extjs-mvc/src/model/validations/Errors.js +136 -0
  42. data/lib/extjs-mvc/src/model/validations/Plugin.js +139 -0
  43. data/lib/extjs-mvc/src/model/validations/Validations.js +276 -0
  44. data/lib/extjs-mvc/src/notes/Charts.graffle +0 -0
  45. data/lib/extjs-mvc/src/overrides/Ext.Component.js +21 -0
  46. data/lib/extjs-mvc/src/overrides/Ext.extend.js +142 -0
  47. data/lib/extjs-mvc/src/spec/Array.spec.js +15 -0
  48. data/lib/extjs-mvc/src/spec/ExtMVC.spec.js +65 -0
  49. data/lib/extjs-mvc/src/spec/Model.spec.js +370 -0
  50. data/lib/extjs-mvc/src/spec/OS.spec.js +83 -0
  51. data/lib/extjs-mvc/src/spec/Router.spec.js +99 -0
  52. data/lib/extjs-mvc/src/spec/SpecHelper.js +106 -0
  53. data/lib/extjs-mvc/src/spec/String.spec.js +83 -0
  54. data/lib/extjs-mvc/src/spec/model/AbstractAdapter.spec.js +49 -0
  55. data/lib/extjs-mvc/src/spec/model/Associations.spec.js +99 -0
  56. data/lib/extjs-mvc/src/spec/model/Cache.spec.js +5 -0
  57. data/lib/extjs-mvc/src/spec/model/RESTAdapter.spec.js +19 -0
  58. data/lib/extjs-mvc/src/spec/model/ValidationErrors.spec.js +64 -0
  59. data/lib/extjs-mvc/src/spec/model/Validations.spec.js +166 -0
  60. data/lib/extjs-mvc/src/spec/model/ValidationsPlugin.spec.js +108 -0
  61. data/lib/extjs-mvc/src/spec/suite.html +60 -0
  62. data/lib/extjs-mvc/src/specs-old/JSSpec.css +216 -0
  63. data/lib/extjs-mvc/src/specs-old/JSSpec.js +1512 -0
  64. data/lib/extjs-mvc/src/specs-old/all.html +66 -0
  65. data/lib/extjs-mvc/src/specs-old/base.js +14 -0
  66. data/lib/extjs-mvc/src/specs-old/controller.js +17 -0
  67. data/lib/extjs-mvc/src/specs-old/diff_match_patch.js +1 -0
  68. data/lib/extjs-mvc/src/specs-old/model.js +70 -0
  69. data/lib/extjs-mvc/src/specs-old/route.js +38 -0
  70. data/lib/extjs-mvc/src/specs-old/router.js +59 -0
  71. data/lib/extjs-mvc/src/specs-old/string.js +22 -0
  72. data/lib/extjs-mvc/src/testrunner/JSpecFormatter.js +111 -0
  73. data/lib/extjs-mvc/src/testrunner/TestClient.js +181 -0
  74. data/lib/extjs-mvc/src/testrunner/TestGrid.js +351 -0
  75. data/lib/extjs-mvc/src/testrunner/TestRunner.js +110 -0
  76. data/lib/extjs-mvc/src/testrunner/TestViewport.js +94 -0
  77. data/lib/extjs-mvc/src/vendor.yml +30 -0
  78. data/lib/extjs-mvc/src/vendor/ext-3.1.1/vendor.yml +16 -0
  79. data/lib/extjs-mvc/src/view/FormWindow.js +184 -0
  80. data/lib/extjs-mvc/src/view/HasManyEditorGridPanel.js +211 -0
  81. data/lib/extjs-mvc/src/view/scaffold/Edit.js +46 -0
  82. data/lib/extjs-mvc/src/view/scaffold/Index.js +561 -0
  83. data/lib/extjs-mvc/src/view/scaffold/New.js +20 -0
  84. data/lib/extjs-mvc/src/view/scaffold/ScaffoldFormPanel.js +255 -0
  85. data/lib/{vendor.yml → extjs-mvc/vendor.yml} +0 -0
  86. data/test/app/vendor/extjs-mvc/App.js +219 -0
  87. data/test/app/vendor/extjs-mvc/MVC.js +260 -0
  88. data/test/app/vendor/extjs-mvc/Presenter.js +52 -0
  89. data/test/app/vendor/extjs-mvc/README.rdoc +69 -0
  90. data/test/app/vendor/extjs-mvc/controller/Controller.js +278 -0
  91. data/test/app/vendor/extjs-mvc/controller/CrudController.js +460 -0
  92. data/test/app/vendor/extjs-mvc/lib/Array.js +26 -0
  93. data/test/app/vendor/extjs-mvc/lib/Booter.js +417 -0
  94. data/test/app/vendor/extjs-mvc/lib/ClassManager.js +191 -0
  95. data/test/app/vendor/extjs-mvc/lib/ControllerClassManager.js +95 -0
  96. data/test/app/vendor/extjs-mvc/lib/Dependencies.js +44 -0
  97. data/test/app/vendor/extjs-mvc/lib/DispatchMatcher.js +98 -0
  98. data/test/app/vendor/extjs-mvc/lib/Dispatcher.js +129 -0
  99. data/test/app/vendor/extjs-mvc/lib/Environment.js +43 -0
  100. data/test/app/vendor/extjs-mvc/lib/Inflector.js +155 -0
  101. data/test/app/vendor/extjs-mvc/lib/ModelClassManager.js +19 -0
  102. data/test/app/vendor/extjs-mvc/lib/Route.js +139 -0
  103. data/test/app/vendor/extjs-mvc/lib/Router.js +282 -0
  104. data/test/app/vendor/extjs-mvc/lib/String.js +94 -0
  105. data/test/app/vendor/extjs-mvc/lib/ViewClassManager.js +229 -0
  106. data/test/app/vendor/extjs-mvc/lib/notes.txt +32 -0
  107. data/test/app/vendor/extjs-mvc/model/AdapterManager.js +30 -0
  108. data/test/app/vendor/extjs-mvc/model/Association.js +26 -0
  109. data/test/app/vendor/extjs-mvc/model/Base.js +63 -0
  110. data/test/app/vendor/extjs-mvc/model/BelongsToAssociation.js +116 -0
  111. data/test/app/vendor/extjs-mvc/model/Cache.js +131 -0
  112. data/test/app/vendor/extjs-mvc/model/HasManyAssociation.js +160 -0
  113. data/test/app/vendor/extjs-mvc/model/Model.js +331 -0
  114. data/test/app/vendor/extjs-mvc/model/UrlBuilder.js +106 -0
  115. data/test/app/vendor/extjs-mvc/model/adapters/AbstractAdapter.js +296 -0
  116. data/test/app/vendor/extjs-mvc/model/adapters/MemoryAdapter.js +103 -0
  117. data/test/app/vendor/extjs-mvc/model/adapters/RESTAdapter.js +345 -0
  118. data/test/app/vendor/extjs-mvc/model/adapters/RESTJSONAdapter.js +68 -0
  119. data/test/app/vendor/extjs-mvc/model/adapters/notes.txt +42 -0
  120. data/test/app/vendor/extjs-mvc/model/associations/Association.js +192 -0
  121. data/test/app/vendor/extjs-mvc/model/associations/notes.txt +87 -0
  122. data/test/app/vendor/extjs-mvc/model/validations/Errors.js +136 -0
  123. data/test/app/vendor/extjs-mvc/model/validations/Plugin.js +139 -0
  124. data/test/app/vendor/extjs-mvc/model/validations/Validations.js +276 -0
  125. data/test/app/vendor/extjs-mvc/notes/Charts.graffle +0 -0
  126. data/test/app/vendor/extjs-mvc/overrides/Ext.Component.js +21 -0
  127. data/test/app/vendor/extjs-mvc/overrides/Ext.extend.js +142 -0
  128. data/test/app/vendor/extjs-mvc/spec/Array.spec.js +15 -0
  129. data/test/app/vendor/extjs-mvc/spec/ExtMVC.spec.js +65 -0
  130. data/test/app/vendor/extjs-mvc/spec/Model.spec.js +370 -0
  131. data/test/app/vendor/extjs-mvc/spec/OS.spec.js +83 -0
  132. data/test/app/vendor/extjs-mvc/spec/Router.spec.js +99 -0
  133. data/test/app/vendor/extjs-mvc/spec/SpecHelper.js +106 -0
  134. data/test/app/vendor/extjs-mvc/spec/String.spec.js +83 -0
  135. data/test/app/vendor/extjs-mvc/spec/model/AbstractAdapter.spec.js +49 -0
  136. data/test/app/vendor/extjs-mvc/spec/model/Associations.spec.js +99 -0
  137. data/test/app/vendor/extjs-mvc/spec/model/Cache.spec.js +5 -0
  138. data/test/app/vendor/extjs-mvc/spec/model/RESTAdapter.spec.js +19 -0
  139. data/test/app/vendor/extjs-mvc/spec/model/ValidationErrors.spec.js +64 -0
  140. data/test/app/vendor/extjs-mvc/spec/model/Validations.spec.js +166 -0
  141. data/test/app/vendor/extjs-mvc/spec/model/ValidationsPlugin.spec.js +108 -0
  142. data/test/app/vendor/extjs-mvc/spec/suite.html +60 -0
  143. data/test/app/vendor/extjs-mvc/specs-old/JSSpec.css +216 -0
  144. data/test/app/vendor/extjs-mvc/specs-old/JSSpec.js +1512 -0
  145. data/test/app/vendor/extjs-mvc/specs-old/all.html +66 -0
  146. data/test/app/vendor/extjs-mvc/specs-old/base.js +14 -0
  147. data/test/app/vendor/extjs-mvc/specs-old/controller.js +17 -0
  148. data/test/app/vendor/extjs-mvc/specs-old/diff_match_patch.js +1 -0
  149. data/test/app/vendor/extjs-mvc/specs-old/model.js +70 -0
  150. data/test/app/vendor/extjs-mvc/specs-old/route.js +38 -0
  151. data/test/app/vendor/extjs-mvc/specs-old/router.js +59 -0
  152. data/test/app/vendor/extjs-mvc/specs-old/string.js +22 -0
  153. data/test/app/vendor/extjs-mvc/testrunner/JSpecFormatter.js +111 -0
  154. data/test/app/vendor/extjs-mvc/testrunner/TestClient.js +181 -0
  155. data/test/app/vendor/extjs-mvc/testrunner/TestGrid.js +351 -0
  156. data/test/app/vendor/extjs-mvc/testrunner/TestRunner.js +110 -0
  157. data/test/app/vendor/extjs-mvc/testrunner/TestViewport.js +94 -0
  158. data/test/app/vendor/extjs-mvc/vendor.yml +30 -0
  159. data/test/app/vendor/extjs-mvc/vendor/ext-3.1.1/vendor.yml +16 -0
  160. data/test/app/vendor/extjs-mvc/view/FormWindow.js +184 -0
  161. data/test/app/vendor/extjs-mvc/view/HasManyEditorGridPanel.js +211 -0
  162. data/test/app/vendor/extjs-mvc/view/scaffold/Edit.js +46 -0
  163. data/test/app/vendor/extjs-mvc/view/scaffold/Index.js +561 -0
  164. data/test/app/vendor/extjs-mvc/view/scaffold/New.js +20 -0
  165. data/test/app/vendor/extjs-mvc/view/scaffold/ScaffoldFormPanel.js +255 -0
  166. data/test/helper.rb +7 -1
  167. data/test/test_extjs-mvc.rb +46 -0
  168. metadata +167 -7
  169. data/test/test_extjs-mvc-gem.rb +0 -7
@@ -0,0 +1,276 @@
1
+ Ext.ns('ExtMVC.model.plugin.validation');
2
+
3
+ /**
4
+ * @ignore
5
+ * The Validation classes themselves are defined here.
6
+ * Subclass ExtMVC.model.plugin.validation.AbstractValidation to create your own validations
7
+ */
8
+
9
+ /**
10
+ * @class ExtMVC.model.plugin.validation.AbstractValidation
11
+ * Base class for all validations - not used directly, but any of the following may be used:
12
+ <pre><code>
13
+ ExtMVC.model.define("SomeModel", {
14
+ fields: [
15
+ {name: 'title', type: 'string'},
16
+ {name: 'price', type: 'int'},
17
+ {name: 'stock', type: 'int'},
18
+ {name: 'gender', type: 'string'},
19
+ {name: 'colour', type: 'string'}
20
+ ],
21
+
22
+ validatesPresenceOf : ["title", "price"],
23
+ validatesLengthOf : {field: 'title', minimum: 3, maximum: 12},
24
+
25
+ validatesInclusionOf: {field: 'gender', allowed : ["Male", "Female"]},
26
+ validatesExclusionOf: {field: 'colour', disallowed: ["Red"]},
27
+ validatesFormatOf : {field: 'email', regex: /someRegex/},
28
+
29
+ validatesNumericalityOf: "stock"
30
+ });
31
+ </code></pre>
32
+ *
33
+ * Most validations will allow an array to be passed to set the validation up on more than one field (e.g.
34
+ * see the validatesPresenceOf declaration above). If only a string is provided it is assume to be the field name.
35
+ * The following are all equivalent:
36
+ <pre><code>
37
+ validatesPresenceOf: "title"
38
+ validatesPresenceOf: ["title"]
39
+ validatesPresenceOf: {field: "title"}
40
+ validatesPresenceOf: [{field: "title"}]
41
+ </code></pre>
42
+ *
43
+ * <h2>Running validations</h2>
44
+ * This plugin overrides ExtMVC.model.Base's usual isValid() function to provide feedback from the validations:
45
+ *
46
+ <pre><code>
47
+ var user = new SomeModel({title: "A really long title", colour: "Blue"});
48
+ user.isValid(); //returns false if any of the validations failed
49
+ user.errors; //returns an {@link ExtMVC.model.plugin.validation.Errors Errors} object
50
+ </code></pre>
51
+ */
52
+ ExtMVC.model.plugin.validation.AbstractValidation = function(ownerClass, field, config) {
53
+ this.ownerClass = ownerClass;
54
+ this.field = field;
55
+
56
+ Ext.apply(this, config);
57
+ };
58
+
59
+ ExtMVC.model.plugin.validation.AbstractValidation.prototype = {
60
+ /**
61
+ * Returns the current value of the field to which this validation applies
62
+ * @param {ExtMVC.model.Base} instance The model instance to get the value from
63
+ * @return {Mixed} The current value of the field
64
+ */
65
+ getValue: function(instance) {
66
+ return instance.get(this.field);
67
+ },
68
+
69
+ /**
70
+ * Empty function which must be overridden by a validation subclass. Make your function return
71
+ * true if the validation passes, false otherwise
72
+ * @return {Boolean} True if this validation passes
73
+ */
74
+ isValid: function(instance) {
75
+ return true;
76
+ }
77
+ };
78
+
79
+ /**
80
+ * @class ExtMVC.model.plugin.validation.ValidatesPresenceOf
81
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
82
+ * Ensures that a field is present. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
83
+ */
84
+ ExtMVC.model.plugin.validation.ValidatesPresenceOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
85
+ /**
86
+ * @property message
87
+ * @type String
88
+ * The textual message returned if this validation didn't pass
89
+ */
90
+ message: 'must be present',
91
+
92
+ /**
93
+ * Returns true if the field is an object or a non-empty string
94
+ * @return {Boolean} True if the field is present
95
+ */
96
+ isValid: function(instance) {
97
+ var value = this.getValue(instance),
98
+ valid = false;
99
+
100
+ switch(typeof value) {
101
+ case 'object': if (value != null) valid = true; break;
102
+ case 'string': if (value.length != 0) valid = true; break;
103
+ };
104
+
105
+ return valid;
106
+ }
107
+ });
108
+
109
+ /**
110
+ * @class ExtMVC.model.plugin.validation.ValidatesLengthOf
111
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
112
+ * Returns true if the field is within the length bounds imposed. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
113
+ */
114
+ ExtMVC.model.plugin.validation.ValidatesLengthOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
115
+
116
+ /**
117
+ * @property tooShortMessage
118
+ * @type String
119
+ * The message returned if this field was too short
120
+ */
121
+ tooShortMessage: 'is too short',
122
+
123
+ /**
124
+ * @property tooLongMessage
125
+ * @type String
126
+ * The message returned if this field was too long
127
+ */
128
+ tooLongMessage: 'is too long',
129
+
130
+ message: '',
131
+
132
+ /**
133
+ * Tests that the mimimum and maximum length of this field are met.
134
+ * Intended to be used on strings and arrays
135
+ * @return {Boolean} True if the conditions are met
136
+ */
137
+ isValid: function(instance) {
138
+ var value = this.getValue(instance);
139
+
140
+ if (typeof value == 'undefined') return true;
141
+
142
+ if (this.minimum && value.length < this.minimum) {
143
+ this.message = this.tooShortMessage;
144
+ return false;
145
+ }
146
+
147
+ if (this.maximum & value.length > this.maximum) {
148
+ this.message = this.tooLongMessage;
149
+ return false;
150
+ }
151
+
152
+ return true;
153
+ }
154
+ });
155
+
156
+ /**
157
+ * @class ExtMVC.model.plugin.validation.ValidatesNumericalityOf
158
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
159
+ * Ensures that the field is a number. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
160
+ */
161
+ ExtMVC.model.plugin.validation.ValidatesNumericalityOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
162
+ /**
163
+ * @property message
164
+ * @type String
165
+ * The message returned if this field is not a number
166
+ */
167
+ message: 'must be a number',
168
+
169
+ /**
170
+ * Returns true if the typeof this field is a number
171
+ * @return {Boolean} True if this is a number
172
+ */
173
+ isValid: function(instance) {
174
+ return 'number' == typeof this.getValue(instance);
175
+ }
176
+ });
177
+
178
+ /**
179
+ * @class ExtMVC.model.plugin.validation.ValidatesInclusionOf
180
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
181
+ * Ensures that the field is one of the allowed values. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
182
+ */
183
+ ExtMVC.model.plugin.validation.ValidatesInclusionOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
184
+
185
+
186
+ /**
187
+ * Override Abstract constructor to build the validation message
188
+ */
189
+ constructor: function(m, f, config) {
190
+ //set up defaults
191
+ config = config || {};
192
+ Ext.applyIf(config, { allowed: [] });
193
+
194
+ ExtMVC.model.plugin.validation.ValidatesInclusionOf.superclass.constructor.call(this, m, f, config);
195
+
196
+ Ext.applyIf(this, {
197
+ message: 'must be one of ' + this.allowed.toSentence('or')
198
+ });
199
+ },
200
+
201
+ /**
202
+ * Returns true if the value of this field is one of those specified in this.allowed
203
+ * @return {Boolean} True if the field's value is allowed
204
+ */
205
+ isValid: function(instance) {
206
+ var value = this.getValue(instance);
207
+
208
+ for (var i=0; i < this.allowed.length; i++) {
209
+ if (this.allowed[i] == value) return true;
210
+ };
211
+
212
+ return false;
213
+ }
214
+ });
215
+
216
+ /**
217
+ * @class ExtMVC.model.plugin.validation.ValidatesExclusionOf
218
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
219
+ * Ensures that the field is not one of the allowed values. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
220
+ */
221
+ ExtMVC.model.plugin.validation.ValidatesExclusionOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
222
+
223
+ /**
224
+ * Override Abstract constructor to build the validation message
225
+ * @ignore
226
+ */
227
+ constructor: function(m, f, config) {
228
+ //set up defaults
229
+ config = config || {};
230
+ Ext.applyIf(config, { disallowed: [] });
231
+
232
+ ExtMVC.model.plugin.validation.ValidatesExclusionOf.superclass.constructor.call(this, m, f, config);
233
+
234
+ Ext.applyIf(this, {
235
+ message: 'must not be ' + this.disallowed.toSentence('or')
236
+ });
237
+ },
238
+
239
+ /**
240
+ * Returns true if the value of this field is one of those specified in this.allowed
241
+ * @return {Boolean} True if the field's value is allowed
242
+ */
243
+ isValid: function(instance) {
244
+ var value = this.getValue(instance),
245
+ valid = true;
246
+
247
+ for (var i=0; i < this.disallowed.length; i++) {
248
+ if (this.disallowed[i] == value) valid = false;
249
+ };
250
+
251
+ return valid;
252
+ }
253
+ });
254
+
255
+ /**
256
+ * @class ExtMVC.model.plugin.validation.ValidatesFormatOf
257
+ * @extends ExtMVC.model.plugin.validation.AbstractValidation
258
+ * Ensures that the field matches the given regular expression. See {*link ExtMVC.model.plugin.validation.AbstractValidation AbstractValidation} for example.
259
+ */
260
+ ExtMVC.model.plugin.validation.ValidatesFormatOf = Ext.extend(ExtMVC.model.plugin.validation.AbstractValidation, {
261
+
262
+ /**
263
+ * @property message
264
+ * @type String
265
+ * The default message to return if this validation does not pass
266
+ */
267
+ message: 'is invalid',
268
+
269
+ /**
270
+ * Returns true if the value of this field matches the suppled regular expression
271
+ * @return {Boolean} True if the field's value matches
272
+ */
273
+ isValid: function(instance) {
274
+ return this.regex.test(this.getValue(instance));
275
+ }
276
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Override how getXTypes works so that it doesn't require that every single class has
3
+ * an xtype registered for it.
4
+ */
5
+ Ext.override(Ext.Component, {
6
+ getXTypes : function(){
7
+ var tc = this.constructor;
8
+ if(!tc.xtypes){
9
+ var c = [], sc = this;
10
+ while(sc){ //was: while(sc && sc.constructor.xtype) {
11
+ var xtype = sc.constructor.xtype;
12
+ if (xtype != undefined) c.unshift(xtype);
13
+
14
+ sc = sc.constructor.superclass;
15
+ }
16
+ tc.xtypeChain = c;
17
+ tc.xtypes = c.join('/');
18
+ }
19
+ return tc.xtypes;
20
+ }
21
+ });
@@ -0,0 +1,142 @@
1
+ // /**
2
+ // * An extension to Ext.extend which calls the extended object's onExtended function, if it exists
3
+ // * The only lines that are different from vanilla Ext.extend are the 2 before the return sb statement
4
+ // */
5
+ // Ext.extend = function(){
6
+ // // inline overrides
7
+ // var io = function(o){
8
+ // for(var m in o){
9
+ // this[m] = o[m];
10
+ // }
11
+ // };
12
+ // var oc = Object.prototype.constructor;
13
+ //
14
+ // return function(sb, sp, overrides){
15
+ // if(Ext.isObject(sp)){
16
+ // overrides = sp;
17
+ // sp = sb;
18
+ // sb = overrides.constructor!= oc ? overrides.constructor : function(){sp.apply(this, arguments);};
19
+ // }
20
+ // var F = function(){},
21
+ // sbp,
22
+ // spp = sp.prototype;
23
+ //
24
+ // F.prototype = spp;
25
+ // sbp = sb.prototype = new F();
26
+ // sbp.constructor=sb;
27
+ // sb.superclass=spp;
28
+ // if(spp.constructor == oc){
29
+ // spp.constructor=sp;
30
+ // }
31
+ // sb.override = function(o){
32
+ // Ext.override(sb, o);
33
+ // };
34
+ // sbp.superclass = sbp.supr = (function(){
35
+ // return spp;
36
+ // });
37
+ // sbp.override = io;
38
+ // Ext.override(sb, overrides);
39
+ // sb.extend = function(o){Ext.extend(sb, o);};
40
+ //
41
+ // var extendFunction = sb.prototype.onExtended;
42
+ // if (extendFunction) extendFunction.call(sb.prototype);
43
+ //
44
+ // return sb;
45
+ // };
46
+ // }();
47
+
48
+ // (function() {
49
+ // var inlineOverrides = function(o) {
50
+ // for(var m in o){
51
+ // this[m] = o[m];
52
+ // }
53
+ // };
54
+ //
55
+ // //reference to the constructor of Object - we can match against this so as not to extend improperly
56
+ // var objectConstructor = Object.prototype.constructor;
57
+ //
58
+ // /**
59
+ // * Returns true if the given function is the bottom level Object object. We use this to test if we are
60
+ // * extending Object directly, or some subclass of Object.
61
+ // * @param {Object} superclass The superclass constructor function
62
+ // */
63
+ // var superclassIsObject = function(superclass) {
64
+ // return superclass.prototype.constructor == objectConstructor;
65
+ // };
66
+ //
67
+ // Ext.extend = function() {
68
+ // //this method has two different signatures - 2 or 3 arguments
69
+ // if (arguments.length == 3) {
70
+ // // 3 arguments - where we're given the subclass constructor function, the superclass and some overrides
71
+ // var subclassConstructor = arguments[0],
72
+ // superclass = arguments[1],
73
+ // overrides = arguments[2];
74
+ // } else {
75
+ // // 2 arguments - where we're just given the superclass and some overrides
76
+ // var superclass = arguments[0],
77
+ // overrides = arguments[1];
78
+ //
79
+ // // Because we weren't given a subclass constructor, make one now
80
+ // var subclassConstructor = overrides.constructor == objectConstructor
81
+ // ? function(){superclass.apply(this, arguments);} //TODO: Explain this
82
+ // : overrides.constructor;
83
+ // }
84
+ //
85
+ // //This is the beginnings of our new class - just an empty function for now
86
+ // var F = function() {};
87
+ //
88
+ // //set our new class' prototype to the same as the superclass
89
+ // F.prototype = superclass.prototype;
90
+ //
91
+ // // This is where the actual 'inheritance' happens. In JavaScript we extend objects by setting the prototype
92
+ // // of a new object to an instance of an existing one
93
+ // subclassConstructor.prototype = new F();
94
+ //
95
+ // // We'll use the subclass and superclass prototypes a lot, so get references to them here
96
+ // var subclassProto = subclassConstructor.prototype,
97
+ // superclassProto = superclass.prototype;
98
+ //
99
+ // //Tell our new subclass its constructor
100
+ // subclassProto.constructor = subclassConstructor;
101
+ //
102
+ // //TODO: Here we're giving the subclass's constructor FUNCTION a supertype property, which is set to the prototype
103
+ // //of the supertype... why?
104
+ // subclassConstructor.superclass = superclass.prototype;
105
+ //
106
+ // // TODO: Explain this
107
+ // if (superclassIsObject(superclass)) superclassProto.constructor = superclass;
108
+ //
109
+ // //This is what enables your to do things like MyExtendedClass.superclass.initComponent.apply(this, arguments);
110
+ // subclassProto.superclass = subclassProto.supr = function() {
111
+ // return superclassProto;
112
+ // };
113
+ //
114
+ // subclassProto.override = inlineOverrides;
115
+ // Ext.override(subclassConstructor, overrides);
116
+ //
117
+ // //Here we're adding override and extend to the constructor Function itself... for some reason (e.g. Ext.Window.override({}))
118
+ // Ext.apply(subclassConstructor, {
119
+ // extend: function(o){
120
+ // Ext.extend(subclassConstructor, o);
121
+ // },
122
+ // override: function(o) {
123
+ // Ext.override(subclassConstructor, o);
124
+ // }
125
+ // });
126
+ //
127
+ // return subclassConstructor;
128
+ // };
129
+ // })();
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
@@ -0,0 +1,15 @@
1
+ Screw.Unit(function() {
2
+ describe("Array extensions", function() {
3
+ describe("toSentence", function() {
4
+ var array = ['Adama', 'Tigh', 'Roslin'];
5
+
6
+ it("should join an array using and by default", function() {
7
+ expect(array.toSentence()).to(equal, "Adama, Tigh and Roslin");
8
+ });
9
+
10
+ it("should allow specification of a custom connector string", function() {
11
+ expect(array.toSentence('or')).to(equal, "Adama, Tigh or Roslin");
12
+ });
13
+ });
14
+ });
15
+ });