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
@@ -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);
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.view.scaffold.Edit
|
3
|
+
* @extends ExtMVC.view.scaffold.ScaffoldFormPanel
|
4
|
+
* Shows a generic edit form for a given model
|
5
|
+
*/
|
6
|
+
ExtMVC.registerView('scaffold', 'edit', {
|
7
|
+
xtype : 'scaffold_form',
|
8
|
+
registerXType: 'scaffold_edit',
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Sets the panel's title, if not already set
|
12
|
+
*/
|
13
|
+
initComponent: function() {
|
14
|
+
Ext.applyIf(this, {
|
15
|
+
title: 'Edit ' + this.model.prototype.singularHumanName
|
16
|
+
});
|
17
|
+
|
18
|
+
ExtMVC.getView('scaffold', 'form').prototype.initComponent.apply(this, arguments);
|
19
|
+
},
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Loads the given record into the form and maintains a reference to it so that it can be returned
|
23
|
+
* when the 'save' event is fired
|
24
|
+
* @param {ExtMVC.Model.Base} instance The model instance to load into this form
|
25
|
+
*/
|
26
|
+
loadRecord: function(instance) {
|
27
|
+
this.instance = instance;
|
28
|
+
this.getForm().loadRecord(instance);
|
29
|
+
},
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Called when the save button is clicked or CTRL + s pressed. By default this simply fires
|
33
|
+
* the 'save' event, passing this.getForm().getValues() as the sole argument
|
34
|
+
*/
|
35
|
+
onSave: function() {
|
36
|
+
this.fireEvent('save', this.instance, this.getFormValues(), this);
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @event save
|
41
|
+
* Fired when the user clicks the save button, or presses ctrl + s
|
42
|
+
* @param {ExtMVC.model.Base} instance The existing instance that is to be updated
|
43
|
+
* @param {Object} values The values entered into the form
|
44
|
+
* @param {ExtMVC.view.scaffold.ScaffoldFormPanel} this The form panel
|
45
|
+
*/
|
46
|
+
});
|