extjs-mvc 0.3.10 → 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +5 -173
  3. data/Rakefile +18 -20
  4. data/VERSION +1 -1
  5. data/bin/xmvc +13 -0
  6. data/lib/extjs-mvc/README +20 -0
  7. data/lib/extjs-mvc/builder.rb +83 -0
  8. data/lib/extjs-mvc/builders/all_builder.rb +15 -0
  9. data/lib/extjs-mvc/builders/app_builder.rb +36 -0
  10. data/lib/extjs-mvc/builders/base.rb +138 -0
  11. data/lib/extjs-mvc/builders/css_builder.rb +36 -0
  12. data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
  13. data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
  14. data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
  15. data/lib/extjs-mvc/cli.rb +52 -0
  16. data/lib/extjs-mvc/generator.rb +79 -0
  17. data/lib/extjs-mvc/generators/app.rb +57 -0
  18. data/lib/extjs-mvc/generators/base.rb +53 -0
  19. data/lib/extjs-mvc/generators/controller.rb +41 -0
  20. data/lib/extjs-mvc/generators/model.rb +41 -0
  21. data/lib/extjs-mvc/generators/scaffold.rb +17 -0
  22. data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
  23. data/lib/extjs-mvc/generators/templates/Model.js +9 -0
  24. data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
  25. data/lib/extjs-mvc/generators/templates/View.js +16 -0
  26. data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
  27. data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
  28. data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
  29. data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
  30. data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
  31. data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
  32. data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
  33. data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
  34. data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
  35. data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
  36. data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
  37. data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
  38. data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
  39. data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
  40. data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
  41. data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
  42. data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
  43. data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
  44. data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
  45. data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
  46. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
  47. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
  48. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
  49. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  50. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
  51. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
  52. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
  53. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  54. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
  55. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
  56. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
  57. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
  58. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
  59. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  60. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
  61. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
  62. data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
  63. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
  64. data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
  65. data/lib/extjs-mvc/generators/view.rb +29 -0
  66. data/lib/extjs-mvc/plugin.rb +105 -0
  67. data/lib/extjs-mvc/scripts.rb +15 -0
  68. data/lib/extjs-mvc/settings.rb +75 -0
  69. data/lib/extjs-mvc/setup.rb +5 -0
  70. data/lib/extjs-mvc/stats.rb +241 -0
  71. data/lib/extjs-mvc/test.rb +11 -0
  72. data/lib/extjs-mvc/testserver.ru +95 -0
  73. data/lib/extjs-mvc/ui.rb +58 -0
  74. data/lib/extjs-mvc/update.rb +73 -0
  75. data/lib/extjs-mvc.rb +70 -32
  76. data/lib/js/App.js +219 -0
  77. data/lib/js/MVC.js +260 -0
  78. data/lib/js/Presenter.js +52 -0
  79. data/lib/js/README.rdoc +69 -0
  80. data/lib/js/build +21 -0
  81. data/lib/js/controller/Controller.js +278 -0
  82. data/lib/js/controller/CrudController.js +460 -0
  83. data/lib/js/lib/Array.js +26 -0
  84. data/lib/js/lib/Booter.js +415 -0
  85. data/lib/js/lib/ClassManager.js +191 -0
  86. data/lib/js/lib/ControllerClassManager.js +95 -0
  87. data/lib/js/lib/Dependencies.js +44 -0
  88. data/lib/js/lib/DispatchMatcher.js +98 -0
  89. data/lib/js/lib/Dispatcher.js +129 -0
  90. data/lib/js/lib/Environment.js +43 -0
  91. data/lib/js/lib/Inflector.js +138 -0
  92. data/lib/js/lib/ModelClassManager.js +19 -0
  93. data/lib/js/lib/Route.js +139 -0
  94. data/lib/js/lib/Router.js +282 -0
  95. data/lib/js/lib/String.js +94 -0
  96. data/lib/js/lib/ViewClassManager.js +229 -0
  97. data/lib/js/lib/notes.txt +32 -0
  98. data/lib/js/model/AdapterManager.js +30 -0
  99. data/lib/js/model/Association.js +26 -0
  100. data/lib/js/model/Base.js +63 -0
  101. data/lib/js/model/BelongsToAssociation.js +116 -0
  102. data/lib/js/model/Cache.js +131 -0
  103. data/lib/js/model/HasManyAssociation.js +160 -0
  104. data/lib/js/model/Model.js +331 -0
  105. data/lib/js/model/UrlBuilder.js +106 -0
  106. data/lib/js/model/adapters/AbstractAdapter.js +296 -0
  107. data/lib/js/model/adapters/MemoryAdapter.js +103 -0
  108. data/lib/js/model/adapters/RESTAdapter.js +345 -0
  109. data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
  110. data/lib/js/model/adapters/notes.txt +42 -0
  111. data/lib/js/model/associations/Association.js +192 -0
  112. data/lib/js/model/associations/notes.txt +87 -0
  113. data/lib/js/model/validations/Errors.js +136 -0
  114. data/lib/js/model/validations/Plugin.js +139 -0
  115. data/lib/js/model/validations/Validations.js +276 -0
  116. data/lib/js/notes/Charts.graffle +0 -0
  117. data/lib/js/overrides/Ext.Component.js +21 -0
  118. data/lib/js/overrides/Ext.extend.js +142 -0
  119. data/lib/js/spec/Array.spec.js +15 -0
  120. data/lib/js/spec/ExtMVC.spec.js +65 -0
  121. data/lib/js/spec/Model.spec.js +370 -0
  122. data/lib/js/spec/OS.spec.js +83 -0
  123. data/lib/js/spec/Router.spec.js +99 -0
  124. data/lib/js/spec/SpecHelper.js +106 -0
  125. data/lib/js/spec/String.spec.js +83 -0
  126. data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
  127. data/lib/js/spec/model/Associations.spec.js +99 -0
  128. data/lib/js/spec/model/Cache.spec.js +5 -0
  129. data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
  130. data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
  131. data/lib/js/spec/model/Validations.spec.js +166 -0
  132. data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
  133. data/lib/js/spec/suite.html +60 -0
  134. data/lib/js/specs-old/JSSpec.css +216 -0
  135. data/lib/js/specs-old/JSSpec.js +1512 -0
  136. data/lib/js/specs-old/all.html +66 -0
  137. data/lib/js/specs-old/base.js +14 -0
  138. data/lib/js/specs-old/controller.js +17 -0
  139. data/lib/js/specs-old/diff_match_patch.js +1 -0
  140. data/lib/js/specs-old/model.js +70 -0
  141. data/lib/js/specs-old/route.js +38 -0
  142. data/lib/js/specs-old/router.js +59 -0
  143. data/lib/js/specs-old/string.js +22 -0
  144. data/lib/js/testrunner/JSpecFormatter.js +111 -0
  145. data/lib/js/testrunner/TestClient.js +181 -0
  146. data/lib/js/testrunner/TestGrid.js +351 -0
  147. data/lib/js/testrunner/TestRunner.js +110 -0
  148. data/lib/js/testrunner/TestViewport.js +94 -0
  149. data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
  150. data/lib/js/vendor/screw-unit/LICENSE +22 -0
  151. data/lib/js/vendor/screw-unit/README.markdown +307 -0
  152. data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  153. data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
  154. data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
  155. data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
  156. data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  157. data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
  158. data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
  159. data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
  160. data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
  161. data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
  162. data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  163. data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
  164. data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
  165. data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
  166. data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
  167. data/lib/js/view/FormWindow.js +184 -0
  168. data/lib/js/view/HasManyEditorGridPanel.js +211 -0
  169. data/lib/js/view/scaffold/Edit.js +46 -0
  170. data/lib/js/view/scaffold/Index.js +561 -0
  171. data/lib/js/view/scaffold/New.js +20 -0
  172. data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
  173. data/test/helper.rb +10 -0
  174. data/test/test_extjs-mvc-gem.rb +7 -0
  175. metadata +232 -56
  176. data/README +0 -12
  177. data/lib/controller/controller.rb +0 -28
  178. data/lib/core_ext/array/extract_options.rb +0 -15
  179. data/lib/extjs/component.rb +0 -71
  180. data/lib/extjs/data/store.rb +0 -131
  181. data/lib/helpers/component.rb +0 -37
  182. data/lib/helpers/store.rb +0 -7
  183. data/lib/model/active_record.rb +0 -89
  184. data/lib/model/base.rb +0 -370
  185. data/lib/model/data_mapper.rb +0 -66
  186. data/lib/model/mongo_mapper.rb +0 -64
  187. data/lib/test/macros.rb +0 -20
  188. data/test/app/config/application.rb +0 -70
  189. data/test/app/config/database.yml +0 -3
  190. data/test/app/db/schema.rb +0 -75
  191. data/test/app/models/active_record/address.rb +0 -4
  192. data/test/app/models/active_record/data_type.rb +0 -3
  193. data/test/app/models/active_record/group.rb +0 -4
  194. data/test/app/models/active_record/house.rb +0 -4
  195. data/test/app/models/active_record/location.rb +0 -5
  196. data/test/app/models/active_record/person.rb +0 -4
  197. data/test/app/models/active_record/user.rb +0 -6
  198. data/test/app/models/active_record/user_group.rb +0 -4
  199. data/test/component_test.rb +0 -15
  200. data/test/debug.log +0 -2969
  201. data/test/model_test.rb +0 -526
  202. data/test/mongo_mapper_test.rb +0 -0
  203. data/test/store_test.rb +0 -0
  204. data/test/test_helper.rb +0 -32
