-
Notifications
You must be signed in to change notification settings - Fork 0
/
BundledApplication.js
126 lines (111 loc) · 3.99 KB
/
BundledApplication.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Ext.app.Controller.strings.module = {
getter: 'getModule',
upper: 'Module'
};
Ext.define('Ext.app.BundledApplication', {
extend: 'Ext.app.Application',
autoCreateViewport: false,
namespace: true, //to avoid warn msg
depth: 0,
isModule: false,
onClassExtended: function (cls, data, hooks) {
var Controller = Ext.app.Controller,
proto = cls.prototype,
requires = [],
viewportClass = data.autoCreateViewport,
onBeforeClassCreated, paths, namespace, ns, appFolder;
var isApplication = cls.$className.split('.').pop() === '$application';
//if name is not provided, then assign "short" $className as name.
namespace = data.name || cls.superclass.name || (!isApplication && cls.$className.split('.').pop());
//re-assign name property
data.name = namespace;
//data.isApplication = isApplication;
data.isModule = !isApplication;
if (!isApplication) {
ns = cls.$className.replace(['', 'module', namespace].join('.'), '');
appFolder = [
Ext.Loader.getPath(ns),
'module',
data.appFolder || namespace
].join('/');
} else {
appFolder = data.appFolder || cls.superclass.appFolder;
}
if (namespace) {
data.$namespace = namespace;
Ext.app.addNamespaces(namespace);
}
if (data.namespaces) {
Ext.app.addNamespaces(data.namespaces);
}
if (!data['paths processed']) {
if (namespace && appFolder) {
Ext.Loader.setPath(namespace, appFolder);
}
paths = data.paths;
if (paths) {
for (ns in paths) {
if (paths.hasOwnProperty(ns)) {
Ext.Loader.setPath(ns, paths[ns]);
}
}
}
}
else {
delete data['paths processed'];
}
if (viewportClass) {
//<debug>
if (!namespace) {
Ext.Error.raise("[Ext.app.BundledApplication] Can't resolve namespace for " +
data.$className + ", did you forget to specify 'name' property?");
}
//</debug>
if (viewportClass === true) {
viewportClass = 'Viewport';
} else {
requires.push('Ext.plugin.Viewport');
}
Controller.processDependencies(proto, requires, namespace, 'view', viewportClass);
}
Controller.processDependencies(proto, requires, namespace, 'module', data.modules);
// Any "requires" also have to be processed before we fire up the App instance.
if (requires.length) {
onBeforeClassCreated = hooks.onBeforeCreated;
hooks.onBeforeCreated = function (cls, data) {
var args = Ext.Array.clone(arguments);
Ext.require(requires, function () {
return onBeforeClassCreated.apply(this, args);
});
};
}
},
/**
* Creates new Application.
* @param {Object} [config] Config object.
*/
constructor: function (config) {
var me = this;
Ext.app.route.Router.application = me;
me._modules = new Ext.util.MixedCollection();
me.callParent(arguments);
},
getModule: function (name, /* private */ preventCreate) {
var me = this, module, depth = 1;
if (!preventCreate) {
var _app = me,
className = me.getModuleClassName(name, 'module');
while (_app.hasOwnProperty('application')) {
_app = _app.application;
depth++;
}
module = Ext.create(className, {
application: me,
depth: depth,
moduleClassName: name
});
me._modules.add(module);
}
return module;
}
});