forked from extmvc/extmvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ext-mvc-all.js
7277 lines (6262 loc) · 230 KB
/
ext-mvc-all.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @class ExtMVC
* ExtMVC
* @singleton
*/
ExtMVC = Ext.extend(Ext.util.Observable, {
version: "0.7a",
constructor: function() {
ExtMVC.superclass.constructor.apply(this, arguments);
/**
* @property dispatcher
* @type Ext.lib.Dispatcher
* The dispatcher object which finds the right controller and action when ExtMVC.dispatch is called
*/
// this.dispatcher = new Ext.lib.Dispatcher({
//
// });
},
dispatch: function() {
var dispatcher = this.dispatcher;
return dispatcher.dispatch.apply(dispatcher, arguments);
},
/**
* Sets the Ext.Application instance currently in use. This is currently required :/
* @param {Ext.Application} app The application currently in use
*/
setApplication: function(app) {
this.app = app;
this.name = app.name;
ExtMVC.model.modelNamespace = window[app.name].models;
},
fields: {
},
registerFields: function(name, fields) {
this.fields[name] = fields;
},
getFields: function(name) {
return this.fields[name];
},
/**
* Registers a model class with Ext MVC
* @param {String} name The name to give this model
* @param {Object} config Model definition configuration
*/
registerModel: function(name, config) {
this.registerClass('model', arguments);
},
/**
* Registers a controller class with Ext MVC
* @param {String} name The name to give this controller
* @param {Object} config Controller definition configuration
*/
registerController: function(name, config) {
this.registerClass('controller', arguments);
},
/**
* Registers a view class with Ext MVC.
* @param {String} namesapce The namespace to add this view to
* @param {String} name The name to give this view
* @param {Object} config View definition configuration
*/
registerView: function(namespace, name, config) {
this.registerClass('view', arguments);
},
/**
* Abstraction for registering views, models and controllers
* @param {String} managerName The name of the class manager to register with
* @param {Array} args The args to pass to the manager's register method
*/
registerClass: function(managerName, args) {
var manager = this.getClassManager(managerName);
manager.register.apply(manager, args);
},
/**
* @property classManagers
* @type Object
* {name: classManager} mappings used by this.getClassManager and this.registerClassManager
*/
classManagers: {},
/**
* @private
* Sets up model, view and controller class managers
*/
initializeClassManagers: function() {
this.registerClassManager('model', new ExtMVC.lib.ModelClassManager());
this.registerClassManager('view', new ExtMVC.lib.ViewClassManager());
this.registerClassManager('controller', new ExtMVC.lib.ControllerClassManager());
},
/**
* Returns the class manager for the given name
* @param {String} name The name of the manager (model, view or controller)
* @return {ExtMVC.lib.ClassManager} The class manager instance
*/
getClassManager: function(name) {
return this.classManagers[name];
},
/**
* Registers a class manager instance under a given name
* @param {String} name The name of the class manager
* @param {ExtMVC.lib.ClassManager} manager The ClassManager instance to register
*/
registerClassManager: function(name, manager) {
this.classManagers[name] = manager;
},
/**
* Returns the canonical controller instance for the given controller name
* @return {ExtMVC.Controller} The controller instance
*/
getController: function(name) {
return this.getClassManager('controller').getInstance(name);
},
/**
* Returns the constructor for a given model name
* @param {String} name The name of the model
* @return {Function} The model constructor
*/
getModel: function(name) {
return this.getClassManager('model').getConstructor(name);
},
/**
* Instantiates a model of the given name with the data supplied
* @param {String} modelName The name of the model to instantiate
* @param {Object} data Data object to instantiate the instance with
* @return {ExtMVC.Model} The new model instance
*/
buildModel: function(modelName, data) {
return new (this.getModel(modelName))(data);
},
/**
* Returns the constructor for a given view namespace/name combination
* @param {String} namespace The view namespace to look in
* @param {String} name The name of the view within the view namespace
* @return {Function} The view constructor
*/
getView: function getView(namespace, name) {
return this.getClassManager('view').getConstructor(namespace, name);
},
/**
* Returns a new view instance for the given namespace/name combo, using the supplied config
* @param {String} namespace The namespace to find the view from
* @param {String} name The view name
* @param {Object} config Optional config object
* @return {Ext.Component} The new view instance
*/
buildView: function buildView(namespace, name, config) {
var constructor = this.getView(namespace, name);
return new (constructor)(config);
},
/**
* Loads packaged classes from a given url, calling a callback when they have been registered. Sample return:
<pre>
{
controllers: [
{
name: 'comments',
superclass: 'crud',
config: {
index: function() {
this.render('index', {
title: "Loaded on demand!"
});
}
}
}
],
views: [
{
name: 'new',
namespace: 'comments',
config: {
xtype: 'scaffoldnew',
title: "New Comment"
}
}
],
models: [
{
name : 'Comment',
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'title', type: 'string'},
{name: 'message', type: 'string'}
]
}
}
]
}
</pre>
* @param {String} url The url to retrieve the package from
* @param {Function} callback Optional callback function, called after the package has been read and registered
* @param {Object} scope The scope to execute the callback function in
*/
loadOnDemand: function(url, callback, scope) {
Ext.Ajax.request({
url : url,
scope : scope || this,
success: function(response) {
var pkg = Ext.decode(response.responseText);
Ext.each(pkg.controllers || [], function(config) {
this.registerController(config.name, config);
}, this);
Ext.each(pkg.models || [], function(config) {
this.registerModel(config.name, config);
}, this);
Ext.each(pkg.views || [], function(config) {
this.registerView(config.namespace, config.name, config);
}, this);
if (Ext.isFunction(callback)) callback.call(scope, pkg);
}
});
}
});
ExtMVC = new ExtMVC();
// ExtMVC.initializeClassManagers();
Ext.onReady(function() {
/**
* @property dispatcher
* @type Ext.lib.Dispatcher
* The dispatcher object which finds the right controller and action when ExtMVC.dispatch is called
*/
ExtMVC.dispatcher = new ExtMVC.lib.Dispatcher();
});
Ext.ns('ExtMVC.router', 'ExtMVC.plugin', 'ExtMVC.controller', 'ExtMVC.view', 'ExtMVC.view.scaffold', 'ExtMVC.lib', 'ExtMVC.test');
/**
* @class ExtMVC.App
* @extends Ext.util.Observable
* @cfg {Boolean} usesHistory True to automatically create required DOM elements for Ext.History,
* sets up a listener on Ext.History's change event to fire this.onHistoryChange. False by default
*/
ExtMVC.App = Ext.extend(Ext.util.Observable, {
/**
* @constructor
* Sets up the Application - adds events, sets up namespaces, optionally sets up history.
* Fires the 'before-launch' event before initializing router, viewport and history.
* Calls this.launch() once everything else is set up (override the 'launch' method to provide your own logic).
* Fires the 'launched' event after calling this.launch()
*/
constructor: function(config) {
ExtMVC.App.superclass.constructor.apply(this, arguments);
//apply configuration object and set up namespaces
Ext.apply(this, config || {});
window[this.name] = this;
this.initializeNamespaces();
// Ext.onReady(this.onReady, this);
this.on('launched', function() {
/**
* TODO: This used to reside in initializeHistory but this.launch() needs to be
* called before this dispatches so it is temporarily here... ugly though
*/
if (this.usesHistory) {
if (this.dispatchHistoryOnLoad === true) {
Ext.History.init(function(history) {
var hash = document.location.hash.replace("#", "");
var params = this.router.recognise(hash);
if (params) {this.dispatch(params);}
}, this);
} else {
Ext.History.init();
}
}
}, this);
},
/**
* @private
* Called when Ext.onReady fires
*/
onReady: function() {
if (this.fireEvent('before-launch', this)) {
this.initializeRouter();
// this.initializeViewport();
this.initializeEvents();
if (this.usesHistory === true) this.initializeHistory();
this.launch();
}
},
/**
* @property name
* @type String
* The application's name. This is used when creating namespaces for models, views and controllers,
* and automatically set up as a global variable reference to this application. Read only.
*/
name: 'MyApp',
/**
* @property usesHistory
* @type Boolean
* True to automatically create required DOM elements for Ext.History,
* sets up a listener on Ext.History's change event to fire this.onHistoryChange.
* False by default
*/
usesHistory: false,
/**
* @prop dispatchHistoryOnLoad
* @type Boolean
* If usesHistory is true and dispatchHistoryOnLoad is also true, the OS will attempt to match
* any string currently after the # in the url and dispatch to it
*/
dispatchHistoryOnLoad: true,
/**
* Called when the application is booted up. Override this to provide your own startup logic (defaults to Ext.emptyFn)
*/
launch: function() {
this.fireEvent('launched', this);
},
/**
* @property params
* @type Object
* An object containing the most current parameters (usually decoded from a url using this.router)
* e.g. {controller: 'index', action: 'welcome', id: 10}
*/
params: {},
/**
* Dispatches a request to a registered controller.
* @param {Object} dispatchConfig A config object which should look something like this:
* {controller: 'MyController', action: 'index'}, where 'MyController' is the key for a controller
* which has been registered to the controller. If action is not specified, it defaults to 'index'
* @param {Object} scope The scope in which to fire the event (defaults to the controller)
* @param {Array} args An array of arguments which are passed to the controller action.
*/
dispatch: function dispatch(dispatchConfig, scope, args) {
var dispatchConfig = dispatchConfig || {};
Ext.applyIf(dispatchConfig, {
action: 'index'
});
this.params = dispatchConfig;
var c = ExtMVC.getController(dispatchConfig.controller);
if (c != undefined) {
var action = c[dispatchConfig.action];
if (typeof action == "function") action.apply(scope || c, args || []);
else throw new Error(String.format("Action '{0}' not found on Controller '{1}'", dispatchConfig.action, dispatchConfig.controller));
}
},
/**
* Sets up a Router instance. This is called automatically before onLaunch()
* Add routes using this.router.connect
*/
initializeRouter: function() {
if (this.router == undefined) {
this.router = new ExtMVC.router.Router();
ExtMVC.router.Router.defineRoutes(this.router);
}
},
/**
* Uses Ext.namespace to create packages view controllers, models and views
* E.g. if name = 'Blog' or this.name = 'Blog', this is the same as:
* Ext.ns('Blog', 'Blog.controllers', 'Blog.models', 'Blog.views')
*/
initializeNamespaces: function initializeNamespaces(name) {
var name = name || this.name;
if (name) {
Ext.ns(name, name + '.controllers', name + '.models', name + '.views');
};
},
/**
* Creates the necessary DOM elements required for Ext.History to manage state
* Sets up listeners on Ext.History's change event to fire the dispatch() action in the normal way.
* This is not called automatically as not all applications will need it
*/
initializeHistory: function initializeHistory() {
this.historyForm = Ext.getBody().createChild({
tag: 'form',
action: '#',
cls: 'x-hidden',
id: 'history-form',
children: [
{
tag: 'div',
children: [
{
tag: 'input',
id: 'x-history-field',
type: 'hidden'
},
{
tag: 'iframe',
id: 'x-history-frame'
}
]
}
]
});
Ext.History.on('change', this.onHistoryChange, this);
},
/**
* Takes a history token (anything after the # in the url), consults the router and dispatches
* to the appropriate controller and action if a match was found
* @param {String} token The url token (e.g. the token would be cont/act/id for a url like mydomain.com/#cont/act/id)
*/
onHistoryChange: function onHistoryChange(token) {
var match = this.router.recognise(token);
if (match) {
this.dispatch(match, null, [{url: token}]);
};
},
/**
* Sets up events emitted by the Application
*/
initializeEvents: function initializeEvents() {
this.addEvents(
/**
* @event before-launch
* Fires before this application launches
* @param {ExtMVC.App} this The application about to be launched
*/
'before-launch',
/**
* @event launched
* Fires once the application has been launched
* @param {ExtMVC.App} this The application which has been launched
*/
'launched'
);
}
});
ExtMVC.App.define = function(config) {
ExtMVC.app = new ExtMVC.App(config);
};
ExtMVC.lib.ClassManager = Ext.extend(Ext.util.Observable, {
/**
* @property autoDefine
* @type Boolean
* If true, the ClassManager will attempt to define classes immediately via this.define (defaults to true)
*/
autoDefine: true,
constructor: function constructor(config) {
config = config || {};
Ext.applyIf(config, {
/**
* @property registeredClasses
* @type Object
* {name: config} mapping of all registered classes
*/
registeredClasses: {},
/**
* @property constructors
* @type Object
* {name: Function} mapping of all registered classes to their constructor functions
*/
constructors: {}
});
Ext.apply(this, config);
this.addEvents(
/**
* @event class-registered
* Fires when a class has been registered to this package
* @param {String} name The name of the class
* @param {Object} config The class config object
*/
'class-registered',
/**
* @event class-defined
* Fires after a class has been registered and then defined using Ext.extend
* @param {String} name The name of the class
* @param {Function} constructor The class constructor
*/
'class-defined'
);
// this.on({
// scope : this,
// 'class-registered': this.afterRegister,
// 'class-defined' : this.afterDefine
// });
},
/**
* Registers a config object or class constructor to a given class name
* @param {String} name The name to register this class under
* @param {Object/Function} config Either a config object or a constructor function
*/
register: function register(name, config) {
this.registeredClasses[name] = config;
this.fireEvent('class-registered', name, config);
if (this.autoDefine === true) this.define(name);
},
/**
* Returns the config object for a given class name. Only really useful privately
* @param {String} name The name of the class
* @return {Object} The config object for this class
*/
getRegistered: function getRegistered(name) {
return this.registeredClasses[name];
},
/**
* Defines the given class name by using Ext.extend to declare it. The result of Ext.extend
* is then stored in this.constructors, and the constructor can then be retrieved with this.getConstructor(name)
* @param {String} name The name of the class to define
* @return {Function} The newly defined class constructor
*/
define: function define(name) {
console.log('defining');
console.log(name);
var overrides = this.getRegistered(name);
//extend the parent object and register the constructor
var klass = Ext.extend(this.getConstructor(overrides.extend), overrides);
this.constructors[name] = klass;
this.fireEvent('class-defined', name, klass);
return klass;
},
/**
* Returns the constructor function for a registered class name. If the constructor
* itself hasn't been defined yet, it is defined first using this.define(), then returned
* @param {String} name The name of the class to return the constructor for
* @return {Function} The constructor function
*/
getConstructor: function getConstructor(name) {
return this.constructors[name] || this.define(name);
}
});
/**
* Ideal syntax after these changes:
*/
// ExtMVC.registerView('index', 'index', {
// xtype: "panel",
// title: "Welcome to Ext MVC",
// html : "This is a test"
// });
//
// Ext.registerController("index", {
// index: function() {
// this.render("index", {
// title: "Different Title"
// });
// },
//
// //this would actually be here by default
// welcome: function() {
// this.render("index");
// },
//
// //if we give the function a name, we can accept alternative render format:
// //all MVC Crud controller methods can be made like this
// search: function search() {
// this.render({
// //options for new MyApp.views.index.search
// });
// },
//
// create: function(data) {
// var newUser = ExtMVC.buildModel("SuperUser", data);
//
// newUser.save({
// success: function(user) {
//
// },
// failure: function(user) {
//
// }
// });
//
// //or how about
// ExtMVC.createModel("SuperUser", data, {
// success: function(user) {
//
// },
// failure: function(user) {
//
// }
// });
// },
//
// update: function(user, changes) {
// user.update(changes, {
// success: function(user) {
//
// },
// failure: function(user) {
//
// }
// });
// }
// });
//
// ExtMVC.registerController("someSubController", {
// extend: "index",
//
// index: function() {
// this.superclass.index.call(this);
// }
// });
//
//
// ExtMVC.registerModel("SuperUser", {
// extend: "User",
// fields: [
// {name: 'id', type: 'int'}
// ]
// });
/**
* @class Array
* Extensions to the array class
*/
/**
* Turns an array into a sentence, joined by a specified connector - e.g.:
* ['Adama', 'Tigh', 'Roslin'].toSentence(); //'Adama, Tigh and Roslin'
* ['Adama', 'Tigh', 'Roslin'].toSentence('or'); //'Adama, Tigh or Roslin'
* @param {String} connector The string to use to connect the last two words. Usually 'and' or 'or', defaults to 'and'
*/
Array.prototype.toSentence = function(connector) {
connector = connector || 'and';
var sentence = "";
if (this.length <= 1) {
sentence = this[0];
} else {
//we'll join all but the last error with commas
var firstErrors = this.slice(0, this.length - 1);
//add the last error, with the connector string
sentence = String.format("{0} {1} {2}", firstErrors.join(", "), connector, this[this.length - 1]);
}
return sentence;
};
/**
* @class ExtMVC.lib.Booter
* @extends Ext.util.Observable
* Boots an Ext MVC application by loading all application files and launching
*/
ExtMVC.lib.Booter = Ext.extend(Ext.util.Observable, {
/**
* @property defaultBootParams
* @type Object
* Contains default boot parameters (e.g. sets the default environment to 'production')
*/
defaultBootParams: {
environment: 'production'
},
constructor: function(config) {
config = config || {};
Ext.applyIf(config, this.parseLocationParams());
Ext.apply(this, config, this.defaultBootParams);
ExtMVC.lib.Booter.superclass.constructor.apply(this, arguments);
this.initEvents();
this.initListeners();
},
/**
* The Booter loads some code asynchronously, so uses events to proceed the logic. This sets up
* all of the internal event monitoring.
*/
initListeners: function() {
this.on('environment-loaded', this.loadApplicationFiles, this);
this.on({
scope : this,
'environment-loaded' : this.loadApplicationFiles,
'application-files-loaded': this.launchApp,
'boot-complete' : this.onBootComplete
});
},
/**
* Sets up events emitted by this component
*/
initEvents: function() {
this.addEvents(
/**
* @event before-boot
* Called just before boot starts. Use this as a hook to tie in any pre-boot logic
* @param {ExtMVC.lib.Booter} this The Booter instance
*/
'before-boot',
/**
* @event boot-complete
* Fires when the entire boot sequence has been completed
*/
'boot-complete',
/**
* @event environment-loaded
* Fires when environment config data has been retrieved
* @param {ExtMVC.Environment} environment the Ext.Environment object
*/
'environment-loaded',
/**
* @event app-files-loaded
* Fires when all application files (overrides, config, models, views and controllers)
* have been loaded and are available
*/
'application-files-loaded',
/**
* @event application-launched
* Fires after the application has been launched
*/
'application-launched'
);
},
boot: function() {
this.fireEvent('before-boot');
if (this.useLoadingMask) this.addLoadingMask();
this.loadEnvironment();
},
/**
* Called when the app has been fully booted. Override to provide you own logic (defaults to an empty function)
*/
onBootComplete: function() {},
/**
* Loads up the current environment by loading config/environment.json, and the appropriate file from within
* config/environments/ for the current environment (e.g. config/environments/production.json)
*/
loadEnvironment: function() {
Ext.Ajax.request({
url : 'config/environment.json',
scope : this,
success: function(response, options) {
var envName = this.environment;
this.environment = new ExtMVC.Environment(Ext.decode(response.responseText));
Ext.Ajax.request({
url : String.format("config/environments/{0}.json", envName),
success: function(response, options) {
this.environment.update(Ext.decode(response.responseText));
this.fireEvent('environment-loaded', this.environment);
},
scope : this
});
},
failure: function() {
Ext.Msg.alert(
'Could not load environment',
'The environment could not be found'
);
}
});
},
/**
* Loads all required application files, fires the 'app-files-loaded' event when done
* @param {ExtMVC.Environment} environment The ExtMVC.Environment to gather file list from
*/
loadApplicationFiles: function(env) {
this.loadStylesheets(env);
//if the 'scripts' property on the Environment is present then models, controllers, plugins etc are ignored
if (Ext.isArray(env.scripts)) { //&& env.scripts.length > 0) {
if (env.scripts.length == 0) {
this.fireEvent('application-files-loaded');
} else {
this.loadFiles(env.scripts, false, function() {
this.fireEvent('application-files-loaded');
}, this);
}
return;
}
var order = ['overrides', 'config', 'plugins', 'models', 'controllers', 'views'],
baseFiles = [],
pluginFiles = [],
modelFiles = [],
controllerFiles = [],
viewFiles = [];
// var groups = {
// 'base': {preserveOrder: false, }
// };
Ext.each(env.config, function(file) {
baseFiles.push(String.format("../{0}.js", file));
}, this);
Ext.each(env.plugins, function(file) {
pluginFiles.push(String.format("{0}/{1}/{2}-all.js", env.pluginsDir, file, file));
}, this);
Ext.each(env.overrides, function(file) {
pluginFiles.push(String.format("{0}/{1}.js", env.overridesDir, file));
}, this);
Ext.each(env.models, function(file) {
modelFiles.push(String.format("{0}/models/{1}.js", env.appDir, file));
}, this);
Ext.each(env.controllers, function(file) {
controllerFiles.push(String.format("{0}/controllers/{1}Controller.js", env.appDir, file));
}, this);
Ext.each(env.views, function(viewObj) {
Ext.iterate(viewObj, function(dir, fileList) {
Ext.each(fileList, function(file) {
viewFiles.push(String.format("{0}/views/{1}/{2}.js", env.appDir, dir, file));
}, this);
}, this);
}, this);
var me = this;
var doFireEvent = function() {
me.fireEvent('application-files-loaded');
};
this.loadFiles(baseFiles, false, function() {
this.loadFiles(pluginFiles, false, function() {
this.loadFiles(modelFiles, false, function() {
this.loadFiles(controllerFiles, true, function() {
this.loadFiles(viewFiles, true, function() {
doFireEvent();
});
});
});
});
});
},
/**
* Once all application files are loaded, this launches the application, hides the loading mask, fires the
* 'application-launched' event
*/
launchApp: function() {
ExtMVC.app.onReady();
if (this.useLoadingMask) this.removeLoadingMask();
this.fireEvent('application-launched');
this.fireEvent('boot-complete');
},
/**
* @property useLoadingMask
* @type Boolean
* True to automatically add an application loading mask layer to give the user loading feedback (defaults to false)
*/
useLoadingMask: false,
/**
* Adds loading mask HTML elements to the page (called at start of bootup)
*/
addLoadingMask: function() {
var body = Ext.getBody();
body.createChild({
id: 'loading-mask'
});
body.createChild({
id: 'loading',
cn: [{
cls: 'loading-indicator',
html: this.getLoadingMaskMessage()
}]
});
},
/**
* Returns the loading mask message string. Override this to provide your own
* @return {String} The message to place inside the loading mask (defaults to "Loading...")
*/
getLoadingMaskMessage: function() {
return "Loading...";
},
/**
* @property loadingMaskFadeDelay
* @type Number
* Number of milliseconds after app launch is called before the loading mask will fade away.
* Gives your app a little time to draw its UI (defaults to 250)
*/
loadingMaskFadeDelay: 250,
/**
* Fades out the loading mask (called after bootup is complete)
*/
removeLoadingMask: function() {
(function(){
Ext.get('loading').remove();
Ext.get('loading-mask').fadeOut({remove:true});
}).defer(this.loadingMaskFadeDelay);
},
/**
* @private
* Inspects document.location and returns an object containing all of the url params
* @return {Object} The url params
*/
parseLocationParams: function() {
var args = window.location.search.split("?")[1],
params = {};
/**
* Read config data from url parameters
*/
if (args != undefined) {
Ext.each(args.split("&"), function(arg) {
var splits = arg.split("="),
key = splits[0],
value = splits[1];
params[key] = value;
}, this);
}
return params;
},
/**
* Inserts <link> tags to load stylesheets contained in the environment
* @param {ExtMVC.lib.Environment} env The environment to load stylesheets from
*/