extjs-mvc 0.4.0.j → 0.4.0.k
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/extjs-mvc.rb +0 -14
- data/lib/extjs-mvc/api.rb +14 -27
- data/lib/extjs-mvc/src/App.js +219 -0
- data/lib/extjs-mvc/src/MVC.js +260 -0
- data/lib/extjs-mvc/src/Presenter.js +52 -0
- data/lib/extjs-mvc/src/README.rdoc +69 -0
- data/lib/extjs-mvc/src/controller/Controller.js +278 -0
- data/lib/extjs-mvc/src/controller/CrudController.js +460 -0
- data/lib/extjs-mvc/src/lib/Array.js +26 -0
- data/lib/extjs-mvc/src/lib/Booter.js +417 -0
- data/lib/extjs-mvc/src/lib/ClassManager.js +191 -0
- data/lib/extjs-mvc/src/lib/ControllerClassManager.js +95 -0
- data/lib/extjs-mvc/src/lib/Dependencies.js +44 -0
- data/lib/extjs-mvc/src/lib/DispatchMatcher.js +98 -0
- data/lib/extjs-mvc/src/lib/Dispatcher.js +129 -0
- data/lib/extjs-mvc/src/lib/Environment.js +43 -0
- data/lib/extjs-mvc/src/lib/Inflector.js +155 -0
- data/lib/extjs-mvc/src/lib/ModelClassManager.js +19 -0
- data/lib/extjs-mvc/src/lib/Route.js +139 -0
- data/lib/extjs-mvc/src/lib/Router.js +282 -0
- data/lib/extjs-mvc/src/lib/String.js +94 -0
- data/lib/extjs-mvc/src/lib/ViewClassManager.js +229 -0
- data/lib/extjs-mvc/src/lib/notes.txt +32 -0
- data/lib/extjs-mvc/src/model/AdapterManager.js +30 -0
- data/lib/extjs-mvc/src/model/Association.js +26 -0
- data/lib/extjs-mvc/src/model/Base.js +63 -0
- data/lib/extjs-mvc/src/model/BelongsToAssociation.js +116 -0
- data/lib/extjs-mvc/src/model/Cache.js +131 -0
- data/lib/extjs-mvc/src/model/HasManyAssociation.js +160 -0
- data/lib/extjs-mvc/src/model/Model.js +331 -0
- data/lib/extjs-mvc/src/model/UrlBuilder.js +106 -0
- data/lib/extjs-mvc/src/model/adapters/AbstractAdapter.js +296 -0
- data/lib/extjs-mvc/src/model/adapters/MemoryAdapter.js +103 -0
- data/lib/extjs-mvc/src/model/adapters/RESTAdapter.js +345 -0
- data/lib/extjs-mvc/src/model/adapters/RESTJSONAdapter.js +68 -0
- data/lib/extjs-mvc/src/model/adapters/notes.txt +42 -0
- data/lib/extjs-mvc/src/model/associations/Association.js +192 -0
- data/lib/extjs-mvc/src/model/associations/notes.txt +87 -0
- data/lib/extjs-mvc/src/model/validations/Errors.js +136 -0
- data/lib/extjs-mvc/src/model/validations/Plugin.js +139 -0
- data/lib/extjs-mvc/src/model/validations/Validations.js +276 -0
- data/lib/extjs-mvc/src/notes/Charts.graffle +0 -0
- data/lib/extjs-mvc/src/overrides/Ext.Component.js +21 -0
- data/lib/extjs-mvc/src/overrides/Ext.extend.js +142 -0
- data/lib/extjs-mvc/src/spec/Array.spec.js +15 -0
- data/lib/extjs-mvc/src/spec/ExtMVC.spec.js +65 -0
- data/lib/extjs-mvc/src/spec/Model.spec.js +370 -0
- data/lib/extjs-mvc/src/spec/OS.spec.js +83 -0
- data/lib/extjs-mvc/src/spec/Router.spec.js +99 -0
- data/lib/extjs-mvc/src/spec/SpecHelper.js +106 -0
- data/lib/extjs-mvc/src/spec/String.spec.js +83 -0
- data/lib/extjs-mvc/src/spec/model/AbstractAdapter.spec.js +49 -0
- data/lib/extjs-mvc/src/spec/model/Associations.spec.js +99 -0
- data/lib/extjs-mvc/src/spec/model/Cache.spec.js +5 -0
- data/lib/extjs-mvc/src/spec/model/RESTAdapter.spec.js +19 -0
- data/lib/extjs-mvc/src/spec/model/ValidationErrors.spec.js +64 -0
- data/lib/extjs-mvc/src/spec/model/Validations.spec.js +166 -0
- data/lib/extjs-mvc/src/spec/model/ValidationsPlugin.spec.js +108 -0
- data/lib/extjs-mvc/src/spec/suite.html +60 -0
- data/lib/extjs-mvc/src/specs-old/JSSpec.css +216 -0
- data/lib/extjs-mvc/src/specs-old/JSSpec.js +1512 -0
- data/lib/extjs-mvc/src/specs-old/all.html +66 -0
- data/lib/extjs-mvc/src/specs-old/base.js +14 -0
- data/lib/extjs-mvc/src/specs-old/controller.js +17 -0
- data/lib/extjs-mvc/src/specs-old/diff_match_patch.js +1 -0
- data/lib/extjs-mvc/src/specs-old/model.js +70 -0
- data/lib/extjs-mvc/src/specs-old/route.js +38 -0
- data/lib/extjs-mvc/src/specs-old/router.js +59 -0
- data/lib/extjs-mvc/src/specs-old/string.js +22 -0
- data/lib/extjs-mvc/src/testrunner/JSpecFormatter.js +111 -0
- data/lib/extjs-mvc/src/testrunner/TestClient.js +181 -0
- data/lib/extjs-mvc/src/testrunner/TestGrid.js +351 -0
- data/lib/extjs-mvc/src/testrunner/TestRunner.js +110 -0
- data/lib/extjs-mvc/src/testrunner/TestViewport.js +94 -0
- data/lib/extjs-mvc/src/vendor.yml +30 -0
- data/lib/extjs-mvc/src/vendor/ext-3.1.1/vendor.yml +16 -0
- data/lib/extjs-mvc/src/view/FormWindow.js +184 -0
- data/lib/extjs-mvc/src/view/HasManyEditorGridPanel.js +211 -0
- data/lib/extjs-mvc/src/view/scaffold/Edit.js +46 -0
- data/lib/extjs-mvc/src/view/scaffold/Index.js +561 -0
- data/lib/extjs-mvc/src/view/scaffold/New.js +20 -0
- data/lib/extjs-mvc/src/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/lib/{vendor.yml → extjs-mvc/vendor.yml} +0 -0
- data/test/app/vendor/extjs-mvc/App.js +219 -0
- data/test/app/vendor/extjs-mvc/MVC.js +260 -0
- data/test/app/vendor/extjs-mvc/Presenter.js +52 -0
- data/test/app/vendor/extjs-mvc/README.rdoc +69 -0
- data/test/app/vendor/extjs-mvc/controller/Controller.js +278 -0
- data/test/app/vendor/extjs-mvc/controller/CrudController.js +460 -0
- data/test/app/vendor/extjs-mvc/lib/Array.js +26 -0
- data/test/app/vendor/extjs-mvc/lib/Booter.js +417 -0
- data/test/app/vendor/extjs-mvc/lib/ClassManager.js +191 -0
- data/test/app/vendor/extjs-mvc/lib/ControllerClassManager.js +95 -0
- data/test/app/vendor/extjs-mvc/lib/Dependencies.js +44 -0
- data/test/app/vendor/extjs-mvc/lib/DispatchMatcher.js +98 -0
- data/test/app/vendor/extjs-mvc/lib/Dispatcher.js +129 -0
- data/test/app/vendor/extjs-mvc/lib/Environment.js +43 -0
- data/test/app/vendor/extjs-mvc/lib/Inflector.js +155 -0
- data/test/app/vendor/extjs-mvc/lib/ModelClassManager.js +19 -0
- data/test/app/vendor/extjs-mvc/lib/Route.js +139 -0
- data/test/app/vendor/extjs-mvc/lib/Router.js +282 -0
- data/test/app/vendor/extjs-mvc/lib/String.js +94 -0
- data/test/app/vendor/extjs-mvc/lib/ViewClassManager.js +229 -0
- data/test/app/vendor/extjs-mvc/lib/notes.txt +32 -0
- data/test/app/vendor/extjs-mvc/model/AdapterManager.js +30 -0
- data/test/app/vendor/extjs-mvc/model/Association.js +26 -0
- data/test/app/vendor/extjs-mvc/model/Base.js +63 -0
- data/test/app/vendor/extjs-mvc/model/BelongsToAssociation.js +116 -0
- data/test/app/vendor/extjs-mvc/model/Cache.js +131 -0
- data/test/app/vendor/extjs-mvc/model/HasManyAssociation.js +160 -0
- data/test/app/vendor/extjs-mvc/model/Model.js +331 -0
- data/test/app/vendor/extjs-mvc/model/UrlBuilder.js +106 -0
- data/test/app/vendor/extjs-mvc/model/adapters/AbstractAdapter.js +296 -0
- data/test/app/vendor/extjs-mvc/model/adapters/MemoryAdapter.js +103 -0
- data/test/app/vendor/extjs-mvc/model/adapters/RESTAdapter.js +345 -0
- data/test/app/vendor/extjs-mvc/model/adapters/RESTJSONAdapter.js +68 -0
- data/test/app/vendor/extjs-mvc/model/adapters/notes.txt +42 -0
- data/test/app/vendor/extjs-mvc/model/associations/Association.js +192 -0
- data/test/app/vendor/extjs-mvc/model/associations/notes.txt +87 -0
- data/test/app/vendor/extjs-mvc/model/validations/Errors.js +136 -0
- data/test/app/vendor/extjs-mvc/model/validations/Plugin.js +139 -0
- data/test/app/vendor/extjs-mvc/model/validations/Validations.js +276 -0
- data/test/app/vendor/extjs-mvc/notes/Charts.graffle +0 -0
- data/test/app/vendor/extjs-mvc/overrides/Ext.Component.js +21 -0
- data/test/app/vendor/extjs-mvc/overrides/Ext.extend.js +142 -0
- data/test/app/vendor/extjs-mvc/spec/Array.spec.js +15 -0
- data/test/app/vendor/extjs-mvc/spec/ExtMVC.spec.js +65 -0
- data/test/app/vendor/extjs-mvc/spec/Model.spec.js +370 -0
- data/test/app/vendor/extjs-mvc/spec/OS.spec.js +83 -0
- data/test/app/vendor/extjs-mvc/spec/Router.spec.js +99 -0
- data/test/app/vendor/extjs-mvc/spec/SpecHelper.js +106 -0
- data/test/app/vendor/extjs-mvc/spec/String.spec.js +83 -0
- data/test/app/vendor/extjs-mvc/spec/model/AbstractAdapter.spec.js +49 -0
- data/test/app/vendor/extjs-mvc/spec/model/Associations.spec.js +99 -0
- data/test/app/vendor/extjs-mvc/spec/model/Cache.spec.js +5 -0
- data/test/app/vendor/extjs-mvc/spec/model/RESTAdapter.spec.js +19 -0
- data/test/app/vendor/extjs-mvc/spec/model/ValidationErrors.spec.js +64 -0
- data/test/app/vendor/extjs-mvc/spec/model/Validations.spec.js +166 -0
- data/test/app/vendor/extjs-mvc/spec/model/ValidationsPlugin.spec.js +108 -0
- data/test/app/vendor/extjs-mvc/spec/suite.html +60 -0
- data/test/app/vendor/extjs-mvc/specs-old/JSSpec.css +216 -0
- data/test/app/vendor/extjs-mvc/specs-old/JSSpec.js +1512 -0
- data/test/app/vendor/extjs-mvc/specs-old/all.html +66 -0
- data/test/app/vendor/extjs-mvc/specs-old/base.js +14 -0
- data/test/app/vendor/extjs-mvc/specs-old/controller.js +17 -0
- data/test/app/vendor/extjs-mvc/specs-old/diff_match_patch.js +1 -0
- data/test/app/vendor/extjs-mvc/specs-old/model.js +70 -0
- data/test/app/vendor/extjs-mvc/specs-old/route.js +38 -0
- data/test/app/vendor/extjs-mvc/specs-old/router.js +59 -0
- data/test/app/vendor/extjs-mvc/specs-old/string.js +22 -0
- data/test/app/vendor/extjs-mvc/testrunner/JSpecFormatter.js +111 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestClient.js +181 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestGrid.js +351 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestRunner.js +110 -0
- data/test/app/vendor/extjs-mvc/testrunner/TestViewport.js +94 -0
- data/test/app/vendor/extjs-mvc/vendor.yml +30 -0
- data/test/app/vendor/extjs-mvc/vendor/ext-3.1.1/vendor.yml +16 -0
- data/test/app/vendor/extjs-mvc/view/FormWindow.js +184 -0
- data/test/app/vendor/extjs-mvc/view/HasManyEditorGridPanel.js +211 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/Edit.js +46 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/Index.js +561 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/New.js +20 -0
- data/test/app/vendor/extjs-mvc/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/test/helper.rb +7 -1
- data/test/test_extjs-mvc.rb +46 -0
- metadata +167 -7
- data/test/test_extjs-mvc-gem.rb +0 -7
@@ -0,0 +1,94 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.test.TestViewport
|
3
|
+
* @extends Ext.Viewport
|
4
|
+
* Specialised Viewport which manages the running and reporting of tests
|
5
|
+
*/
|
6
|
+
ExtMVC.test.TestViewport = Ext.extend(Ext.Viewport, {
|
7
|
+
|
8
|
+
constructor: function(config) {
|
9
|
+
config = config || {};
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @property header
|
13
|
+
* @type Ext.Panel
|
14
|
+
* Ext MVC test suite banner Panel
|
15
|
+
*/
|
16
|
+
this.header = new Ext.Panel({
|
17
|
+
html : 'Ext MVC Application Test suite',
|
18
|
+
region: 'north'
|
19
|
+
});
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @property statusText
|
23
|
+
* @type Ext.Toolbar.TextItem
|
24
|
+
* Displays the current status of the test suite in the bottom toolbar
|
25
|
+
*/
|
26
|
+
this.statusText = new Ext.Toolbar.TextItem({
|
27
|
+
text: "Ready"
|
28
|
+
});
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @property rerunButton
|
32
|
+
* @type Ext.Button
|
33
|
+
* Button attached to the toolbar which re-runs the whole suite
|
34
|
+
*/
|
35
|
+
this.rerunButton = new Ext.Button({
|
36
|
+
text : 'Rerun all tests',
|
37
|
+
iconCls : 'all',
|
38
|
+
scope : this,
|
39
|
+
handler : function() {
|
40
|
+
this.client.runner.runTests();
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @property main
|
46
|
+
* @type Ext.Panel
|
47
|
+
* The main Ext.grid.GridPanel that shows results from browsers as they come in
|
48
|
+
*/
|
49
|
+
this.main = new ExtMVC.test.TestGrid({
|
50
|
+
region: 'center',
|
51
|
+
tbar : [this.rerunButton],
|
52
|
+
bbar : [this.statusText]
|
53
|
+
});
|
54
|
+
|
55
|
+
Ext.applyIf(config, {
|
56
|
+
layout: 'border',
|
57
|
+
items: [
|
58
|
+
this.header,
|
59
|
+
this.main
|
60
|
+
]
|
61
|
+
});
|
62
|
+
|
63
|
+
ExtMVC.test.TestViewport.superclass.constructor.call(this, config);
|
64
|
+
|
65
|
+
this.initListeners();
|
66
|
+
},
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Initialises listeners on the Test Client
|
70
|
+
*/
|
71
|
+
initListeners: function() {
|
72
|
+
if (this.client != undefined) {
|
73
|
+
//used in calculating run time
|
74
|
+
var startTime;
|
75
|
+
|
76
|
+
this.client.runner.on({
|
77
|
+
scope: this,
|
78
|
+
starting: function() {
|
79
|
+
startTime = new Date();
|
80
|
+
this.statusText.setText("Running specs");
|
81
|
+
},
|
82
|
+
finished: function(stats) {
|
83
|
+
Ext.apply(stats, {
|
84
|
+
time : new Date() - startTime,
|
85
|
+
failingSpecs: new ExtMVC.test.JSpecFormatter(JSpec, JSpec.options).getFailingSpecs()
|
86
|
+
});
|
87
|
+
|
88
|
+
this.main.store.loadData([stats], true);
|
89
|
+
this.statusText.setText("Ready");
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
}
|
94
|
+
});
|
@@ -0,0 +1,30 @@
|
|
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
|
+
name: extjs-mvc
|
5
|
+
|
6
|
+
version:
|
7
|
+
|
8
|
+
dependencies:
|
9
|
+
- ext-3.1.1
|
10
|
+
|
11
|
+
javascripts:
|
12
|
+
- MVC.js
|
13
|
+
- App.js
|
14
|
+
- lib/ClassManager.js
|
15
|
+
- lib/*.js
|
16
|
+
- overrides/*.js
|
17
|
+
- controller/*.js
|
18
|
+
- model/Model.js
|
19
|
+
- model/Base.js
|
20
|
+
- model/adapters/AbstractAdapter.js
|
21
|
+
- model/adapters/*.js
|
22
|
+
- model/validations/Validations.js
|
23
|
+
- model/validations/*.js
|
24
|
+
- view/*.js
|
25
|
+
- view/scaffold/ScaffoldFormPanel.js
|
26
|
+
- view/scaffold/*.js
|
27
|
+
- testrunner/TestRunner.js
|
28
|
+
- testrunner/*.js
|
29
|
+
stylesheets:
|
30
|
+
- extjs-mvc-all.css
|
@@ -0,0 +1,16 @@
|
|
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
|
+
name: ext
|
5
|
+
|
6
|
+
version: 3.1.1
|
7
|
+
|
8
|
+
dependencies:
|
9
|
+
|
10
|
+
host: http://extjs.cachefly.net
|
11
|
+
|
12
|
+
javascripts:
|
13
|
+
- adapter/ext/ext-base.js
|
14
|
+
- ext-all.js
|
15
|
+
|
16
|
+
stylesheets:
|
@@ -0,0 +1,184 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.view.FormWindow
|
3
|
+
* @extends Ext.Window
|
4
|
+
* Convenience class for creating a window with a default form. Example:
|
5
|
+
*
|
6
|
+
<pre>
|
7
|
+
MyApp.views.MyFormWindow = Ext.extend(ExtMVC.view.FormWindow, {
|
8
|
+
|
9
|
+
height: 200,
|
10
|
+
|
11
|
+
width : 400,
|
12
|
+
|
13
|
+
|
14
|
+
buildForm: function() {
|
15
|
+
//return your Ext.form.FormPanel here
|
16
|
+
}
|
17
|
+
});
|
18
|
+
</pre>
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
ExtMVC.registerView('extmvc', 'formwindow', {
|
22
|
+
xtype : 'window',
|
23
|
+
registerXType: 'formwindow',
|
24
|
+
|
25
|
+
modal : true,
|
26
|
+
height : 230,
|
27
|
+
width : 400,
|
28
|
+
|
29
|
+
initComponent: function() {
|
30
|
+
/**
|
31
|
+
* @property form
|
32
|
+
* @type Ext.form.FormPanel
|
33
|
+
* The new POLN form
|
34
|
+
*/
|
35
|
+
this.form = this.buildForm();
|
36
|
+
|
37
|
+
Ext.apply(this, {
|
38
|
+
items : [
|
39
|
+
this.form
|
40
|
+
],
|
41
|
+
layout: 'fit',
|
42
|
+
closeAction: 'hide',
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @property maskOnSave
|
46
|
+
* @type Boolean
|
47
|
+
* True to add a mask to the field while saving (defaults to true)
|
48
|
+
*/
|
49
|
+
maskOnSave: true,
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @property saveMaskMessage
|
53
|
+
* @type String
|
54
|
+
* The message to show in the saving mask (defaults to "Saving...")
|
55
|
+
*/
|
56
|
+
saveMaskMessage: "Saving...",
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @property hasSaveButton
|
60
|
+
* @type Boolean
|
61
|
+
* True to include a save button (defaults to true)
|
62
|
+
*/
|
63
|
+
hasSaveButton: true,
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @property hasCancelButton
|
67
|
+
* @type Boolean
|
68
|
+
* True to include a cancel button (defaults to true)
|
69
|
+
*/
|
70
|
+
hasCancelButton: true
|
71
|
+
});
|
72
|
+
|
73
|
+
//applyIf applies when buttons: [] is passed, which meant there was no way to
|
74
|
+
//specify any empty set of buttons before
|
75
|
+
if (!Ext.isArray(this.buttons)) {
|
76
|
+
Ext.apply(this, {
|
77
|
+
buttons: this.buildButtons()
|
78
|
+
});
|
79
|
+
};
|
80
|
+
|
81
|
+
Ext.Window.prototype.initComponent.apply(this, arguments);
|
82
|
+
},
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Builds the buttons added to this form. By default this returns an array containing
|
86
|
+
* a Save button and a Cancel button, which fire the 'save' and 'cancel' events respectively
|
87
|
+
* @return {Array} An array of Ext.Button objects or configs
|
88
|
+
*/
|
89
|
+
buildButtons: function() {
|
90
|
+
var buttons = [];
|
91
|
+
|
92
|
+
if (this.hasSaveButton === true) buttons.push(this.buildSaveButton());
|
93
|
+
if (this.hasCancelButton === true) buttons.push(this.buildCancelButton());
|
94
|
+
|
95
|
+
return buttons;
|
96
|
+
},
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Builds the Save button config. Override this to provide your own
|
100
|
+
* @return {Object/Ext.Button} The button config or object
|
101
|
+
*/
|
102
|
+
buildSaveButton: function() {
|
103
|
+
return {
|
104
|
+
text : 'Save',
|
105
|
+
iconCls: 'save',
|
106
|
+
scope : this,
|
107
|
+
handler: this.onSave
|
108
|
+
};
|
109
|
+
},
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Builds the Cancel button config. Override this to provide your own
|
113
|
+
* @return {Object/Ext.Button} The button config or object
|
114
|
+
*/
|
115
|
+
buildCancelButton: function() {
|
116
|
+
return {
|
117
|
+
text: 'Cancel',
|
118
|
+
scope: this,
|
119
|
+
iconCls: 'cancel',
|
120
|
+
handler: this.onCancel
|
121
|
+
};
|
122
|
+
},
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Creates and returns a FormPanel instance to go inside the window. Override this yourself
|
126
|
+
* @return {Ext.form.FormPanel} The form panel
|
127
|
+
*/
|
128
|
+
buildForm: function() {
|
129
|
+
return new Ext.form.FormPanel({});
|
130
|
+
},
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Loads an instance into the form
|
134
|
+
* @param {GetIt.models.PurchaseOrderLineNote} instance The POLN instance to load
|
135
|
+
*/
|
136
|
+
loadRecord: function(instance) {
|
137
|
+
/**
|
138
|
+
* @property instance
|
139
|
+
* @type ExtMVC.model.Base
|
140
|
+
* The instance currently loaded into the form
|
141
|
+
*/
|
142
|
+
this.instance = instance;
|
143
|
+
|
144
|
+
this.form.form.loadRecord(instance);
|
145
|
+
},
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Called when the user clicks the save button
|
149
|
+
*/
|
150
|
+
onSave: function() {
|
151
|
+
if (this.maskOnSave === true) this.el.mask(this.saveMaskMessage);
|
152
|
+
|
153
|
+
if (this.instance == undefined || this.instance.newRecord()) {
|
154
|
+
this.fireEvent('save', this.getFormValues(), this);
|
155
|
+
} else {
|
156
|
+
this.fireEvent('save', this.instance, this.getFormValues(), this);
|
157
|
+
}
|
158
|
+
},
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Called when the usre clicks the cancel button. By default this just hides the window
|
162
|
+
*/
|
163
|
+
onCancel: function() {
|
164
|
+
this.close();
|
165
|
+
},
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Gets form values in a nicer way than getForm.getValues() does - calls getValue on each field.
|
169
|
+
* See http://www.diloc.de/blog/2008/03/05/how-to-submit-ext-forms-the-right-way/
|
170
|
+
* @return {Object} key: value pairings of form values
|
171
|
+
*/
|
172
|
+
getFormValues: function() {
|
173
|
+
var form = this.form.getForm(),
|
174
|
+
values = {};
|
175
|
+
|
176
|
+
form.items.each(function(item) {
|
177
|
+
var func = (typeof item.getSubmitValue == "function") ? 'getSubmitValue' : 'getValue';
|
178
|
+
|
179
|
+
values[item.getName()] = item[func]();
|
180
|
+
}, this);
|
181
|
+
|
182
|
+
return values;
|
183
|
+
}
|
184
|
+
});
|
@@ -0,0 +1,211 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.view.HasManyEditorGridPanel
|
3
|
+
* @extends Ext.grid.EditorGridPanel
|
4
|
+
* Provides some sensible defaults for a HasMany editor grid. For example, given the following models:
|
5
|
+
* ExtMVC.model.define("MyApp.models.User", {
|
6
|
+
* ...
|
7
|
+
* hasMany: "Post"
|
8
|
+
* });
|
9
|
+
*
|
10
|
+
* ExtMVC.model.define("MyApp.models.Post", {
|
11
|
+
* ...
|
12
|
+
* belongsTo: "User"
|
13
|
+
* });
|
14
|
+
*
|
15
|
+
* Inside the edit User view, if we wanted to be able to quickly edit any of that User's Posts, we can insert
|
16
|
+
* a HasManyEditorGridPanel like this:
|
17
|
+
*
|
18
|
+
* items: [
|
19
|
+
* {
|
20
|
+
* xtype: 'hasmany_editorgrid',
|
21
|
+
* modelObj: userObj,
|
22
|
+
* association: userObj.posts,
|
23
|
+
* columns: [... set up editor columns as per a normal EditorGridPanel]
|
24
|
+
* }
|
25
|
+
* ]
|
26
|
+
*
|
27
|
+
* In the example above, userObj refers to the loaded User instance tied to the edit form. The HasMany editor grid
|
28
|
+
* automatically listens to afteredit events and saves the HasMany model (Post in this case).
|
29
|
+
*/
|
30
|
+
ExtMVC.view.HasManyEditorGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
|
31
|
+
|
32
|
+
initComponent: function() {
|
33
|
+
Ext.applyIf(this, {
|
34
|
+
autoScroll: true,
|
35
|
+
store: this.association.findAll(),
|
36
|
+
viewConfig: { forceFit: true }
|
37
|
+
});
|
38
|
+
|
39
|
+
if (this.hasTopToolbar) { this.addTopToolbar(); }
|
40
|
+
|
41
|
+
ExtMVC.view.HasManyEditorGridPanel.superclass.initComponent.apply(this, arguments);
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Set up listening on the afteredit event. Simply saves the model instance
|
45
|
+
*/
|
46
|
+
this.on('afteredit', function(args) {
|
47
|
+
args.record.save({
|
48
|
+
success: function() {
|
49
|
+
args.record.commit();
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}, this);
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Set up listening to selection change to activate the Remove button
|
56
|
+
*/
|
57
|
+
this.getSelectionModel().on('selectionchange', function(selModel, selection) {
|
58
|
+
if (this.deleteButton) {
|
59
|
+
this.deleteButton.enable();
|
60
|
+
};
|
61
|
+
}, this);
|
62
|
+
},
|
63
|
+
|
64
|
+
/**
|
65
|
+
* @property hasTopToolbar
|
66
|
+
* @type Boolean
|
67
|
+
* True to automatically show a toolbar at the top of the grid with Add and Delete buttons (defaults to true)
|
68
|
+
*/
|
69
|
+
hasTopToolbar: true,
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @property hasNewButton
|
73
|
+
* @type Boolean
|
74
|
+
* True to add a 'New' button to the top toolbar if the top toolbar is present (defaults to true)
|
75
|
+
*/
|
76
|
+
hasNewButton: true,
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @property hasDeleteButton
|
80
|
+
* @type Boolean
|
81
|
+
* True to add a 'Delete' button to the top toolbar if the top toolbar is present (defaults to true)
|
82
|
+
*/
|
83
|
+
hasDeleteButton: true,
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Private.
|
87
|
+
* Creates a top toolbar and applies it to 'this'. Should only be called from inside initComponent
|
88
|
+
*/
|
89
|
+
addTopToolbar: function(paramName) {
|
90
|
+
var items = [];
|
91
|
+
|
92
|
+
if (this.hasNewButton) {
|
93
|
+
this.newButton = new Ext.Toolbar.Button({
|
94
|
+
iconCls: 'add',
|
95
|
+
text: 'Add',
|
96
|
+
scope: this,
|
97
|
+
handler: this.onAdd
|
98
|
+
});
|
99
|
+
|
100
|
+
items.push(this.newButton);
|
101
|
+
items.push('-');
|
102
|
+
};
|
103
|
+
|
104
|
+
if (this.hasDeleteButton) {
|
105
|
+
this.deleteButton = new Ext.Toolbar.Button({
|
106
|
+
text: 'Remove selected',
|
107
|
+
disabled: true,
|
108
|
+
iconCls: 'delete',
|
109
|
+
scope: this,
|
110
|
+
handler: this.onDelete
|
111
|
+
});
|
112
|
+
|
113
|
+
items.push(this.deleteButton);
|
114
|
+
};
|
115
|
+
|
116
|
+
Ext.applyIf(this, {
|
117
|
+
tbar: items
|
118
|
+
});
|
119
|
+
},
|
120
|
+
|
121
|
+
/**
|
122
|
+
* @property windowConfig
|
123
|
+
* @type Object
|
124
|
+
* Config object passed when creating the New Association window. Override this to customise
|
125
|
+
* the window that appears
|
126
|
+
*/
|
127
|
+
windowConfig: {},
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Called when the Add button is clicked on the top toolbar
|
131
|
+
*/
|
132
|
+
onAdd: function(btn) {
|
133
|
+
if (!this.addWindow) {
|
134
|
+
this.addWindow = new Ext.Window(
|
135
|
+
Ext.applyIf(this.windowConfig, {
|
136
|
+
title: 'New',
|
137
|
+
layout: 'fit',
|
138
|
+
modal: true,
|
139
|
+
height: 300,
|
140
|
+
width: 400,
|
141
|
+
items: [this.form],
|
142
|
+
closeAction: 'hide',
|
143
|
+
buttons: [
|
144
|
+
{
|
145
|
+
text: 'Save',
|
146
|
+
iconCls: 'save',
|
147
|
+
scope: this,
|
148
|
+
handler: this.onSaveNew
|
149
|
+
},
|
150
|
+
{
|
151
|
+
text: 'Cancel',
|
152
|
+
iconCls: 'cancel',
|
153
|
+
scope: this,
|
154
|
+
handler: this.onCancelNew
|
155
|
+
}
|
156
|
+
]
|
157
|
+
})
|
158
|
+
);
|
159
|
+
}
|
160
|
+
|
161
|
+
this.addWindow.show();
|
162
|
+
},
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Called when a row is selected and the delete button is clicked
|
166
|
+
*/
|
167
|
+
onDelete: function(btn) {
|
168
|
+
var record = this.getSelectionModel().selection.record;
|
169
|
+
|
170
|
+
if (record) {
|
171
|
+
record.destroy({
|
172
|
+
scope: this,
|
173
|
+
success: function() {
|
174
|
+
this.store.reload();
|
175
|
+
},
|
176
|
+
failure: function() {
|
177
|
+
Ext.Msg.alert('Delete failed', "Something went wrong while trying to delete - please try again");
|
178
|
+
this.store.reload();
|
179
|
+
}
|
180
|
+
});
|
181
|
+
};
|
182
|
+
|
183
|
+
this.deleteButton.disable();
|
184
|
+
},
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Called when the user clicks the save button to create a new record
|
188
|
+
*/
|
189
|
+
onSaveNew: function() {
|
190
|
+
this.association.create(this.form.getForm().getValues(), {
|
191
|
+
scope: this,
|
192
|
+
success: function(modelObj, response) {
|
193
|
+
this.store.reload();
|
194
|
+
this.addWindow.hide();
|
195
|
+
},
|
196
|
+
failure: function(modelObj, response) {
|
197
|
+
this.form.getForm().clearInvalid();
|
198
|
+
this.form.getForm().markInvalid(modelObj.errors.forForm());
|
199
|
+
}
|
200
|
+
});
|
201
|
+
},
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Called when the user cancels adding a new association model
|
205
|
+
*/
|
206
|
+
onCancelNew: function(paramName) {
|
207
|
+
this.addWindow.hide();
|
208
|
+
}
|
209
|
+
});
|
210
|
+
|
211
|
+
Ext.reg('hasmany_editorgrid', ExtMVC.view.HasManyEditorGridPanel);
|