source: Dev/branches/rest-dojo-ui/client/dojox/mvc/_Container.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: 3.3 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dijit/_WidgetBase",
5        "dojo/regexp"
6], function(declare, lang, _WidgetBase, regexp){
7        /*=====
8                declare = dojo.declare;
9                _WidgetBase = dijit._WidgetBase;
10        =====*/
11
12        return declare("dojox.mvc._Container", [_WidgetBase], {
13       
14                // stopParser: [private] Boolean
15                //              Flag to parser to not try and parse widgets declared inside the container.
16                stopParser: true,
17
18                // exprchar:  Character
19                //              Character to use for a substitution expression, for a substitution string like ${this.index}
20                exprchar: '$',
21       
22                // templateString: [private] String
23                //              The template or content for this container. It is usually obtained from the
24                //              body of the container and may be modified or repeated over a collection/array.
25                //              In this simple implementation, attach points, attach events and WAI
26                //              attributes are not supported in the template.
27                templateString : "",
28       
29                // _containedWidgets: [protected] dijit._Widget[]
30                //              The array of contained widgets at any given point in time within this container.
31                _containedWidgets : [],
32       
33                ////////////////////// PROTECTED METHODS ////////////////////////
34       
35                _parser : null,
36               
37                _createBody: function(){
38                        // summary:
39                        //              Parse the body of this MVC container widget.
40                        // description:
41                        //              The bodies of MVC containers may be model-bound views generated dynamically.
42                        //              Parse the body, start an contained widgets and attach template nodes for
43                        //              contained widgets as necessary.
44                        // tags:
45                        //              protected
46                        if(!this._parser){
47                                try{
48                                        // returns dojo/parser if loaded, otherwise throws
49                                        this._parser = require("dojo/parser");
50                                }catch(e){
51                                        // if here, dojo/parser not loaded
52                                        try{
53                                                // returns dojox/mobile/parser if loaded, otherwise throws
54                                                this._parser = require("dojox/mobile/parser");
55                                        }catch(e){
56                                                // if here, both dojox/mobile/parser and dojo/parser are not loaded
57                                                console.error("Add explicit require(['dojo/parser']) or explicit require(['dojox/mobile/parser']), one of the parsers is required!");
58                                        }
59                                }
60                        }
61                        if(this._parser){
62                                this._containedWidgets = this._parser.parse(this.srcNodeRef,{
63                                        template: true,
64                                        inherited: {dir: this.dir, lang: this.lang},
65                                        propsThis: this,
66                                        scope: "dojo"
67                                });
68                        }
69                },
70       
71                _destroyBody: function(){
72                        // summary:
73                        //              Destroy the body of this MVC container widget. Also destroys any
74                        //              contained widgets.
75                        // tags:
76                        //              protected
77                        if(this._containedWidgets && this._containedWidgets.length > 0){
78                                for(var n = this._containedWidgets.length - 1; n > -1; n--){
79                                        var w = this._containedWidgets[n];
80                                        if(w && !w._destroyed && w.destroy){
81                                                w.destroy();
82                                        }
83                                }
84                        }
85                },
86       
87                ////////////////////// PRIVATE METHODS ////////////////////////
88
89                _exprRepl: function(tmpl){
90                        // summary:
91                        //              Does substitution of ${foo+bar} type expressions in template string.
92                        // tags:
93                        //              private
94                        var pThis = this, transform = function(value, key){
95                                if(!value){return "";}
96                                var exp = value.substr(2);
97                                exp = exp.substr(0, exp.length - 1);
98                                with(pThis){return eval(exp);}
99                        };
100                        transform = lang.hitch(this, transform);
101                        return tmpl.replace(new RegExp(regexp.escapeString(this.exprchar)+"(\{.*?\})","g"),
102                                function(match, key, format){
103                                        return transform(match, key).toString();
104                                });
105                }
106        });
107});
Note: See TracBrowser for help on using the repository browser.