extjs-mvc 0.4.0.f → 0.4.0.g
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/bin/extjs-mvc +0 -3
- data/lib/extjs-mvc.rb +10 -6
- data/lib/extjs-mvc/api.rb +0 -1
- metadata +8 -84
- data/lib/src/App.js +0 -219
- data/lib/src/MVC.js +0 -260
- data/lib/src/Presenter.js +0 -52
- data/lib/src/README.rdoc +0 -69
- data/lib/src/controller/Controller.js +0 -278
- data/lib/src/controller/CrudController.js +0 -460
- data/lib/src/lib/Array.js +0 -26
- data/lib/src/lib/Booter.js +0 -416
- data/lib/src/lib/ClassManager.js +0 -191
- data/lib/src/lib/ControllerClassManager.js +0 -95
- data/lib/src/lib/Dependencies.js +0 -44
- data/lib/src/lib/DispatchMatcher.js +0 -98
- data/lib/src/lib/Dispatcher.js +0 -129
- data/lib/src/lib/Environment.js +0 -43
- data/lib/src/lib/Inflector.js +0 -155
- data/lib/src/lib/ModelClassManager.js +0 -19
- data/lib/src/lib/Route.js +0 -139
- data/lib/src/lib/Router.js +0 -282
- data/lib/src/lib/String.js +0 -94
- data/lib/src/lib/ViewClassManager.js +0 -229
- data/lib/src/lib/notes.txt +0 -32
- data/lib/src/model/AdapterManager.js +0 -30
- data/lib/src/model/Association.js +0 -26
- data/lib/src/model/Base.js +0 -63
- data/lib/src/model/BelongsToAssociation.js +0 -116
- data/lib/src/model/Cache.js +0 -131
- data/lib/src/model/HasManyAssociation.js +0 -160
- data/lib/src/model/Model.js +0 -331
- data/lib/src/model/UrlBuilder.js +0 -106
- data/lib/src/model/adapters/AbstractAdapter.js +0 -296
- data/lib/src/model/adapters/MemoryAdapter.js +0 -103
- data/lib/src/model/adapters/RESTAdapter.js +0 -345
- data/lib/src/model/adapters/RESTJSONAdapter.js +0 -68
- data/lib/src/model/adapters/notes.txt +0 -42
- data/lib/src/model/associations/Association.js +0 -192
- data/lib/src/model/associations/notes.txt +0 -87
- data/lib/src/model/validations/Errors.js +0 -136
- data/lib/src/model/validations/Plugin.js +0 -139
- data/lib/src/model/validations/Validations.js +0 -276
- data/lib/src/notes/Charts.graffle +0 -0
- data/lib/src/overrides/Ext.Component.js +0 -21
- data/lib/src/overrides/Ext.extend.js +0 -142
- data/lib/src/spec/Array.spec.js +0 -15
- data/lib/src/spec/ExtMVC.spec.js +0 -65
- data/lib/src/spec/Model.spec.js +0 -370
- data/lib/src/spec/OS.spec.js +0 -83
- data/lib/src/spec/Router.spec.js +0 -99
- data/lib/src/spec/SpecHelper.js +0 -106
- data/lib/src/spec/String.spec.js +0 -83
- data/lib/src/spec/model/AbstractAdapter.spec.js +0 -49
- data/lib/src/spec/model/Associations.spec.js +0 -99
- data/lib/src/spec/model/Cache.spec.js +0 -5
- data/lib/src/spec/model/RESTAdapter.spec.js +0 -19
- data/lib/src/spec/model/ValidationErrors.spec.js +0 -64
- data/lib/src/spec/model/Validations.spec.js +0 -166
- data/lib/src/spec/model/ValidationsPlugin.spec.js +0 -108
- data/lib/src/spec/suite.html +0 -60
- data/lib/src/specs-old/JSSpec.css +0 -216
- data/lib/src/specs-old/JSSpec.js +0 -1512
- data/lib/src/specs-old/all.html +0 -66
- data/lib/src/specs-old/base.js +0 -14
- data/lib/src/specs-old/controller.js +0 -17
- data/lib/src/specs-old/diff_match_patch.js +0 -1
- data/lib/src/specs-old/model.js +0 -70
- data/lib/src/specs-old/route.js +0 -38
- data/lib/src/specs-old/router.js +0 -59
- data/lib/src/specs-old/string.js +0 -22
- data/lib/src/testrunner/JSpecFormatter.js +0 -111
- data/lib/src/testrunner/TestClient.js +0 -181
- data/lib/src/testrunner/TestGrid.js +0 -351
- data/lib/src/testrunner/TestRunner.js +0 -110
- data/lib/src/testrunner/TestViewport.js +0 -94
- data/lib/src/vendor.yml +0 -29
- data/lib/src/vendor/ext-3.1.1/vendor.yml +0 -16
- data/lib/src/view/FormWindow.js +0 -184
- data/lib/src/view/HasManyEditorGridPanel.js +0 -211
- data/lib/src/view/scaffold/Edit.js +0 -46
- data/lib/src/view/scaffold/Index.js +0 -561
- data/lib/src/view/scaffold/New.js +0 -20
- data/lib/src/view/scaffold/ScaffoldFormPanel.js +0 -255
@@ -1,229 +0,0 @@
|
|
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());
|
data/lib/src/lib/notes.txt
DELETED
@@ -1,32 +0,0 @@
|
|
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
|
-
// };
|
@@ -1,30 +0,0 @@
|
|
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
|
-
};
|
@@ -1,26 +0,0 @@
|
|
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
|
-
};
|
data/lib/src/model/Base.js
DELETED
@@ -1,63 +0,0 @@
|
|
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());
|
@@ -1,116 +0,0 @@
|
|
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
|
-
};
|