@@ -0,0 +1,282 @@
1
+ /**
2
+ * @class ExtMVC.router.Router
3
+ * @extends Object
4
+ * TODO: [DOCS] Give a good description of the Router
5
+ */
6
+ ExtMVC.router.Router = function() {};
7
+
8
+ ExtMVC.router.Router.prototype = {
9
+
10
+ /**
11
+ * @property mappings
12
+ * @type Array
13
+ * Readonly. Maintains the collection of defined routes
14
+ */
15
+ mappings: [],
16
+
17
+ /**
18
+ * @property namedRoutes
19
+ * @type Object
20
+ * Readonly. Maintains the collection of named routes
21
+ */
22
+ namedRoutes: {},
23
+
24
+ /**
25
+ * Adds a new route to the collection. Routes are given priority in the order they are added
26
+ * @param {String} re The regular expression-style string to match (e.g. ":controller/:action/:id")
27
+ * @param {Object} additional_params Any additional options which will be returned along with the match elements if the route matches
28
+ * @return {ExtMVC.router.Route} The newly created route object
29
+ */
30
+ connect: function(re, additional_params) {
31
+ var route = new ExtMVC.router.Route(re, additional_params);
32
+ this.mappings.push(route);
33
+
34
+ return route;
35
+ },
36
+
37
+ /**
38
+ * Defines a named route. This is the same as using connect, but with the option to specify the route by name. e.g.:
39
+ * this.name('myRoute', 'my/custom/route/:id', {controller: 'myController', action: 'myAction'});
40
+ * this.urlFor('myRoute', {id: 100}); //returns 'my/custom/route/100'
41
+ * @param {String} routeName The string name to give this route
42
+ * @param {String} re The regular expression-style string to match (e.g. ":controller/:action/:id")
43
+ * @param {Object} additional_params Any additional options which will be returned along with the match elements if the route matches
44
+ */
45
+ name: function(routeName, re, additional_params) {
46
+ this.namedRoutes[routeName] = this.connect(re, additional_params);
47
+ },
48
+
49
+ /**
50
+ * Same as calling connect("", options) - connects the empty route string to a controller/action pair
51
+ * @params {Object} options An object containing at least a controller and optionally an action (which is otherwise defaulted to index)
52
+ */
53
+ root: function(options) {
54
+ var options = options || {};
55
+ this.connect("", Ext.applyIf(options, { action: 'index' }));
56
+ },
57
+
58
+ /**
59
+ * Adds specific index, new, show and edit routes for this resource. e.g.:
60
+ * resources('videos') is equivalent to:
61
+ * name('videos_path', 'videos', {controller: 'videos', action: 'index'});
62
+ * name('new_video_path', 'videos/new', {controller: 'videos', action: 'new' });
63
+ * name('video_path', 'videos/:id', {controller: 'videos', action: 'show' });
64
+ * name('edit_video_path', 'videos/:id/edit', {controller: 'videos', action: 'edit' });
65
+ *
66
+ * You can pass a second parameter which is an options object, e.g.:
67
+ * resources('videos', {controller: 'myController', myKey: 'myValue'}) sets up the following:
68
+ * name('videos_path', 'videos', {controller: 'myController', myKey: 'myValue', action: 'index'});
69
+ * name('new_video_path', 'videos/new', {controller: 'myController', myKey: 'myValue', action: 'new' });
70
+ * name('video_path', 'videos/:id', {controller: 'myController', myKey: 'myValue', action: 'show' });
71
+ * name('edit_video_path', 'videos/:id/edit', {controller: 'myController', myKey: 'myValue', action: 'edit' });
72
+ *
73
+ * Also accepts a series of arguments - resources('videos', 'bookmarks', 'messages')
74
+ * is the same as calling resources with each
75
+ *
76
+ * Finally, this format is also accepted:
77
+ * resources('videos', 'bookmarks', 'messages', {controller: 'myController', myKey: 'myValue'})
78
+ * Which is equivalent to calling resources with each of the three strings in turn, each with the
79
+ * final argument passed as options
80
+ */
81
+ resources: function(resource_name, options) {
82
+ //if we have been passed a bunch of strings, call resources with each
83
+ if (arguments[1] && typeof(arguments[1]) == 'string') {
84
+ var lastArg = arguments[arguments.length - 1];
85
+
86
+ var opts = (typeof(lastArg) == 'object') ? lastArg : {};
87
+
88
+ for (var i=0; i < arguments.length; i++) {
89
+ //don't call with the last argument if it is an object as this is a generic settings object
90
+ if (!(lastArg === arguments[i] && typeof(lastArg) == 'object')) {
91
+ this.resources(arguments[i], opts);
92
+ };
93
+ };
94
+
95
+ return;
96
+ };
97
+
98
+ //work out the named route names for index, show, new and edit actions
99
+ var indexName = String.format("{0}_path", resource_name.pluralize() );
100
+ var newName = String.format("new_{0}_path", resource_name.singularize());
101
+ var showName = String.format("{0}_path", resource_name.singularize());
102
+ var editName = String.format("edit_{0}_path", resource_name.singularize());
103
+
104
+ //add named routes for index, new, edit and show
105
+ this.name(indexName, resource_name, Ext.apply({}, {controller: resource_name, action: 'index'}));
106
+ this.name(newName, resource_name + '/new', Ext.apply({}, {controller: resource_name, action: 'new' }));
107
+ this.name(showName, resource_name + '/:id', Ext.apply({}, {controller: resource_name, action: 'show', conditions: {':id': "[0-9]+"}}));
108
+ this.name(editName, resource_name + '/:id/edit', Ext.apply({}, {controller: resource_name, action: 'edit', conditions: {':id': "[0-9]+"}}));
109
+ },
110
+
111
+ /**
112
+ * Given a hash containing at route segment options (e.g. {controller: 'index', action: 'welcome'}),
113
+ * attempts to generate a url and redirect to it using Ext.History.add.
114
+ * All arguments are passed through to this.urlFor()
115
+ * @param {Object} options An object containing url segment options (such as controller and action)
116
+ * @return {Boolean} True if a url was generated and redirected to
117
+ */
118
+ redirectTo: function() {
119
+ var url = this.urlFor.apply(this, arguments);
120
+ if (url) {
121
+ Ext.History.add(url);
122
+ return true;
123
+ } else return false;
124
+ },
125
+
126
+ /**
127
+ * Constructs and returns a config object for a Ext.History based link to a given url spec. This does not create
128
+ * an Ext.Component, only a shortcut to its config. This is intended for use in quickly generating menu items
129
+ * @param {Object} urlOptions A standard url generation object, e.g. {controller: 'index', action: 'welcome'}
130
+ * @param {Object} linkOptions Options for the link itself, e.g. {text: 'My Link Text'}
131
+ * @return {Object} a constructed config object for the given parameters
132
+ */
133
+ linkTo: function(urlOptions, linkOptions) {
134
+ var linkOptions = linkOptions || {};
135
+
136
+ var url = this.urlFor(urlOptions);
137
+ if (url) {
138
+ return Ext.applyIf(linkOptions, {
139
+ url: url,
140
+ cls: [urlOptions.controller, urlOptions.action, urlOptions.id].join("-").replace("--", "-").replace(/-$/, ""),
141
+ text: this.constructDefaultLinkToName(urlOptions, linkOptions),
142
+ handler: function() {Ext.History.add(url);}
143
+ });
144
+ } else throw new Error("No match for that url specification");
145
+ },
146
+
147
+ /**
148
+ * Attempts to create good link name for a given object containing action and controller. Override with your own
149
+ * function to create custom link names for your app
150
+ * @param {Object} urlOptions An object containing at least controller and action properties
151
+ * @param {Object} linkOptions An object of arbitrary options for the link, initially passed to linkTo. Not used
152
+ * in default implementation but could be useful when overriding this method
153
+ * @return {String} The best-guess link name for the given params.
154
+ */
155
+ constructDefaultLinkToName: function(urlOptions, linkOptions) {
156
+ if (!urlOptions || !urlOptions.controller || !urlOptions.action) {return "";}
157
+ var linkOptions = linkOptions || {};
158
+
159
+ Ext.applyIf(linkOptions, {
160
+ singularName: urlOptions.controller.singularize()
161
+ });
162
+
163
+ var actionName = urlOptions.action.titleize();
164
+ if (actionName == 'Index') {
165
+ return "Show " + urlOptions.controller.titleize();
166
+ } else {
167
+ return actionName + " " + linkOptions.singularName.titleize();
168
+ }
169
+ },
170
+
171
+ /**
172
+ * @params {String} url The url to be matched by the Router. Router will match against
173
+ * all connected matchers in the order they were connected and return an object created
174
+ * by parsing the url with the first matching matcher as defined using the connect() method
175
+ * @returns {Object} Object of all matches to this url
176
+ */
177
+ recognise: function(url) {
178
+ for (var i=0; i < this.mappings.length; i++) {
179
+ var m = this.mappings[i];
180
+ var match = m.matchesFor(url);
181
+ if (match) { return match; }
182
+ };
183
+
184
+ return false;
185
+ },
186
+
187
+ /**
188
+ * Takes an object of url generation options such as controller and action. Returns a generated url.
189
+ * For a url to be generated, all of these options must match the requirements of at least one route definition
190
+ * @param {Object/String} options An object containing url options, or a named route string.
191
+ * @param {Object} namedRouteOptions If using a named route, this object is passed as additional parameters. e.g:
192
+ * this.name('myRoute', 'my/custom/route/:id', {controller: 'myController', action: 'myAction'});
193
+ * this.urlFor('myRoute', {id: 100}); //returns 'my/custom/route/100'
194
+ * this.urlFor('myRoute', 100); //returns 'my/custom/route/100' - number argument assumed to be an ID
195
+ * this.urlFor('myRoute', modelObj); //returns 'my/custom/route/100' if modelObj is a model object where modelObj.data.id = 100
196
+ * @return {String} The generated url, or false if there was no match
197
+ */
198
+ urlFor: function(options, namedRouteOptions) {
199
+ var route;
200
+
201
+ //named route
202
+ if (typeof(options) == 'string') {
203
+ if (route = this.namedRoutes[options]) {
204
+ var namedRouteOptions = namedRouteOptions || {};
205
+
206
+ //normalise named route options in case we're passed an integer
207
+ if (typeof(namedRouteOptions) == 'number') {
208
+ namedRouteOptions = {id: namedRouteOptions};
209
+ };
210
+
211
+ //normalise named route options in case we're passed a model instance
212
+ if (namedRouteOptions.data && namedRouteOptions.data.id) {
213
+ namedRouteOptions = {id: namedRouteOptions.data.id};
214
+ };
215
+
216
+ return route.urlForNamed(namedRouteOptions);
217
+ };
218
+ }
219
+ //non-named route
220
+ else {
221
+ for (var i=0; i < this.mappings.length; i++) {
222
+ route = this.mappings[i]; var u = route.urlFor(options);
223
+ if (u) { return u; }
224
+ };
225
+ };
226
+
227
+ //there were no matches so return false
228
+ return false;
229
+ },
230
+
231
+ /**
232
+ * Immediately redirects to the specified route.
233
+ * @param {String} route The route
234
+ */
235
+ route: function(route) {
236
+ document.location.hash = route;
237
+ },
238
+
239
+ /**
240
+ * Creates a handler for redirecting to the specified route
241
+ * @param {String} route The route
242
+ * @return {Function} handler A function that redirects to the route
243
+ */
244
+ handleRoute: function(url) {
245
+ return this.route.createDelegate(this, [url]);
246
+ },
247
+
248
+ //experimental...
249
+ withOptions: function(options, routes) {
250
+ var options = options || {};
251
+
252
+ var defaultScope = this;
253
+ var optionScope = {};
254
+
255
+ optionScope.prototype = this;
256
+ Ext.apply(optionScope, {
257
+ connect: function(re, additional_params) {
258
+ var additional_params = additional_params || {};
259
+ Ext.applyIf(additional_params, options);
260
+
261
+ defaultScope.connect.call(defaultScope, re, additional_params);
262
+ },
263
+
264
+ name: function(routeName, re, additional_params) {
265
+ var additional_params = additional_params || {};
266
+ Ext.applyIf(additional_params, options);
267
+
268
+ defaultScope.name.call(defaultScope, routeName, re, additional_params);
269
+ }
270
+ });
271
+
272
+ routes.call(this, optionScope);
273
+ }
274
+ };
275
+
276
+ /**
277
+ * Basic default routes. Redefine this method inside config/routes.js
278
+ */
279
+ ExtMVC.router.Router.defineRoutes = function(map) {
280
+ map.connect(":controller/:action");
281
+ map.connect(":controller/:action/:id");
282
+ };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @class String
3
+ * Extensions to the String class
4
+ **/
5
+
6
+ /**
7
+ * Capitalizes a string (e.g. ("some test sentence").capitalize() == "Some test sentence")
8
+ * @return {String} The capitalized String
9
+ */
10
+ String.prototype.capitalize = function() {
11
+ return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
12
+ };
13
+
14
+ /**
15
+ * Puts the string in Title Case (e.g. ("some test sentence").titleize() == "Some Test Sentence")
16
+ * @return {String} The titleized String
17
+ */
18
+ String.prototype.titleize = function() {
19
+ return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
20
+ };
21
+
22
+ /**
23
+ * Takes any string and de-underscores and uppercases it
24
+ * e.g. long_underscored_string => LongUnderscoredString
25
+ */
26
+ String.prototype.camelize = function() {
27
+ return this.replace(/_/g, " ").titleize().replace(/ /g, "");
28
+ };
29
+
30
+ /**
31
+ * Underscores a string (e.g. (("SomeCamelizedString").underscore() == 'some_camelized_string',
32
+ * ("some normal string").underscore() == 'some_normal_string')
33
+ * @return {String} The underscored string
34
+ */
35
+ String.prototype.underscore = function() {
36
+ return this.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/ /g, "_").replace(/^_/, '');
37
+ };
38
+
39
+ /**
40
+ * Uses the Inflector to singularize itself (e.g. ("cats").singularize() == 'cat')
41
+ * @return {String} The singularized version of this string
42
+ */
43
+ String.prototype.singularize = function() {
44
+ return ExtMVC.Inflector.singularize(this);
45
+ };
46
+
47
+ /**
48
+ * Uses the Inflector to pluralize itself (e.g. ("cat").pluralize() == 'cats')
49
+ * @return {String} The pluralized version of this string
50
+ */
51
+ String.prototype.pluralize = function() {
52
+ return ExtMVC.Inflector.pluralize(this);
53
+ };
54
+
55
+ /**
56
+ * Attempts to humanize a name by replacing underscores with spaces. Mainly useful for Ext.Model.Base
57
+ * @return {String} The humanized string
58
+ */
59
+ String.prototype.humanize = function() {
60
+ return this.underscore().replace(/_/g, " ");
61
+ };
62
+
63
+ /**
64
+ * Replaces instances of the strings &, >, < and " with their escaped versions
65
+ * @return {String} The escaped version of the original text
66
+ */
67
+ String.prototype.escapeHTML = function () {
68
+ return this.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;');
69
+ };
70
+
71
+ /**
72
+ * Converts this string into a currency, prepended with the given currency symbol
73
+ * @param {String} symbol The currency symbol to use (defaults to $)
74
+ */
75
+ String.prototype.toCurrency = function(symbol) {
76
+ if (typeof(symbol) == 'undefined') {var symbol = '$';}
77
+
78
+ var beforeDecimal = this.split(".")[0],
79
+ afterDecimal = this.split(".")[1];
80
+
81
+ var segmentCount = Math.floor(beforeDecimal.length / 3);
82
+ var firstSegmentWidth = beforeDecimal.length % 3,
83
+ pointerPosition = firstSegmentWidth;
84
+
85
+ var segments = firstSegmentWidth == 0 ? [] : [beforeDecimal.substr(0, firstSegmentWidth)];
86
+
87
+ for (var i=0; i < segmentCount; i++) {
88
+ segments.push(beforeDecimal.substr(firstSegmentWidth + (i * 3), 3));
89
+ };
90
+
91
+ beforeDecimal = symbol + segments.join(",");
92
+
93
+ return afterDecimal ? String.format("{0}.{1}", beforeDecimal, afterDecimal) : beforeDecimal;
94
+ };
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @class ExtMVC.lib.ViewClassManager
3
+ * @extends ExtMVC.lib.ClassManager
4
+ * Customised class manager for views. Views differ from most other classes as they are namespaced
5
+ * by view package, so they take namespace and name when registering.
6
+ * VCM will attempt to recursively define view classes that extend others, so if a view's xtype hasn't
7
+ * been registered with Ext.ComponentMgr yet, VCM will attempt to find that xtype by seeing if any of
8
+ * the other registered views have declared that xtype via the 'registerXType' property. If one is found,
9
+ * VCM will either return its constructor if it is already defined, otherwise it will try to define it first,
10
+ * again recursing up the inheritance stack if necessary. Example:
11
+ <pre>
12
+ vcm.register('somePackage', 'someView', {
13
+ xtype: 'anotherview' //this doesn't exist yet
14
+ });
15
+
16
+ //anotherview extends the 'myxtype' type, which hasn't been defined yet
17
+ vcm.register('somePackage', 'someOtherView', {
18
+ xtype: 'myxtype',
19
+ registerXType: 'anotherview'
20
+ });
21
+
22
+ //myview extends panel, and is registered with the 'myxtype' xtype
23
+ vcm.register('somepackage', 'myview', {
24
+ xtype: 'panel',
25
+ registerXType: 'myxtype'
26
+ });
27
+
28
+ When vcm.getConstructor('somepackage', 'someview') is called, it looks to see if 'anotherview' has
29
+ been registered with Ext.ComponentMgr first. If it has, it just calls Ext.extend with the config included
30
+ when registering 'someview', extending the constructor of 'anotherview', and returns the result.
31
+
32
+ If 'anotherview' hasn't yet been registered with Ext.ComponentMgr, it is automatically defined first with
33
+ this.define. In this case, the parent class of 'anotherview' ('myxtype') hasn't been defined yet either,
34
+ so again the inheritance chain is automatically traversed, 'myview' is defined and registered to 'myxtype',
35
+ and the resulting extended class constructor returned so that 'anotherview' can in turn be extended.
36
+ </pre>
37
+ */
38
+ ExtMVC.lib.ViewClassManager = Ext.extend(ExtMVC.lib.ClassManager, {
39
+ autoDefine: false,
40
+
41
+ /**
42
+ * Uses Ext.extend to define a previously registered view class config into a full class.
43
+ * The new class constructor is then cached in this.constructors, keyed by name.
44
+ * @param {String} name The name of the view to turn from config object to class constructor
45
+ */
46
+ define: function define(name) {
47
+ var overrides = this.getRegistered(name);
48
+ if (overrides == undefined) this.throwViewNotFoundError(name);
49
+
50
+ var xtype = overrides.xtype || 'panel';
51
+
52
+ delete overrides.xtype;
53
+
54
+ //extend the class, register it if required
55
+ var constructor = this.getConstructorForXType(xtype);
56
+ var klass = Ext.extend(constructor, overrides);
57
+
58
+ if (klass == undefined) {
59
+ throw new Error(
60
+ String.format("The {0} view could not be created because the xtype you supplied ('{1}') could not be found", name, overrides.xtype)
61
+ );
62
+ }
63
+
64
+ var newXType = overrides.registerXType;
65
+ if (newXType) {
66
+ Ext.reg(newXType, klass);
67
+ this.xtypeLookup[newXType] = klass;
68
+ }
69
+
70
+ this.constructors[name] = klass;
71
+ this.fireEvent('class-defined', name, klass);
72
+
73
+ return klass;
74
+ },
75
+
76
+ /**
77
+ * Register works slightly differently for views because we use a namespace too,
78
+ * so convert it here first
79
+ */
80
+ register: function register(namespace, name, config) {
81
+ var viewName = this.buildName(namespace, name);
82
+
83
+ ExtMVC.lib.ViewClassManager.superclass.register.call(this, viewName, config);
84
+ },
85
+
86
+ getConstructor: function getConstructor(namespace, name) {
87
+ var viewName = this.buildName(namespace, name);
88
+
89
+ return ExtMVC.lib.ViewClassManager.superclass.getConstructor.call(this, viewName);
90
+ },
91
+
92
+ /**
93
+ * @private
94
+ * Finds the constructor for a registered xtype.
95
+ * FIXME: This uses a horrible hack and really shouldn't be here at all - the reason being that Ext.ComponentMgr
96
+ * hides its registered types locally,
97
+ * @param {String} xtype The xtype to retrieve a constructor for
98
+ * @return {Function} The constructor for the xtype requested
99
+ */
100
+ getConstructorForXType: function getConstructorForXType(xtype) {
101
+ var constructor = this.xtypeLookup[xtype];
102
+
103
+ if (constructor == undefined) {
104
+ for (var className in this.registeredClasses) {
105
+ var value = this.registeredClasses[className];
106
+
107
+ //extend the parent object and register the constructor
108
+ if (value.registerXType == xtype) {
109
+ constructor = this.getConstructor(className.split('-')[0], className.split('-')[1]);
110
+ }
111
+ }
112
+ }
113
+
114
+ return constructor;
115
+ },
116
+
117
+ /**
118
+ * Because views are named by namespace and name, we need to turn these 2 names into 1
119
+ * to be able to register them, which is what this function does
120
+ * @param {String} namespace The view namespace
121
+ * @param {String} name The view name
122
+ * @return {String} The composited view name (defaults to "{namespace}-{name}")
123
+ */
124
+ buildName: function buildName(namespace, name) {
125
+ return String.format("{0}-{1}", namespace, name);
126
+ },
127
+
128
+ xtypeLookup: {
129
+ box : Ext.BoxComponent,
130
+ button : Ext.Button,
131
+ buttongroup : Ext.ButtonGroup,
132
+ colorpalette : Ext.ColorPalette,
133
+ component : Ext.Component,
134
+ container : Ext.Container,
135
+ cycle : Ext.CycleButton,
136
+ dataview : Ext.DataView,
137
+ datepicker : Ext.DatePicker,
138
+ editor : Ext.Editor,
139
+ editorgrid : Ext.grid.EditorGridPanel,
140
+ flash : Ext.FlashComponent,
141
+ grid : Ext.grid.GridPanel,
142
+ listview : Ext.ListView,
143
+ panel : Ext.Panel,
144
+ progress : Ext.ProgressBar,
145
+ propertygrid : Ext.grid.PropertyGrid,
146
+ slider : Ext.Slider,
147
+ spacer : Ext.Spacer,
148
+ splitbutton : Ext.SplitButton,
149
+ tabpanel : Ext.TabPanel,
150
+ treepanel : Ext.tree.TreePanel,
151
+ viewport : Ext.ViewPort,
152
+ 'window' : Ext.Window,
153
+
154
+ paging : Ext.PagingToolbar,
155
+ toolbar : Ext.Toolbar,
156
+ tbbutton : Ext.Toolbar.Button,
157
+ tbfill : Ext.Toolbar.Fill,
158
+ tbitem : Ext.Toolbar.Item,
159
+ tbseparator : Ext.Toolbar.Separator,
160
+ tbspacer : Ext.Toolbar.Spacer,
161
+ tbsplit : Ext.Toolbar.SplitButton,
162
+ tbtext : Ext.Toolbar.TextItem,
163
+
164
+ menu : Ext.menu.Menu,
165
+ colormenu : Ext.menu.ColorMenu,
166
+ datemenu : Ext.menu.DateMenu,
167
+ menubaseitem : Ext.menu.BaseItem,
168
+ menucheckitem : Ext.menu.CheckItem,
169
+ menuitem : Ext.menu.Item,
170
+ menuseparator : Ext.menu.Separator,
171
+ menutextitem : Ext.menu.TextItem,
172
+
173
+ form : Ext.FormPanel,
174
+ checkbox : Ext.form.Checkbox,
175
+ checkboxgroup : Ext.form.CheckboxGroup,
176
+ combo : Ext.form.ComboBox,
177
+ datefield : Ext.form.DateField,
178
+ displayfield : Ext.form.DisplayField,
179
+ field : Ext.form.Field,
180
+ fieldset : Ext.form.FieldSet,
181
+ hidden : Ext.form.Hidden,
182
+ htmleditor : Ext.form.HtmlEditor,
183
+ label : Ext.form.Label,
184
+ numberfield : Ext.form.NumberField,
185
+ radio : Ext.form.Radio,
186
+ radiogroup : Ext.form.RadioGroup,
187
+ textarea : Ext.form.TextArea,
188
+ textfield : Ext.form.TextField,
189
+ timefield : Ext.form.TimeField,
190
+ trigger : Ext.form.TriggerField,
191
+
192
+ chart : Ext.chart.Chart,
193
+ barchart : Ext.chart.BarChart,
194
+ cartesianchart: Ext.chart.CartesianChart,
195
+ columnchart : Ext.chart.ColumnChart,
196
+ linechart : Ext.chart.LineChart,
197
+ piechart : Ext.chart.PieChart,
198
+
199
+ arraystore : Ext.data.ArrayStore,
200
+ directstore : Ext.data.DirectStore,
201
+ groupingstore : Ext.data.GroupingStore,
202
+ jsonstore : Ext.data.JsonStore,
203
+ simplestore : Ext.data.SimpleStore,
204
+ store : Ext.data.Store,
205
+ xmlstore : Ext.data.XmlStore
206
+ },
207
+
208
+ /**
209
+ * @private
210
+ * Throws a custom Error if the view name has not been registered yet
211
+ * @param {String} name The name of the view that could not be found
212
+ */
213
+ throwViewNotFoundError: function(name) {
214
+ var dir = name.split("-")[0],
215
+ file = name.split("-")[1];
216
+
217
+ var msg = String.format(
218
+ "The {0} view could not be found, please check that your app/views/{1} directory contains a file called {2}, " +
219
+ "that the file contains \"{3}\" and that config/environment.json includes this file",
220
+ name,
221
+ dir,
222
+ file,
223
+ String.format("Ext.registerView('{0}', '{1}')", dir, file)
224
+ );
225
+ throw new Error(msg);
226
+ }
227
+ });
228
+
229
+ ExtMVC.registerClassManager('view', new ExtMVC.lib.ViewClassManager());
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Old versions of String extensions. Not sure if we should be augmenting String like the above so have left this for reference
3
+ */
4
+
5
+ // /**
6
+ // * @param {String} str A string to be capitalized
7
+ // * @returns A capitalized string (e.g. "some test sentence" becomes "Some test sentence")
8
+ // * @type String
9
+ // */
10
+ // String.capitalize = function(str) {
11
+ // return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
12
+ // };
13
+ //
14
+ // /**
15
+ // * @param {String} str A string to be turned into title case
16
+ // * @returns The string in Title Case (e.g. "some test sentence" becomes "Some Test Sentence")
17
+ // * @type String
18
+ // */
19
+ // String.titleize = function(str) {
20
+ // return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
21
+ // };
22
+ //
23
+ // /**
24
+ // * Takes any string and de-underscores and uppercases it
25
+ // * e.g. long_underscored_string => LongUnderscoredString
26
+ // */
27
+ // String.camelize = function(class_name_string) {
28
+ // return String.titleize(class_name_string.replace(/_/g, " ")).replace(/ /g, "");
29
+ //
30
+ // // this feels nicer, sadly no collect function (yet) though
31
+ // // class_name_string.split("_").collect(function(e) {return String.capitalize(e)}).join("");
32
+ // };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Manages registration and retrieval of MVC Model adapters
3
+ * @class ExtMVC.model.AdapterManager
4
+ */
5
+ ExtMVC.model.AdapterManager = {
6
+ /**
7
+ * @property adapters
8
+ * @type Object
9
+ * Key/Value pairs of registered names and the relevant Adapter objects
10
+ */
11
+ adapters: {},
12
+
13
+ /**
14
+ * Registers an adapter for use with MVC Models.
15
+ * @param {String} name String name for this Adapter (e.g. 'REST')
16
+ * @param {Function} object A reference to the Adapter object itself
17
+ */
18
+ register: function(name, constructor) {
19
+ this.adapters[name] = constructor;
20
+ },
21
+
22
+ /**
23
+ * Retrieves the requested adapter by key name
24
+ * @param {String} name The name of the adapter to fine (e.g. 'REST')
25
+ * @return {Object/Null} The Adapter object, if found
26
+ */
27
+ find: function(name, config) {
28
+ return this.adapters[name];
29
+ }
30
+ };