source: Dev/branches/rest-dojo-ui/client/dojox/app/main.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.3 KB
Line 
1define(["dojo/_base/kernel",
2        "dojo/_base/lang",
3        "dojo/_base/declare",
4        "dojo/_base/Deferred",
5        "dojo/_base/connect",
6        "dojo/ready",
7        "dojo/_base/window",
8        "dojo/dom-construct",
9        "./scene"],
10        function(dojo, lang, declare, deferred, connect, ready, baseWindow, dom, sceneCtor){
11
12        dojo.experimental("dojox.app");
13        var Application = declare([sceneCtor], {
14                constructor: function(params){
15                        this.scenes={};
16                        if(params.stores){
17                            //create stores in the configuration.
18                            for (var item in params.stores){
19                                if(item.charAt(0)!=="_"){//skip the private properties
20                                    var type = params.stores[item].type? params.stores[item].type : "dojo.store.Memory";
21                                    var config = {};
22                                    if(params.stores[item].params){
23                                        dojo.mixin(config, params.stores[item].params);
24                                    }
25                                    var storeCtor = dojo.getObject(type);
26                                    if(config.data && lang.isString(config.data)){
27                                        //get the object specified by string value of data property
28                                        //cannot assign object literal or reference to data property
29                                        //because json.ref will generate __parent to point to its parent
30                                        //and will cause infinitive loop when creating StatefulModel.
31                                        config.data = dojo.getObject(config.data);
32                                    }
33                                    params.stores[item].store = new storeCtor(config);
34                                }
35                            }
36                        }
37
38                },
39
40                // load default view and startup the default view
41        start: function(applicaton){
42            var child = this.loadChild();
43
44            deferred.when(child, dojo.hitch(this, function(){
45                this.startup();
46
47                //set application status to STARTED
48                this.setStatus(this.lifecycle.STARTED);
49            }));
50        },
51                templateString: "<div></div>",
52                selectedChild: null,
53                baseClass: "application mblView",
54                defaultViewType: sceneCtor,
55                buildRendering: function(){
56                        if (this.srcNodeRef===baseWindow.body()){
57                                this.srcNodeRef = dom.create("DIV",{},baseWindow.body());
58                        }
59                        this.inherited(arguments);
60                }
61        });
62       
63        function generateApp(config,node,appSchema,validate){
64
65                //console.log("config.modules: ", config.modules);
66                var modules = config.modules.concat(config.dependencies);
67
68                if (config.template){
69                        //console.log("config.template: ", config.template);
70                        modules.push("dojo/text!" + "app/" + config.template);
71                }
72                //console.log("modules: ", modules);   
73
74                require(modules, function(){
75                        var modules=[Application];
76                        for(var i=0;i<config.modules.length;i++){
77                                modules.push(arguments[i]);
78                        }
79
80                        if (config.template){
81                                var ext = {
82                                        templateString: arguments[arguments.length-1]
83                                }       
84                        }
85                        App = declare(modules,ext);
86
87                        ready(function(){
88                                app = App(config,node || baseWindow.body());
89                app.setStatus(app.lifecycle.STARTING);
90                app.start();
91                        });
92                });
93        }
94
95
96        return function(config,node){
97                if (!config){
98                        throw Error("App Config Missing");
99                }
100
101               
102                if (config.validate){
103                        require(["dojox/json/schema","dojox/json/ref","dojo/text!dojox/application/schema/application.json"],function(schema,appSchema){
104                                schema = dojox.json.ref.resolveJson(schema);   
105                                if (schema.validate(config,appSchema)){
106                                        generateApp(config,node);
107                                }       
108                        });
109               
110
111                }else{
112                        generateApp(config,node);
113                }
114        }
115});
Note: See TracBrowser for help on using the repository browser.