source: Dev/branches/rest-dojo-ui/client/dojox/mvc/_base.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).

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/lang",
4        "./StatefulModel",
5        "./Bind",
6        "./_DataBindingMixin",
7        "./_patches"
8], function(kernel, lang, StatefulModel){
9        // module:
10        //              dojox/mvc/_base
11        // summary:
12        //              Pulls in essential MVC dependencies such as basic support for
13        //              data binds, a data model and data binding mixin for dijits.
14        kernel.experimental("dojox.mvc");
15
16        var mvc = lang.getObject("dojox.mvc", true);
17        /*=====
18                mvc = dojox.mvc;
19        =====*/
20
21        // Factory method for dojox.mvc.StatefulModel instances
22        mvc.newStatefulModel = function(/*Object*/args){
23                // summary:
24                //              Factory method that instantiates a new data model that view
25                //              components may bind to.
26                //      args:
27                //              The mixin properties.
28                // description:
29                //              Factory method that returns a client-side data model, which is a
30                //              tree of dojo.Stateful objects matching the initial data structure
31                //              passed as input:
32                //              - The mixin property "data" is used to provide a plain JavaScript
33                //                object directly representing the data structure.
34                //              - The mixin property "store", along with an optional mixin property
35                //                "query", is used to provide a data store to query to obtain the
36                //                initial data.
37                //              This function returns an immediate dojox.mvc.StatefulModel instance or
38                //              a Promise for such an instance as follows:
39                //              - if args.data: returns immediate
40                //              - if args.store:
41                //                      - if store returns immediate: this function returns immediate
42                //                      - if store returns a Promise: this function returns a model
43                //                        Promise
44                if(args.data){
45                        return new StatefulModel({ data : args.data });
46                }else if(args.store && lang.isFunction(args.store.query)){
47                        var model;
48                        var result = args.store.query(args.query);
49                        if(result.then){
50                                return (result.then(function(data){
51                                        model = new StatefulModel({ data : data });
52                                        model.store = args.store;
53                                        return model;
54                                }));
55                        }else{
56                                model = new StatefulModel({ data : result });
57                                model.store = args.store;
58                                return model;
59                        }
60                }
61        };
62
63        return mvc;
64});
Note: See TracBrowser for help on using the repository browser.