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.
- data/LICENSE +1 -1
- data/README.rdoc +5 -173
- data/Rakefile +18 -20
- data/VERSION +1 -1
- data/bin/xmvc +13 -0
- data/lib/extjs-mvc/README +20 -0
- data/lib/extjs-mvc/builder.rb +83 -0
- data/lib/extjs-mvc/builders/all_builder.rb +15 -0
- data/lib/extjs-mvc/builders/app_builder.rb +36 -0
- data/lib/extjs-mvc/builders/base.rb +138 -0
- data/lib/extjs-mvc/builders/css_builder.rb +36 -0
- data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
- data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
- data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
- data/lib/extjs-mvc/cli.rb +52 -0
- data/lib/extjs-mvc/generator.rb +79 -0
- data/lib/extjs-mvc/generators/app.rb +57 -0
- data/lib/extjs-mvc/generators/base.rb +53 -0
- data/lib/extjs-mvc/generators/controller.rb +41 -0
- data/lib/extjs-mvc/generators/model.rb +41 -0
- data/lib/extjs-mvc/generators/scaffold.rb +17 -0
- data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
- data/lib/extjs-mvc/generators/templates/Model.js +9 -0
- data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
- data/lib/extjs-mvc/generators/templates/View.js +16 -0
- data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
- data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
- data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
- data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
- data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
- data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
- data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
- data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
- data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
- data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
- data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
- data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
- data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
- data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
- data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
- data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
- data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
- data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
- data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
- data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
- data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
- data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
- data/lib/extjs-mvc/generators/view.rb +29 -0
- data/lib/extjs-mvc/plugin.rb +105 -0
- data/lib/extjs-mvc/scripts.rb +15 -0
- data/lib/extjs-mvc/settings.rb +75 -0
- data/lib/extjs-mvc/setup.rb +5 -0
- data/lib/extjs-mvc/stats.rb +241 -0
- data/lib/extjs-mvc/test.rb +11 -0
- data/lib/extjs-mvc/testserver.ru +95 -0
- data/lib/extjs-mvc/ui.rb +58 -0
- data/lib/extjs-mvc/update.rb +73 -0
- data/lib/extjs-mvc.rb +70 -32
- data/lib/js/App.js +219 -0
- data/lib/js/MVC.js +260 -0
- data/lib/js/Presenter.js +52 -0
- data/lib/js/README.rdoc +69 -0
- data/lib/js/build +21 -0
- data/lib/js/controller/Controller.js +278 -0
- data/lib/js/controller/CrudController.js +460 -0
- data/lib/js/lib/Array.js +26 -0
- data/lib/js/lib/Booter.js +415 -0
- data/lib/js/lib/ClassManager.js +191 -0
- data/lib/js/lib/ControllerClassManager.js +95 -0
- data/lib/js/lib/Dependencies.js +44 -0
- data/lib/js/lib/DispatchMatcher.js +98 -0
- data/lib/js/lib/Dispatcher.js +129 -0
- data/lib/js/lib/Environment.js +43 -0
- data/lib/js/lib/Inflector.js +138 -0
- data/lib/js/lib/ModelClassManager.js +19 -0
- data/lib/js/lib/Route.js +139 -0
- data/lib/js/lib/Router.js +282 -0
- data/lib/js/lib/String.js +94 -0
- data/lib/js/lib/ViewClassManager.js +229 -0
- data/lib/js/lib/notes.txt +32 -0
- data/lib/js/model/AdapterManager.js +30 -0
- data/lib/js/model/Association.js +26 -0
- data/lib/js/model/Base.js +63 -0
- data/lib/js/model/BelongsToAssociation.js +116 -0
- data/lib/js/model/Cache.js +131 -0
- data/lib/js/model/HasManyAssociation.js +160 -0
- data/lib/js/model/Model.js +331 -0
- data/lib/js/model/UrlBuilder.js +106 -0
- data/lib/js/model/adapters/AbstractAdapter.js +296 -0
- data/lib/js/model/adapters/MemoryAdapter.js +103 -0
- data/lib/js/model/adapters/RESTAdapter.js +345 -0
- data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
- data/lib/js/model/adapters/notes.txt +42 -0
- data/lib/js/model/associations/Association.js +192 -0
- data/lib/js/model/associations/notes.txt +87 -0
- data/lib/js/model/validations/Errors.js +136 -0
- data/lib/js/model/validations/Plugin.js +139 -0
- data/lib/js/model/validations/Validations.js +276 -0
- data/lib/js/notes/Charts.graffle +0 -0
- data/lib/js/overrides/Ext.Component.js +21 -0
- data/lib/js/overrides/Ext.extend.js +142 -0
- data/lib/js/spec/Array.spec.js +15 -0
- data/lib/js/spec/ExtMVC.spec.js +65 -0
- data/lib/js/spec/Model.spec.js +370 -0
- data/lib/js/spec/OS.spec.js +83 -0
- data/lib/js/spec/Router.spec.js +99 -0
- data/lib/js/spec/SpecHelper.js +106 -0
- data/lib/js/spec/String.spec.js +83 -0
- data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
- data/lib/js/spec/model/Associations.spec.js +99 -0
- data/lib/js/spec/model/Cache.spec.js +5 -0
- data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
- data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
- data/lib/js/spec/model/Validations.spec.js +166 -0
- data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
- data/lib/js/spec/suite.html +60 -0
- data/lib/js/specs-old/JSSpec.css +216 -0
- data/lib/js/specs-old/JSSpec.js +1512 -0
- data/lib/js/specs-old/all.html +66 -0
- data/lib/js/specs-old/base.js +14 -0
- data/lib/js/specs-old/controller.js +17 -0
- data/lib/js/specs-old/diff_match_patch.js +1 -0
- data/lib/js/specs-old/model.js +70 -0
- data/lib/js/specs-old/route.js +38 -0
- data/lib/js/specs-old/router.js +59 -0
- data/lib/js/specs-old/string.js +22 -0
- data/lib/js/testrunner/JSpecFormatter.js +111 -0
- data/lib/js/testrunner/TestClient.js +181 -0
- data/lib/js/testrunner/TestGrid.js +351 -0
- data/lib/js/testrunner/TestRunner.js +110 -0
- data/lib/js/testrunner/TestViewport.js +94 -0
- data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
- data/lib/js/vendor/screw-unit/LICENSE +22 -0
- data/lib/js/vendor/screw-unit/README.markdown +307 -0
- data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
- data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
- data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
- data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
- data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
- data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
- data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
- data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
- data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
- data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
- data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
- data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
- data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
- data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
- data/lib/js/view/FormWindow.js +184 -0
- data/lib/js/view/HasManyEditorGridPanel.js +211 -0
- data/lib/js/view/scaffold/Edit.js +46 -0
- data/lib/js/view/scaffold/Index.js +561 -0
- data/lib/js/view/scaffold/New.js +20 -0
- data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/test/helper.rb +10 -0
- data/test/test_extjs-mvc-gem.rb +7 -0
- metadata +232 -56
- data/README +0 -12
- data/lib/controller/controller.rb +0 -28
- data/lib/core_ext/array/extract_options.rb +0 -15
- data/lib/extjs/component.rb +0 -71
- data/lib/extjs/data/store.rb +0 -131
- data/lib/helpers/component.rb +0 -37
- data/lib/helpers/store.rb +0 -7
- data/lib/model/active_record.rb +0 -89
- data/lib/model/base.rb +0 -370
- data/lib/model/data_mapper.rb +0 -66
- data/lib/model/mongo_mapper.rb +0 -64
- data/lib/test/macros.rb +0 -20
- data/test/app/config/application.rb +0 -70
- data/test/app/config/database.yml +0 -3
- data/test/app/db/schema.rb +0 -75
- data/test/app/models/active_record/address.rb +0 -4
- data/test/app/models/active_record/data_type.rb +0 -3
- data/test/app/models/active_record/group.rb +0 -4
- data/test/app/models/active_record/house.rb +0 -4
- data/test/app/models/active_record/location.rb +0 -5
- data/test/app/models/active_record/person.rb +0 -4
- data/test/app/models/active_record/user.rb +0 -6
- data/test/app/models/active_record/user_group.rb +0 -4
- data/test/component_test.rb +0 -15
- data/test/debug.log +0 -2969
- data/test/model_test.rb +0 -526
- data/test/mongo_mapper_test.rb +0 -0
- data/test/store_test.rb +0 -0
- data/test/test_helper.rb +0 -32
data/lib/js/README.rdoc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
= Ext MVC
|
2
|
+
|
3
|
+
EXT MVC is a complete MVC stack on top of Ext JS (http://extjs.com).
|
4
|
+
|
5
|
+
== Base App
|
6
|
+
|
7
|
+
You are advised to use the base app to get up and running with Ext MVC as it sets everything up for you.
|
8
|
+
|
9
|
+
If you're comfortable with git:
|
10
|
+
|
11
|
+
1. git clone git://github.com/extmvc/baseapp.git myapp
|
12
|
+
2. cd myapp
|
13
|
+
3. rm -rf .git/
|
14
|
+
4. git init
|
15
|
+
|
16
|
+
If not:
|
17
|
+
|
18
|
+
1. Download the latest zip file from Github at http://github.com/extmvc/baseapp/zipball/master and unzip.
|
19
|
+
|
20
|
+
== Getting started
|
21
|
+
|
22
|
+
Read the readme file inside the base app and refer to http://extmvc.com
|
23
|
+
|
24
|
+
== Building
|
25
|
+
|
26
|
+
Ext MVC comes with a set of build tools for itself and your applications, written in Ruby. You need to be using
|
27
|
+
the Baseapp or a structure similar to it for these to work effectively.
|
28
|
+
|
29
|
+
=== Building your Ext MVC application
|
30
|
+
|
31
|
+
Build any app started from the base app by running this from the app's root directory:
|
32
|
+
|
33
|
+
ruby script/build all
|
34
|
+
|
35
|
+
This will examine the contents of index.html, pull out all of the javascript includes and concatenate them into
|
36
|
+
public/application-all.js. If you have the yui-compressor in your vendor directory (this is included by default)
|
37
|
+
and you have java installed, the build process will also minify your application-all.js into application-all-min.js.
|
38
|
+
|
39
|
+
Building your app also concatenates any CSS includes in index.html into public/application-all.css.
|
40
|
+
|
41
|
+
*NOTE*: Building looks at your index.html, NOT public/index.html. index.html is your development version,
|
42
|
+
public/index.html should simply include those concatenated/minified files.
|
43
|
+
|
44
|
+
=== Autobuild
|
45
|
+
|
46
|
+
If you need your app to be built every time you change any of the source files for whatever reason, use:
|
47
|
+
|
48
|
+
ruby script/build auto
|
49
|
+
|
50
|
+
This will again look at index.html and will force a rebuild any time any of those files are changed.
|
51
|
+
|
52
|
+
=== Other app build options
|
53
|
+
|
54
|
+
There are several other build commands, most of which are used by the two above:
|
55
|
+
|
56
|
+
- ruby script/build css - only build CSS files, no JS concatenation or minification
|
57
|
+
- ruby script/build js - only builds JS files, not CSS
|
58
|
+
- ruby script/build concatenate_js - concatenates but does not attempt to minify your JS
|
59
|
+
- ruby script/build minify_js - minifies an already concatenated public/application-all.js file
|
60
|
+
|
61
|
+
=== Building Ext MVC
|
62
|
+
|
63
|
+
If you are changing Ext MVC files and need to build Ext MVC itself, use:
|
64
|
+
|
65
|
+
- ruby script/build mvc
|
66
|
+
- ruby script/build mvc_auto
|
67
|
+
|
68
|
+
Again run from the app root directory. Like with ruby script/build auto, mvc_auto automatically rebuilds whenever
|
69
|
+
any Ext MVC file is changed.
|
data/lib/js/build
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Defines the build order of Ext MVC. Comments indicated with a hash.
|
2
|
+
# Each line denotes either a single file, or a directory glob. If a glob, all matching files are included
|
3
|
+
# (unless they have already been defined)
|
4
|
+
|
5
|
+
- MVC.js
|
6
|
+
- App.js
|
7
|
+
- lib/ClassManager.js
|
8
|
+
- lib/*.js
|
9
|
+
- overrides/*.js
|
10
|
+
- controller/*.js
|
11
|
+
- model/Model.js
|
12
|
+
- model/Base.js
|
13
|
+
- model/adapters/AbstractAdapter.js
|
14
|
+
- model/adapters/*.js
|
15
|
+
- model/validations/Validations.js
|
16
|
+
- model/validations/*.js
|
17
|
+
- view/*.js
|
18
|
+
- view/scaffold/ScaffoldFormPanel.js
|
19
|
+
- view/scaffold/*.js
|
20
|
+
- testrunner/TestRunner.js
|
21
|
+
- testrunner/*.js
|
@@ -0,0 +1,278 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.controller.Controller
|
3
|
+
* @extends Ext.util.Observable
|
4
|
+
* <h1>Controllers in Ext MVC</h1>
|
5
|
+
* <p>Controllers are the glue that stick applications together. They listen to events emitted by the UI as the user
|
6
|
+
* clicks interface elements, and take actions as appropriate. The relevant action may be to create or save a model
|
7
|
+
* instance, to render another view, to perform AJAX requests, or any other action.</p>
|
8
|
+
*
|
9
|
+
* <p>Controllers should be kept skinny as far as possible - receive an event, then hand any processing off to the
|
10
|
+
* appropriate model. This ensures we can keep the code as DRY as possible and makes refactoring easier.</p>
|
11
|
+
*
|
12
|
+
* <h2>Example Controller</h2>
|
13
|
+
* Here is a simple example controller which renders a couple of views and listens to events:
|
14
|
+
<pre><code>
|
15
|
+
//simple controller which manages the Page model within our application
|
16
|
+
MyApp.controllers.PagesController = Ext.extend(ExtMVC.controller.Controller, {
|
17
|
+
name: 'pages',
|
18
|
+
|
19
|
+
//renders the 'Index' template and sets up listeners
|
20
|
+
index: function() {
|
21
|
+
this.render('Index', {
|
22
|
+
listeners: {
|
23
|
+
scope : this,
|
24
|
+
'edit' : this.edit,
|
25
|
+
'delete': this.destroy
|
26
|
+
}
|
27
|
+
});
|
28
|
+
},
|
29
|
+
|
30
|
+
//renders the 'Edit' template (let's say it's a FormPanel), and loads the instance
|
31
|
+
edit: function(instance) {
|
32
|
+
this.render('Edit', {
|
33
|
+
listeners: {
|
34
|
+
scope : this,
|
35
|
+
save : this.update,
|
36
|
+
cancel : function() {
|
37
|
+
alert("You cancelled the update!");
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}).loadRecord(instance);
|
41
|
+
},
|
42
|
+
|
43
|
+
//when the 'delete' event is fired by our 'Index' template (see the index action), this method is called.
|
44
|
+
//In this fictional example, we assume that the templates 'delete' event was called with the single argument
|
45
|
+
//of the Page instance the user wishes to destroy
|
46
|
+
destroy: function(instance) {
|
47
|
+
instance.destroy({
|
48
|
+
success: function() {
|
49
|
+
alert("The Page was deleted");
|
50
|
+
//at this point we might render another page for the user to look at
|
51
|
+
},
|
52
|
+
failure: function() {
|
53
|
+
alert('Curses! The Page could not be deleted');
|
54
|
+
}
|
55
|
+
});
|
56
|
+
},
|
57
|
+
|
58
|
+
//when the 'save' event is fired by our 'Edit' template, this method is called.
|
59
|
+
//Again, we assume that our template fired the event with the Page instance, and also an object with updates
|
60
|
+
update: function(instance, updates) {
|
61
|
+
//this applies the updates to the model instance and saves
|
62
|
+
instance.update(updates, {
|
63
|
+
success: function(updatedInstance) {
|
64
|
+
alert('Success! It saved');
|
65
|
+
//at this point we might render another page for the user to look at
|
66
|
+
},
|
67
|
+
failure: function(updatedInstance) {
|
68
|
+
alert('Darn it. Did not save');
|
69
|
+
|
70
|
+
//here we're firing the controller's update-failed event, which the view can pick up on
|
71
|
+
//The view can simply listen to our Pages controller and add errors from this instance to the form
|
72
|
+
//using form.markInvalid(instance.errors.forForm())
|
73
|
+
this.fireEvent('update-failed', instance);
|
74
|
+
};
|
75
|
+
});
|
76
|
+
},
|
77
|
+
|
78
|
+
//Sets up events emitted by this controller. Controllers are expected to fire events, so this method is called
|
79
|
+
//automatically when a controller is instantiated. Don't forget to call super here
|
80
|
+
initEvents: function() {
|
81
|
+
this.addEvents(
|
82
|
+
//this event will be fired when the controller can't update a Page instance
|
83
|
+
'update-failed'
|
84
|
+
);
|
85
|
+
|
86
|
+
MyApp.controllers.PagesController.superclass.initEvents.apply(this, arguments);
|
87
|
+
}
|
88
|
+
})
|
89
|
+
</code></pre>
|
90
|
+
* Note that many of the methods above are provided by the {@link ExtMVC.controller.CrudController CrudController}
|
91
|
+
*
|
92
|
+
* <h2>Rendering Views</h2>
|
93
|
+
* Each controller can automatically render view classes inside its views package. In the Pages controller above the
|
94
|
+
* views package is MyApp.views.pages - the application itself is called MyApp, and the 'pages' segment comes from the
|
95
|
+
* controller's 'name' property
|
96
|
+
* <br />
|
97
|
+
* <br />
|
98
|
+
* In the example above, the line: <pre><code>this.render('Edit', {})</code></pre> will automatically find the
|
99
|
+
* MyApp.views.pages.Edit class, with the second argument to this.render being a config argument passed to the view's constructor.
|
100
|
+
*
|
101
|
+
* <br />
|
102
|
+
* <h4>Rendering strategies</h4>
|
103
|
+
* Not all applications will render views in the same way
|
104
|
+
*/
|
105
|
+
// ExtMVC.controller.Controller = Ext.extend(Ext.util.Observable,
|
106
|
+
ExtMVC.registerController('controller', {
|
107
|
+
|
108
|
+
constructor: function(config) {
|
109
|
+
Ext.util.Observable.prototype.constructor.apply(this, arguments);
|
110
|
+
|
111
|
+
Ext.apply(this, {
|
112
|
+
/**
|
113
|
+
* @property renderStrategies
|
114
|
+
* @type Object
|
115
|
+
* An object of the form {xtype: function} which keys a container's xtype to the function to use
|
116
|
+
* when rendering a view to that container (see registerRenderStrategy)
|
117
|
+
*/
|
118
|
+
renderStrategies: {}
|
119
|
+
}, config || {});
|
120
|
+
|
121
|
+
this.registerDefaultRenderStrategies();
|
122
|
+
|
123
|
+
this.initEvents();
|
124
|
+
this.initListeners();
|
125
|
+
},
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Registers a rendering function for a given container xtype. When a view is rendered via this.render,
|
129
|
+
* the xtype of the container it is being rendered to is compared to the registered strategy xtypes, and
|
130
|
+
* the most specific match will be used to perform the rendering.
|
131
|
+
* @param {String} xtype The container xtype to register
|
132
|
+
* @param {Function} strategy The function to call when rendering to a container of the given xtype
|
133
|
+
*/
|
134
|
+
registerRenderStrategy: function(xtype, strategy) {
|
135
|
+
this.renderStrategies[xtype] = strategy;
|
136
|
+
},
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Returns the strategy function to use when rendering to the given container instance.
|
140
|
+
* @param {Ext.Container} container The container to add to
|
141
|
+
* @return {Function} The rendering strategy to use
|
142
|
+
*/
|
143
|
+
getRenderStrategy: function(container) {
|
144
|
+
var xtypes = container.getXTypes().split("/");
|
145
|
+
|
146
|
+
for (var i = xtypes.length - 1; i >= 0; i--){
|
147
|
+
var strategy = this.renderStrategies[xtypes[i]];
|
148
|
+
|
149
|
+
if (strategy != undefined) return strategy;
|
150
|
+
};
|
151
|
+
|
152
|
+
throw new Ext.Error("No render strategy could be found for the container you specified");
|
153
|
+
},
|
154
|
+
|
155
|
+
/**
|
156
|
+
* @private
|
157
|
+
* Adds the default strategies for panel and tabpanel
|
158
|
+
*/
|
159
|
+
registerDefaultRenderStrategies: function() {
|
160
|
+
this.registerRenderStrategy('panel', this.panelRenderStrategy);
|
161
|
+
this.registerRenderStrategy('tabpanel', this.tabPanelRenderStrategy);
|
162
|
+
},
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Sets up events emitted by this controller. This defaults to an empty function and is
|
166
|
+
* called automatically when the controller is constructed so can simply be overridden
|
167
|
+
*/
|
168
|
+
initEvents: function() {},
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Sets up events this controller listens to, and the actions the controller should take
|
172
|
+
* when each event is received. This defaults to an empty function and is called when
|
173
|
+
* the controller is constructed so can simply be overridden
|
174
|
+
*/
|
175
|
+
initListeners: function() {},
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Shows the user a notification message. Usually used to inform user of a successful save, deletion, etc
|
179
|
+
* This is an empty function which you must implement yourself
|
180
|
+
* @param {String} notice The string notice to display
|
181
|
+
*/
|
182
|
+
showNotice: function(notice) {},
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @property addTo
|
186
|
+
* @type Ext.Container
|
187
|
+
* The container to add views to using the 'add' renderMethod. Usually set to an Ext.TabPanel instance or similar
|
188
|
+
*/
|
189
|
+
addTo: null,
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Renders a given view name in the way set up by the controller. For this to work you must have passed a
|
193
|
+
* 'name' property when creating the controller, which is automatically used to find the view namespace for
|
194
|
+
* this controller. For example, in an application called MyApp, and a controller with a name of 'users',
|
195
|
+
* the view namespace would be MyApp.views.users, and render('Index') would search for a class called
|
196
|
+
* MyApp.views.users.Index and instantiate it with the passed config.
|
197
|
+
* An error is thrown if the view could not be found.
|
198
|
+
* @param {String} viewName The name of the view class within the view namespace used by this controller
|
199
|
+
* @param {Object} config Configuration options passed through to the view class' constructor
|
200
|
+
* @return {Ext.Component} The view object that was just created
|
201
|
+
*/
|
202
|
+
render: function render() {
|
203
|
+
//handle both method signatures
|
204
|
+
switch(arguments.length) {
|
205
|
+
case 1:
|
206
|
+
//this just falls through into case 2, which provides a config {} if one is not supplied
|
207
|
+
case 2:
|
208
|
+
var namespace = this.name,
|
209
|
+
viewName = arguments[0],
|
210
|
+
config = arguments[1] || {};
|
211
|
+
break;
|
212
|
+
case 3:
|
213
|
+
var namespace = arguments[0],
|
214
|
+
viewName = arguments[1],
|
215
|
+
config = arguments[2] || {};
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
|
219
|
+
//we also use this constructor object to define whether or not the view should be added to the default
|
220
|
+
//container or not
|
221
|
+
Ext.applyIf(config, {
|
222
|
+
autoAdd: true,
|
223
|
+
addTo : ExtMVC.app.main
|
224
|
+
});
|
225
|
+
|
226
|
+
//NOTE: ExtMVC.getView will throw an error if the view hasn't been defined anywhere yet. At the moment this
|
227
|
+
//error will just propagate up as it's probably pretty clear, but we could provide a custom Error message here instead
|
228
|
+
var view = new (this.getView(namespace, viewName))(config);
|
229
|
+
|
230
|
+
if (config.autoAdd === true) {
|
231
|
+
if (view.isXType('window')) {
|
232
|
+
view.show();
|
233
|
+
} else {
|
234
|
+
this.getRenderStrategy(config.addTo)(config.addTo, view);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
return view;
|
239
|
+
},
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Just calls ExtMVC.getView and returns. This is here because we override it in Crud Controller
|
243
|
+
* @param {String} namespace The view namespace
|
244
|
+
* @param {String} name The view name
|
245
|
+
* @return {Function} The view constructor function
|
246
|
+
*/
|
247
|
+
getView: function(namespace, name) {
|
248
|
+
return ExtMVC.getView(namespace, name);
|
249
|
+
},
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @private
|
253
|
+
* The tabpanel render strategy
|
254
|
+
*/
|
255
|
+
tabPanelRenderStrategy: function(container, view) {
|
256
|
+
var existing = container.getItem(view.id);
|
257
|
+
|
258
|
+
//don't add a tab with the same id as an existing one
|
259
|
+
if (existing == undefined) {
|
260
|
+
container.add(view);
|
261
|
+
container.doLayout();
|
262
|
+
container.activate(view);
|
263
|
+
} else {
|
264
|
+
container.setActiveTab(view.id);
|
265
|
+
view.destroy();
|
266
|
+
}
|
267
|
+
},
|
268
|
+
|
269
|
+
/**
|
270
|
+
* @private
|
271
|
+
* The panel render strategy
|
272
|
+
*/
|
273
|
+
panelRenderStrategy: function(container, view) {
|
274
|
+
container.removeAll();
|
275
|
+
container.add(view);
|
276
|
+
container.doLayout();
|
277
|
+
}
|
278
|
+
});
|