extjs-mvc 0.4.0.j → 0.4.0.k

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ begin
14
14
  gem.add_dependency "extjs", ">= 0.1.1"
15
15
  gem.add_dependency "git"
16
16
  gem.add_dependency "thor", ">= 0.13.4"
17
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+ gem.add_development_dependency "shoulda", ">= 0"
18
18
  gem.files = FileList["[A-Z]*", "{bin,lib,test,config}/**/*"]
19
19
 
20
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0.j
1
+ 0.4.0.k
@@ -3,7 +3,6 @@ require 'thor'
3
3
  require 'xmvc'
4
4
  require 'xmvc/cli'
5
5
  require 'extjs'
6
- require 'extjs-mvc/api'
7
6
 
8
7
  ##
9
8
  # This is the extjs-mvc Thor task which install the extjs-mvc-js javascript source via Github
@@ -12,21 +11,8 @@ module ExtJS
12
11
  module MVC
13
12
 
14
13
  VERSION = "0.4.0.a"
15
-
16
- ROOT = File.dirname(__FILE__)
17
-
18
- VENDOR_NAME = 'extjs-mvc'
19
-
20
- CONFIG_PATH = File.join(ROOT, "vendor.yml")
21
-
22
- GIT_URL = 'http://github.com/christocracy/extjs-mvc-src.git'
23
14
 
24
15
  autoload :API, 'extjs-mvc/api'
25
16
 
26
- class << self
27
- def config
28
- @config ||= YAML.load(File.read(CONFIG_PATH)).to_mash
29
- end
30
- end
31
17
  end
32
18
  end
@@ -1,32 +1,15 @@
1
1
  module ExtJS
2
2
  module MVC
3
3
 
4
- VENDOR_NAME = "extjs-mvc"
4
+ GIT_URL = 'http://github.com/christocracy/extjs-mvc-src.git'
5
5
 
6
- class API < Thor
6
+ class API < Xmvc::Vendor
7
7
  include Thor::Actions
8
8
 
9
- desc "secretary", "Returns vendor assets; css, js, images, sass, haml, html...whatever. Returns a Sprockets::Secretary"
10
- def secretary
11
- say_status "ExtJS::MVC", "secretary"
12
- Sprockets::Secretary.new({
13
- :source_files => config["javascripts"],
14
- :root => root
15
- })
16
- end
9
+ vendor_name "extjs-mvc"
17
10
 
18
- desc "config", "Returns config from vendor.yml"
19
- def config
20
- config = {}
21
- root = File.expand_path(File.join(options[:root], ExtJS::MVC::VENDOR_NAME))
22
- path = File.join(root, "vendor.yml")
23
- if File.exists?(path)
24
- config = YAML.load_file(path)
25
- else
26
- #raise Xmvc::VendorFileNotFound.new("Failed to load vendor file 'vendor/extjs-mvc/vendor.yml'")
27
- puts "failed to load ExtJS::MVC config #{path}"
28
- end
29
- config
11
+ def self.source_root
12
+ File.dirname(__FILE__)
30
13
  end
31
14
 
32
15
  ##
@@ -35,17 +18,21 @@ module ExtJS
35
18
  #
36
19
  desc "install", "Install extjs-mvc framework"
37
20
  def install
38
- fancy_name = File.join(File.basename(options[:root]), VENDOR_NAME)
21
+ fancy_name = File.join(File.basename(options[:root]), self.class.vendor_name)
39
22
  say_status "git clone", "#{GIT_URL} -> #{fancy_name}"
40
-
23
+
24
+ ##
25
+ # static extjs-mvc-src
26
+ #
27
+ #directory("src", ".")
28
+
41
29
  # Clone the extjs-mvc-js repo!
42
- path = File.join(options[:root], VENDOR_NAME)
43
30
  ##
44
31
  # UNCOMMENT THIS TO INSTALL FROM GIT
45
32
  #
46
- Git.clone(GIT_URL, path)
33
+ Git.clone(GIT_URL, ".")
47
34
  # report to console which files were created.
48
- Dir["#{path}/**/*.*"].each do |f|
35
+ Dir["./**/*.*"].each do |f|
49
36
  say_status :create, File.join(fancy_name, File.basename(f))
50
37
  end
51
38
  end
