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,229 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.lib.ViewClassManager
|
3
|
+
* @extends ExtMVC.lib.ClassManager
|
4
|
+
* Customised class manager for views. Views differ from most other classes as they are namespaced
|
5
|
+
* by view package, so they take namespace and name when registering.
|
6
|
+
* VCM will attempt to recursively define view classes that extend others, so if a view's xtype hasn't
|
7
|
+
* been registered with Ext.ComponentMgr yet, VCM will attempt to find that xtype by seeing if any of
|
8
|
+
* the other registered views have declared that xtype via the 'registerXType' property. If one is found,
|
9
|
+
* VCM will either return its constructor if it is already defined, otherwise it will try to define it first,
|
10
|
+
* again recursing up the inheritance stack if necessary. Example:
|
11
|
+
<pre>
|
12
|
+
vcm.register('somePackage', 'someView', {
|
13
|
+
xtype: 'anotherview' //this doesn't exist yet
|
14
|
+
});
|
15
|
+
|
16
|
+
//anotherview extends the 'myxtype' type, which hasn't been defined yet
|
17
|
+
vcm.register('somePackage', 'someOtherView', {
|
18
|
+
xtype: 'myxtype',
|
19
|
+
registerXType: 'anotherview'
|
20
|
+
});
|
21
|
+
|
22
|
+
//myview extends panel, and is registered with the 'myxtype' xtype
|
23
|
+
vcm.register('somepackage', 'myview', {
|
24
|
+
xtype: 'panel',
|
25
|
+
registerXType: 'myxtype'
|
26
|
+
});
|
27
|
+
|
28
|
+
When vcm.getConstructor('somepackage', 'someview') is called, it looks to see if 'anotherview' has
|
29
|
+
been registered with Ext.ComponentMgr first. If it has, it just calls Ext.extend with the config included
|
30
|
+
when registering 'someview', extending the constructor of 'anotherview', and returns the result.
|
31
|
+
|
32
|
+
If 'anotherview' hasn't yet been registered with Ext.ComponentMgr, it is automatically defined first with
|
33
|
+
this.define. In this case, the parent class of 'anotherview' ('myxtype') hasn't been defined yet either,
|
34
|
+
so again the inheritance chain is automatically traversed, 'myview' is defined and registered to 'myxtype',
|
35
|
+
and the resulting extended class constructor returned so that 'anotherview' can in turn be extended.
|
36
|
+
</pre>
|
37
|
+
*/
|
38
|
+
ExtMVC.lib.ViewClassManager = Ext.extend(ExtMVC.lib.ClassManager, {
|
39
|
+
autoDefine: false,
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Uses Ext.extend to define a previously registered view class config into a full class.
|
43
|
+
* The new class constructor is then cached in this.constructors, keyed by name.
|
44
|
+
* @param {String} name The name of the view to turn from config object to class constructor
|
45
|
+
*/
|
46
|
+
define: function define(name) {
|
47
|
+
var overrides = this.getRegistered(name);
|
48
|
+
if (overrides == undefined) this.throwViewNotFoundError(name);
|
49
|
+
|
50
|
+
var xtype = overrides.xtype || 'panel';
|
51
|
+
|
52
|
+
delete overrides.xtype;
|
53
|
+
|
54
|
+
//extend the class, register it if required
|
55
|
+
var constructor = this.getConstructorForXType(xtype);
|
56
|
+
var klass = Ext.extend(constructor, overrides);
|
57
|
+
|
58
|
+
if (klass == undefined) {
|
59
|
+
throw new Error(
|
60
|
+
String.format("The {0} view could not be created because the xtype you supplied ('{1}') could not be found", name, overrides.xtype)
|
61
|
+
);
|
62
|
+
}
|
63
|
+
|
64
|
+
var newXType = overrides.registerXType;
|
65
|
+
if (newXType) {
|
66
|
+
Ext.reg(newXType, klass);
|
67
|
+
this.xtypeLookup[newXType] = klass;
|
68
|
+
}
|
69
|
+
|
70
|
+
this.constructors[name] = klass;
|
71
|
+
this.fireEvent('class-defined', name, klass);
|
72
|
+
|
73
|
+
return klass;
|
74
|
+
},
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Register works slightly differently for views because we use a namespace too,
|
78
|
+
* so convert it here first
|
79
|
+
*/
|
80
|
+
register: function register(namespace, name, config) {
|
81
|
+
var viewName = this.buildName(namespace, name);
|
82
|
+
|
83
|
+
ExtMVC.lib.ViewClassManager.superclass.register.call(this, viewName, config);
|
84
|
+
},
|
85
|
+
|
86
|
+
getConstructor: function getConstructor(namespace, name) {
|
87
|
+
var viewName = this.buildName(namespace, name);
|
88
|
+
|
89
|
+
return ExtMVC.lib.ViewClassManager.superclass.getConstructor.call(this, viewName);
|
90
|
+
},
|
91
|
+
|
92
|
+
/**
|
93
|
+
* @private
|
94
|
+
* Finds the constructor for a registered xtype.
|
95
|
+
* FIXME: This uses a horrible hack and really shouldn't be here at all - the reason being that Ext.ComponentMgr
|
96
|
+
* hides its registered types locally,
|
97
|
+
* @param {String} xtype The xtype to retrieve a constructor for
|
98
|
+
* @return {Function} The constructor for the xtype requested
|
99
|
+
*/
|
100
|
+
getConstructorForXType: function getConstructorForXType(xtype) {
|
101
|
+
var constructor = this.xtypeLookup[xtype];
|
102
|
+
|
103
|
+
if (constructor == undefined) {
|
104
|
+
for (var className in this.registeredClasses) {
|
105
|
+
var value = this.registeredClasses[className];
|
106
|
+
|
107
|
+
//extend the parent object and register the constructor
|
108
|
+
if (value.registerXType == xtype) {
|
109
|
+
constructor = this.getConstructor(className.split('-')[0], className.split('-')[1]);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return constructor;
|
115
|
+
},
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Because views are named by namespace and name, we need to turn these 2 names into 1
|
119
|
+
* to be able to register them, which is what this function does
|
120
|
+
* @param {String} namespace The view namespace
|
121
|
+
* @param {String} name The view name
|
122
|
+
* @return {String} The composited view name (defaults to "{namespace}-{name}")
|
123
|
+
*/
|
124
|
+
buildName: function buildName(namespace, name) {
|
125
|
+
return String.format("{0}-{1}", namespace, name);
|
126
|
+
},
|
127
|
+
|
128
|
+
xtypeLookup: {
|
129
|
+
box : Ext.BoxComponent,
|
130
|
+
button : Ext.Button,
|
131
|
+
buttongroup : Ext.ButtonGroup,
|
132
|
+
colorpalette : Ext.ColorPalette,
|
133
|
+
component : Ext.Component,
|
134
|
+
container : Ext.Container,
|
135
|
+
cycle : Ext.CycleButton,
|
136
|
+
dataview : Ext.DataView,
|
137
|
+
datepicker : Ext.DatePicker,
|
138
|
+
editor : Ext.Editor,
|
139
|
+
editorgrid : Ext.grid.EditorGridPanel,
|
140
|
+
flash : Ext.FlashComponent,
|
141
|
+
grid : Ext.grid.GridPanel,
|
142
|
+
listview : Ext.ListView,
|
143
|
+
panel : Ext.Panel,
|
144
|
+
progress : Ext.ProgressBar,
|
145
|
+
propertygrid : Ext.grid.PropertyGrid,
|
146
|
+
slider : Ext.Slider,
|
147
|
+
spacer : Ext.Spacer,
|
148
|
+
splitbutton : Ext.SplitButton,
|
149
|
+
tabpanel : Ext.TabPanel,
|
150
|
+
treepanel : Ext.tree.TreePanel,
|
151
|
+
viewport : Ext.ViewPort,
|
152
|
+
'window' : Ext.Window,
|
153
|
+
|
154
|
+
paging : Ext.PagingToolbar,
|
155
|
+
toolbar : Ext.Toolbar,
|
156
|
+
tbbutton : Ext.Toolbar.Button,
|
157
|
+
tbfill : Ext.Toolbar.Fill,
|
158
|
+
tbitem : Ext.Toolbar.Item,
|
159
|
+
tbseparator : Ext.Toolbar.Separator,
|
160
|
+
tbspacer : Ext.Toolbar.Spacer,
|
161
|
+
tbsplit : Ext.Toolbar.SplitButton,
|
162
|
+
tbtext : Ext.Toolbar.TextItem,
|
163
|
+
|
164
|
+
menu : Ext.menu.Menu,
|
165
|
+
colormenu : Ext.menu.ColorMenu,
|
166
|
+
datemenu : Ext.menu.DateMenu,
|
167
|
+
menubaseitem : Ext.menu.BaseItem,
|
168
|
+
menucheckitem : Ext.menu.CheckItem,
|
169
|
+
menuitem : Ext.menu.Item,
|
170
|
+
menuseparator : Ext.menu.Separator,
|
171
|
+
menutextitem : Ext.menu.TextItem,
|
172
|
+
|
173
|
+
form : Ext.FormPanel,
|
174
|
+
checkbox : Ext.form.Checkbox,
|
175
|
+
checkboxgroup : Ext.form.CheckboxGroup,
|
176
|
+
combo : Ext.form.ComboBox,
|
177
|
+
datefield : Ext.form.DateField,
|
178
|
+
displayfield : Ext.form.DisplayField,
|
179
|
+
field : Ext.form.Field,
|
180
|
+
fieldset : Ext.form.FieldSet,
|
181
|
+
hidden : Ext.form.Hidden,
|
182
|
+
htmleditor : Ext.form.HtmlEditor,
|
183
|
+
label : Ext.form.Label,
|
184
|
+
numberfield : Ext.form.NumberField,
|
185
|
+
radio : Ext.form.Radio,
|
186
|
+
radiogroup : Ext.form.RadioGroup,
|
187
|
+
textarea : Ext.form.TextArea,
|
188
|
+
textfield : Ext.form.TextField,
|
189
|
+
timefield : Ext.form.TimeField,
|
190
|
+
trigger : Ext.form.TriggerField,
|
191
|
+
|
192
|
+
chart : Ext.chart.Chart,
|
193
|
+
barchart : Ext.chart.BarChart,
|
194
|
+
cartesianchart: Ext.chart.CartesianChart,
|
195
|
+
columnchart : Ext.chart.ColumnChart,
|
196
|
+
linechart : Ext.chart.LineChart,
|
197
|
+
piechart : Ext.chart.PieChart,
|
198
|
+
|
199
|
+
arraystore : Ext.data.ArrayStore,
|
200
|
+
directstore : Ext.data.DirectStore,
|
201
|
+
groupingstore : Ext.data.GroupingStore,
|
202
|
+
jsonstore : Ext.data.JsonStore,
|
203
|
+
simplestore : Ext.data.SimpleStore,
|
204
|
+
store : Ext.data.Store,
|
205
|
+
xmlstore : Ext.data.XmlStore
|
206
|
+
},
|
207
|
+
|
208
|
+
/**
|
209
|
+
* @private
|
210
|
+
* Throws a custom Error if the view name has not been registered yet
|
211
|
+
* @param {String} name The name of the view that could not be found
|
212
|
+
*/
|
213
|
+
throwViewNotFoundError: function(name) {
|
214
|
+
var dir = name.split("-")[0],
|
215
|
+
file = name.split("-")[1];
|
216
|
+
|
217
|
+
var msg = String.format(
|
218
|
+
"The {0} view could not be found, please check that your app/views/{1} directory contains a file called {2}, " +
|
219
|
+
"that the file contains \"{3}\" and that config/environment.json includes this file",
|
220
|
+
name,
|
221
|
+
dir,
|
222
|
+
file,
|
223
|
+
String.format("Ext.registerView('{0}', '{1}')", dir, file)
|
224
|
+
);
|
225
|
+
throw new Error(msg);
|
226
|
+
}
|
227
|
+
});
|
228
|
+
|
229
|
+
ExtMVC.registerClassManager('view', new ExtMVC.lib.ViewClassManager());
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Old versions of String extensions. Not sure if we should be augmenting String like the above so have left this for reference
|
3
|
+
*/
|
4
|
+
|
5
|
+
// /**
|
6
|
+
// * @param {String} str A string to be capitalized
|
7
|
+
// * @returns A capitalized string (e.g. "some test sentence" becomes "Some test sentence")
|
8
|
+
// * @type String
|
9
|
+
// */
|
10
|
+
// String.capitalize = function(str) {
|
11
|
+
// return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
|
12
|
+
// };
|
13
|
+
//
|
14
|
+
// /**
|
15
|
+
// * @param {String} str A string to be turned into title case
|
16
|
+
// * @returns The string in Title Case (e.g. "some test sentence" becomes "Some Test Sentence")
|
17
|
+
// * @type String
|
18
|
+
// */
|
19
|
+
// String.titleize = function(str) {
|
20
|
+
// return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
21
|
+
// };
|
22
|
+
//
|
23
|
+
// /**
|
24
|
+
// * Takes any string and de-underscores and uppercases it
|
25
|
+
// * e.g. long_underscored_string => LongUnderscoredString
|
26
|
+
// */
|
27
|
+
// String.camelize = function(class_name_string) {
|
28
|
+
// return String.titleize(class_name_string.replace(/_/g, " ")).replace(/ /g, "");
|
29
|
+
//
|
30
|
+
// // this feels nicer, sadly no collect function (yet) though
|
31
|
+
// // class_name_string.split("_").collect(function(e) {return String.capitalize(e)}).join("");
|
32
|
+
// };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/**
|
2
|
+
* Manages registration and retrieval of MVC Model adapters
|
3
|
+
* @class ExtMVC.model.AdapterManager
|
4
|
+
*/
|
5
|
+
ExtMVC.model.AdapterManager = {
|
6
|
+
/**
|
7
|
+
* @property adapters
|
8
|
+
* @type Object
|
9
|
+
* Key/Value pairs of registered names and the relevant Adapter objects
|
10
|
+
*/
|
11
|
+
adapters: {},
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Registers an adapter for use with MVC Models.
|
15
|
+
* @param {String} name String name for this Adapter (e.g. 'REST')
|
16
|
+
* @param {Function} object A reference to the Adapter object itself
|
17
|
+
*/
|
18
|
+
register: function(name, constructor) {
|
19
|
+
this.adapters[name] = constructor;
|
20
|
+
},
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Retrieves the requested adapter by key name
|
24
|
+
* @param {String} name The name of the adapter to fine (e.g. 'REST')
|
25
|
+
* @return {Object/Null} The Adapter object, if found
|
26
|
+
*/
|
27
|
+
find: function(name, config) {
|
28
|
+
return this.adapters[name];
|
29
|
+
}
|
30
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* class ExtMVC.model.Association
|
3
|
+
* @ignore
|
4
|
+
*/
|
5
|
+
ExtMVC.model.Association = {
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @ignore
|
9
|
+
* Returns the default association name for a given class (e.g. "Post" becomes "posts", "SecretAgent" becomes "secretAgents" etc)
|
10
|
+
* @param {String} className The string name of the class which this belongs to
|
11
|
+
* @return {String} The association name for this class
|
12
|
+
*/
|
13
|
+
hasManyAssociationName: function(className) {
|
14
|
+
return className.toLowerCase() + 's';
|
15
|
+
},
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @ignore
|
19
|
+
* Returns the default association name for a given class (e.g. "Post" becomes "post", "SecretAgent" becomes "secretAgent")
|
20
|
+
* @param {String} className The string name of the class to calculate a belongsTo name for
|
21
|
+
* @return {String} The association name for this class
|
22
|
+
*/
|
23
|
+
belongsToAssociationName: function(className) {
|
24
|
+
return className.toLowerCase();
|
25
|
+
}
|
26
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.model.Base
|
3
|
+
* A set of properties and functions which are applied to all ExtMVC.models when they are defined
|
4
|
+
*/
|
5
|
+
ExtMVC.model.Base = function() {};
|
6
|
+
|
7
|
+
ExtMVC.model.Base.prototype = {
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @property primaryKey
|
11
|
+
* @type String
|
12
|
+
* The name of the field assumed to be the primary key (defaults to 'id')
|
13
|
+
*/
|
14
|
+
primaryKey: 'id',
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Returns true if this model's primaryKey has not yet been set (i.e. it has not been saved yet)
|
18
|
+
* @return {Boolean} True if this model's primaryKey has not yet been set
|
19
|
+
*/
|
20
|
+
newRecord: function() {
|
21
|
+
var id = this.get(this.primaryKey);
|
22
|
+
return typeof id == 'undefined' || id == '';
|
23
|
+
},
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Returns a unique string for a model instance, suitable for use as a key in a cache (e.g. ExtMVC.model.Cache).
|
27
|
+
* new User({id: 123}).MVCModelId(); //'user-123'
|
28
|
+
* @return {String} The unique key for this model object
|
29
|
+
*/
|
30
|
+
MVCModelId: function() {
|
31
|
+
return String.format("{0}-{1}", this.tableName, this.get(this.primaryKey));
|
32
|
+
},
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Returns a JsonReader suitable for use decoding generic JSON data from a server response
|
36
|
+
* Override this to provide your own Reader
|
37
|
+
*/
|
38
|
+
getReader: function() {
|
39
|
+
if (!this.reader) {
|
40
|
+
this.reader = new Ext.data.JsonReader({
|
41
|
+
totalProperty: "results",
|
42
|
+
root: this.tableName
|
43
|
+
}, this.constructor);
|
44
|
+
}
|
45
|
+
|
46
|
+
return this.reader;
|
47
|
+
},
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @property initialize
|
51
|
+
* @type Function
|
52
|
+
* Function which is called whenever a model object is instantiated. Override this with your own callback if needed
|
53
|
+
*/
|
54
|
+
initialize: Ext.emptyFn
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @ignore
|
60
|
+
* Add the above Base methods and properties to the Ext.data.Record prototype. This means all Record instances
|
61
|
+
* will have MVC models methods, even if not instantiated by an MVC-defined model constructor
|
62
|
+
*/
|
63
|
+
Ext.apply(Ext.data.Record.prototype, new ExtMVC.model.Base());
|
@@ -0,0 +1,116 @@
|
|
1
|
+
/**
|
2
|
+
* @class ExtMVC.model.BelongsToAssociation
|
3
|
+
* @extends ExtMVC.model.Association
|
4
|
+
*/
|
5
|
+
ExtMVC.model.BelongsToAssociation = function(ownerObject, config) {
|
6
|
+
var config = config || {};
|
7
|
+
|
8
|
+
Ext.applyIf(config, {
|
9
|
+
associationName: ExtMVC.model.Association.belongsToAssociationName(config.name)
|
10
|
+
});
|
11
|
+
|
12
|
+
//TODO: these should be abstracted to a parent object (as should private vars and funcs below)
|
13
|
+
Ext.applyIf(config, {
|
14
|
+
primaryKey: 'id',
|
15
|
+
foreignKey: ownerObject.foreignKeyName,
|
16
|
+
extend: {},
|
17
|
+
|
18
|
+
className: (ownerObject.constructor.namespace ? ownerObject.constructor.namespace + '.' + config.name : config.name)
|
19
|
+
});
|
20
|
+
|
21
|
+
//get a reference to the class definition function of the associated object
|
22
|
+
//(e.g. a hasMany: ['Post'] association will return a reference to Post)
|
23
|
+
var associatedObjectClass = eval(config.className);
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Private, calls the ownerObject's class method with the supplied args
|
27
|
+
*/
|
28
|
+
function callOwnerObjectClassMethod(method, args, scope) {
|
29
|
+
return ownerObject.constructor[method].apply(scope || ownerObject.constructor, args || []);
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Private, calls the associated object's class method with the supplied args
|
34
|
+
*/
|
35
|
+
function callAssociatedObjectClassMethod (method, args, scope) {
|
36
|
+
return associatedObjectClass[method].apply(scope || associatedObjectClass, args || []);
|
37
|
+
};
|
38
|
+
|
39
|
+
return {
|
40
|
+
/**
|
41
|
+
* @property associationName
|
42
|
+
* @type String
|
43
|
+
* Returns the name of this association so that the model can add it to its definition
|
44
|
+
*/
|
45
|
+
associationName: config.associationName,
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @property associationClass
|
49
|
+
* @type ExtMVC.model
|
50
|
+
* A reference to the association's class (e.g. belongsTo: "Post" would have associationClass of Post)
|
51
|
+
*/
|
52
|
+
associationClass: associatedObjectClass,
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @property associationType
|
56
|
+
* @type String
|
57
|
+
* The type of association (hasMany or belongsTo)
|
58
|
+
*/
|
59
|
+
associationType: 'belongsTo',
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @property lastFetched
|
63
|
+
* @type Date
|
64
|
+
* Date object representing the last time the associated object was successfully fetched
|
65
|
+
*/
|
66
|
+
lastFetched: null,
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Sets the associated model for this association to the specified model object
|
70
|
+
* @param {ExtMVC.model} modelObject The associated model to set this belongsTo association to
|
71
|
+
*/
|
72
|
+
set: function(modelObject) {
|
73
|
+
this.lastFetched = new Date();
|
74
|
+
this.cachedObject = modelObject;
|
75
|
+
|
76
|
+
//add the foreign key automatically
|
77
|
+
ownerObject.data[modelObject.foreignKeyName] = modelObject.data[config.primaryKey];
|
78
|
+
},
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Gets the associated model for this association
|
82
|
+
* @param {Object} options Options to pass through to the Ajax load request
|
83
|
+
* @param {Number} cacheFor If the object has been retrieved less than this number of seconds ago, use the cached object
|
84
|
+
*/
|
85
|
+
get: function(options, cacheFor) {
|
86
|
+
var options = options || {};
|
87
|
+
var cacheFor = cacheFor || 0;
|
88
|
+
|
89
|
+
Ext.applyIf(options, {
|
90
|
+
loadSuccess: Ext.emptyFn,
|
91
|
+
loadFailure: Ext.emptyFn
|
92
|
+
});
|
93
|
+
|
94
|
+
var cacheIsCurrent = (((new Date() - this.lastFetched) / 1000) < cacheFor) || (cacheFor == -1);
|
95
|
+
|
96
|
+
if (this.lastFetched && this.cachedObject && cacheIsCurrent) {
|
97
|
+
//return the cached object via a callback
|
98
|
+
options.loadSuccess.call(options.scope || this, this.cachedObject);
|
99
|
+
|
100
|
+
//also return via normal return if this is a cached object. This allows some functions to use the cached object
|
101
|
+
//without the overhead of setting up a callback, so long as they first check that the object has been fetched
|
102
|
+
return this.cachedObject;
|
103
|
+
} else {
|
104
|
+
//inject caching code before loadSuccess - caches the object into this.cachedObject and sets this.lastFetched to now
|
105
|
+
Ext.apply(options, {
|
106
|
+
loadSuccess: options.loadSuccess.createInterceptor(function(obj) {
|
107
|
+
this.cachedObject = obj;
|
108
|
+
this.lastFetched = new Date();
|
109
|
+
}, this)
|
110
|
+
});
|
111
|
+
|
112
|
+
return callAssociatedObjectClassMethod('findById', [1, options]);
|
113
|
+
};
|
114
|
+
}
|
115
|
+
};
|
116
|
+
};
|