@@ -0,0 +1,219 @@
1
+ /**
2
+ * @class ExtMVC.App
3
+ * @extends Ext.util.Observable
4
+ * @cfg {Boolean} usesHistory True to automatically create required DOM elements for Ext.History,
5
+ * sets up a listener on Ext.History's change event to fire this.onHistoryChange. False by default
6
+ */
7
+ ExtMVC.App = Ext.extend(Ext.util.Observable, {
8
+ /**
9
+ * @constructor
10
+ * Sets up the Application - adds events, sets up namespaces, optionally sets up history.
11
+ * Fires the 'before-launch' event before initializing router, viewport and history.
12
+ * Calls this.launch() once everything else is set up (override the 'launch' method to provide your own logic).
13
+ * Fires the 'launched' event after calling this.launch()
14
+ */
15
+ constructor: function(config) {
16
+ ExtMVC.App.superclass.constructor.apply(this, arguments);
17
+
18
+ //apply configuration object and set up namespaces
19
+ Ext.apply(this, config || {});
20
+ window[this.name] = this;
21
+
22
+ this.initializeNamespaces();
23
+
24
+ // Ext.onReady(this.onReady, this);
25
+
26
+ this.on('launched', function() {
27
+ /**
28
+ * TODO: This used to reside in initializeHistory but this.launch() needs to be
29
+ * called before this dispatches so it is temporarily here... ugly though
30
+ */
31
+ if (this.usesHistory) {
32
+ if (this.dispatchHistoryOnLoad === true) {
33
+ Ext.History.init(function(history) {
34
+ var hash = document.location.hash.replace("#", "");
35
+ var params = this.router.recognise(hash);
36
+
37
+ if (params) {this.dispatch(params);}
38
+ }, this);
39
+ } else {
40
+ Ext.History.init();
41
+ }
42
+ }
43
+ }, this);
44
+ },
45
+
46
+ /**
47
+ * @private
48
+ * Called when Ext.onReady fires
49
+ */
50
+ onReady: function() {
51
+ if (this.fireEvent('before-launch', this)) {
52
+ this.initializeRouter();
53
+ // this.initializeViewport();
54
+ this.initializeEvents();
55
+
56
+ if (this.usesHistory === true) this.initializeHistory();
57
+
58
+ this.launch();
59
+ }
60
+ },
61
+
62
+ /**
63
+ * @property name
64
+ * @type String
65
+ * The application's name. This is used when creating namespaces for models, views and controllers,
66
+ * and automatically set up as a global variable reference to this application. Read only.
67
+ */
68
+ name: 'MyApp',
69
+
70
+ /**
71
+ * @property usesHistory
72
+ * @type Boolean
73
+ * True to automatically create required DOM elements for Ext.History,
74
+ * sets up a listener on Ext.History's change event to fire this.onHistoryChange.
75
+ * False by default
76
+ */
77
+ usesHistory: false,
78
+
79
+ /**
80
+ * @prop dispatchHistoryOnLoad
81
+ * @type Boolean
82
+ * If usesHistory is true and dispatchHistoryOnLoad is also true, the OS will attempt to match
83
+ * any string currently after the # in the url and dispatch to it
84
+ */
85
+ dispatchHistoryOnLoad: true,
86
+
87
+ /**
88
+ * Called when the application is booted up. Override this to provide your own startup logic (defaults to Ext.emptyFn)
89
+ */
90
+ launch: function() {
91
+ this.fireEvent('launched', this);
92
+ },
93
+
94
+ /**
95
+ * @property params
96
+ * @type Object
97
+ * An object containing the most current parameters (usually decoded from a url using this.router)
98
+ * e.g. {controller: 'index', action: 'welcome', id: 10}
99
+ */
100
+ params: {},
101
+
102
+ /**
103
+ * Dispatches a request to a registered controller.
104
+ * @param {Object} dispatchConfig A config object which should look something like this:
105
+ * {controller: 'MyController', action: 'index'}, where 'MyController' is the key for a controller
106
+ * which has been registered to the controller. If action is not specified, it defaults to 'index'
107
+ * @param {Object} scope The scope in which to fire the event (defaults to the controller)
108
+ * @param {Array} args An array of arguments which are passed to the controller action.
109
+ */
110
+ dispatch: function dispatch(dispatchConfig, scope, args) {
111
+ var dispatchConfig = dispatchConfig || {};
112
+ Ext.applyIf(dispatchConfig, {
113
+ action: 'index'
114
+ });
115
+
116
+ this.params = dispatchConfig;
117
+
118
+ var c = ExtMVC.getController(dispatchConfig.controller);
119
+ if (c != undefined) {
120
+ var action = c[dispatchConfig.action];
121
+
122
+ if (typeof action == "function") action.apply(scope || c, args || []);
123
+ else throw new Error(String.format("Action '{0}' not found on Controller '{1}'", dispatchConfig.action, dispatchConfig.controller));
124
+ }
125
+ },
126
+
127
+ /**
128
+ * Sets up a Router instance. This is called automatically before onLaunch()
129
+ * Add routes using this.router.connect
130
+ */
131
+ initializeRouter: function() {
132
+ if (this.router == undefined) {
133
+ this.router = new ExtMVC.router.Router();
134
+ ExtMVC.router.Router.defineRoutes(this.router);
135
+ }
136
+ },
137
+
138
+ /**
139
+ * Uses Ext.namespace to create packages view controllers, models and views
140
+ * E.g. if name = 'Blog' or this.name = 'Blog', this is the same as:
141
+ * Ext.ns('Blog', 'Blog.controllers', 'Blog.models', 'Blog.views')
142
+ */
143
+ initializeNamespaces: function initializeNamespaces(name) {
144
+ var name = name || this.name;
145
+ if (name) {
146
+ Ext.ns(name, name + '.controllers', name + '.models', name + '.views');
147
+ };
148
+ },
149
+
150
+ /**
151
+ * Creates the necessary DOM elements required for Ext.History to manage state
152
+ * Sets up listeners on Ext.History's change event to fire the dispatch() action in the normal way.
153
+ * This is not called automatically as not all applications will need it
154
+ */
155
+ initializeHistory: function initializeHistory() {
156
+ this.historyForm = Ext.getBody().createChild({
157
+ tag: 'form',
158
+ action: '#',
159
+ cls: 'x-hidden',
160
+ id: 'history-form',
161
+ children: [
162
+ {
163
+ tag: 'div',
164
+ children: [
165
+ {
166
+ tag: 'input',
167
+ id: 'x-history-field',
168
+ type: 'hidden'
169
+ },
170
+ {
171
+ tag: 'iframe',
172
+ id: 'x-history-frame'
173
+ }
174
+ ]
175
+ }
176
+ ]
177
+ });
178
+
179
+ Ext.History.on('change', this.onHistoryChange, this);
180
+ },
181
+
182
+ /**
183
+ * Takes a history token (anything after the # in the url), consults the router and dispatches
184
+ * to the appropriate controller and action if a match was found
185
+ * @param {String} token The url token (e.g. the token would be cont/act/id for a url like mydomain.com/#cont/act/id)
186
+ */
187
+ onHistoryChange: function onHistoryChange(token) {
188
+ var match = this.router.recognise(token);
189
+
190
+ if (match) {
191
+ this.dispatch(match, null, [{url: token}]);
192
+ };
193
+ },
194
+
195
+ /**
196
+ * Sets up events emitted by the Application
197
+ */
198
+ initializeEvents: function initializeEvents() {
199
+ this.addEvents(
200
+ /**
201
+ * @event before-launch
202
+ * Fires before this application launches
203
+ * @param {ExtMVC.App} this The application about to be launched
204
+ */
205
+ 'before-launch',
206
+
207
+ /**
208
+ * @event launched
209
+ * Fires once the application has been launched
210
+ * @param {ExtMVC.App} this The application which has been launched
211
+ */
212
+ 'launched'
213
+ );
214
+ }
215
+ });
216
+
217
+ ExtMVC.App.define = function(config) {
218
+ ExtMVC.app = new ExtMVC.App(config);
219
+ };
@@ -0,0 +1,260 @@
1
+ /**
2
+ * @class ExtMVC
3
+ * ExtMVC
4
+ * @singleton
5
+ */
6
+ ExtMVC = Ext.extend(Ext.util.Observable, {
7
+ version: "0.7a",
8
+
9
+ constructor: function() {
10
+ ExtMVC.superclass.constructor.apply(this, arguments);
11
+
12
+ /**
13
+ * @property dispatcher
14
+ * @type Ext.lib.Dispatcher
15
+ * The dispatcher object which finds the right controller and action when ExtMVC.dispatch is called
16
+ */
17
+ // this.dispatcher = new Ext.lib.Dispatcher({
18
+ //
19
+ // });
20
+ },
21
+
22
+ dispatch: function() {
23
+ var dispatcher = this.dispatcher;
24
+
25
+ return dispatcher.dispatch.apply(dispatcher, arguments);
26
+ },
27
+
28
+ /**
29
+ * Sets the Ext.Application instance currently in use. This is currently required :/
30
+ * @param {Ext.Application} app The application currently in use
31
+ */
32
+ setApplication: function(app) {
33
+ this.app = app;
34
+ this.name = app.name;
35
+
36
+ ExtMVC.model.modelNamespace = window[app.name].models;
37
+ },
38
+
39
+ fields: {
40
+
41
+ },
42
+
43
+ registerFields: function(name, fields) {
44
+ this.fields[name] = fields;
45
+ },
46
+
47
+ getFields: function(name) {
48
+ return this.fields[name];
49
+ },
50
+
51
+
52
+
53
+ /**
54
+ * Registers a model class with Ext MVC
55
+ * @param {String} name The name to give this model
56
+ * @param {Object} config Model definition configuration
57
+ */
58
+ registerModel: function(name, config) {
59
+ this.registerClass('model', arguments);
60
+ },
61
+
62
+ /**
63
+ * Registers a controller class with Ext MVC
64
+ * @param {String} name The name to give this controller
65
+ * @param {Object} config Controller definition configuration
66
+ */
67
+ registerController: function(name, config) {
68
+ this.registerClass('controller', arguments);
69
+ },
70
+
71
+ /**
72
+ * Registers a view class with Ext MVC.
73
+ * @param {String} namesapce The namespace to add this view to
74
+ * @param {String} name The name to give this view
75
+ * @param {Object} config View definition configuration
76
+ */
77
+ registerView: function(namespace, name, config) {
78
+ this.registerClass('view', arguments);
79
+ },
80
+
81
+ /**
82
+ * Abstraction for registering views, models and controllers
83
+ * @param {String} managerName The name of the class manager to register with
84
+ * @param {Array} args The args to pass to the manager's register method
85
+ */
86
+ registerClass: function(managerName, args) {
87
+ var manager = this.getClassManager(managerName);
88
+
89
+ manager.register.apply(manager, args);
90
+ },
91
+
92
+ /**
93
+ * @property classManagers
94
+ * @type Object
95
+ * {name: classManager} mappings used by this.getClassManager and this.registerClassManager
96
+ */
97
+ classManagers: {},
98
+
99
+ /**
100
+ * @private
101
+ * Sets up model, view and controller class managers
102
+ */
103
+ initializeClassManagers: function() {
104
+ this.registerClassManager('model', new ExtMVC.lib.ModelClassManager());
105
+ this.registerClassManager('view', new ExtMVC.lib.ViewClassManager());
106
+ this.registerClassManager('controller', new ExtMVC.lib.ControllerClassManager());
107
+ },
108
+
109
+ /**
110
+ * Returns the class manager for the given name
111
+ * @param {String} name The name of the manager (model, view or controller)
112
+ * @return {ExtMVC.lib.ClassManager} The class manager instance
113
+ */
114
+ getClassManager: function(name) {
115
+ return this.classManagers[name];
116
+ },
117
+
118
+ /**
119
+ * Registers a class manager instance under a given name
120
+ * @param {String} name The name of the class manager
121
+ * @param {ExtMVC.lib.ClassManager} manager The ClassManager instance to register
122
+ */
123
+ registerClassManager: function(name, manager) {
124
+ this.classManagers[name] = manager;
125
+ },
126
+
127
+ /**
128
+ * Returns the canonical controller instance for the given controller name
129
+ * @return {ExtMVC.Controller} The controller instance
130
+ */
131
+ getController: function(name) {
132
+ return this.getClassManager('controller').getInstance(name);
133
+ },
134
+
135
+ /**
136
+ * Returns the constructor for a given model name
137
+ * @param {String} name The name of the model
138
+ * @return {Function} The model constructor
139
+ */
140
+ getModel: function(name) {
141
+ return this.getClassManager('model').getConstructor(name);
142
+ },
143
+
144
+ /**
145
+ * Instantiates a model of the given name with the data supplied
146
+ * @param {String} modelName The name of the model to instantiate
147
+ * @param {Object} data Data object to instantiate the instance with
148
+ * @return {ExtMVC.Model} The new model instance
149
+ */
150
+ buildModel: function(modelName, data) {
151
+ return new (this.getModel(modelName))(data);
152
+ },
153
+
154
+ /**
155
+ * Returns the constructor for a given view namespace/name combination
156
+ * @param {String} namespace The view namespace to look in
157
+ * @param {String} name The name of the view within the view namespace
158
+ * @return {Function} The view constructor
159
+ */
160
+ getView: function getView(namespace, name) {
161
+ return this.getClassManager('view').getConstructor(namespace, name);
162
+ },
163
+
164
+ /**
165
+ * Returns a new view instance for the given namespace/name combo, using the supplied config
166
+ * @param {String} namespace The namespace to find the view from
167
+ * @param {String} name The view name
168
+ * @param {Object} config Optional config object
169
+ * @return {Ext.Component} The new view instance
170
+ */
171
+ buildView: function buildView(namespace, name, config) {
172
+ var constructor = this.getView(namespace, name);
173
+
174
+ return new (constructor)(config);
175
+ },
176
+
177
+ /**
178
+ * Loads packaged classes from a given url, calling a callback when they have been registered. Sample return:
179
+ <pre>
180
+ {
181
+ controllers: [
182
+ {
183
+ name: 'comments',
184
+ superclass: 'crud',
185
+ config: {
186
+ index: function() {
187
+ this.render('index', {
188
+ title: "Loaded on demand!"
189
+ });
190
+ }
191
+ }
192
+ }
193
+ ],
194
+ views: [
195
+ {
196
+ name: 'new',
197
+ namespace: 'comments',
198
+ config: {
199
+ xtype: 'scaffoldnew',
200
+ title: "New Comment"
201
+ }
202
+ }
203
+ ],
204
+ models: [
205
+ {
206
+ name : 'Comment',
207
+ config: {
208
+ fields: [
209
+ {name: 'id', type: 'int'},
210
+ {name: 'title', type: 'string'},
211
+ {name: 'message', type: 'string'}
212
+ ]
213
+ }
214
+ }
215
+ ]
216
+ }
217
+ </pre>
218
+ * @param {String} url The url to retrieve the package from
219
+ * @param {Function} callback Optional callback function, called after the package has been read and registered
220
+ * @param {Object} scope The scope to execute the callback function in
221
+ */
222
+ loadOnDemand: function(url, callback, scope) {
223
+ Ext.Ajax.request({
224
+ url : url,
225
+ scope : scope || this,
226
+ success: function(response) {
227
+ var pkg = Ext.decode(response.responseText);
228
+
229
+ Ext.each(pkg.controllers || [], function(config) {
230
+ this.registerController(config.name, config);
231
+ }, this);
232
+
233
+ Ext.each(pkg.models || [], function(config) {
234
+ this.registerModel(config.name, config);
235
+ }, this);
236
+
237
+ Ext.each(pkg.views || [], function(config) {
238
+ this.registerView(config.namespace, config.name, config);
239
+ }, this);
240
+
241
+ if (Ext.isFunction(callback)) callback.call(scope, pkg);
242
+ }
243
+ });
244
+ }
245
+ });
246
+
247
+ ExtMVC = new ExtMVC();
248
+
249
+ // ExtMVC.initializeClassManagers();
250
+
251
+ Ext.onReady(function() {
252
+ /**
253
+ * @property dispatcher
254
+ * @type Ext.lib.Dispatcher
255
+ * The dispatcher object which finds the right controller and action when ExtMVC.dispatch is called
256
+ */
257
+ ExtMVC.dispatcher = new ExtMVC.lib.Dispatcher();
258
+ });
259
+
260
+ Ext.ns('ExtMVC.router', 'ExtMVC.plugin', 'ExtMVC.controller', 'ExtMVC.view', 'ExtMVC.view.scaffold', 'ExtMVC.lib', 'ExtMVC.test');