source: Dev/trunk/src/client/dojox/app/utils/constraints.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1define(["dojo/_base/array"], function(arr){
2        var constraints = [];
3        return {
4                getSelectedChild: function(view, constraint){
5                        // summary:
6                        //              get current selected child according to the constraint
7                        //
8                        // view: View
9                        //              the View to get the child from
10                        // constraint: Object
11                        //              tbe constraint object
12                        //
13                        // returns:
14                        //              the selected child view for this constraint
15                        var type = typeof(constraint);
16                        var hash = (type == "string" || type == "number") ? constraint : constraint.__hash;
17                        return (view && view.selectedChildren && view.selectedChildren[hash]) ?
18                                view.selectedChildren[hash] : null;
19                },
20
21                setSelectedChild: function(view, constraint, child){
22                        // summary:
23                        //              set current selected child according to the constraint
24                        //
25                        // view: View
26                        //              the View to set the selected child to
27                        // constraint: Object
28                        //              tbe constraint object
29                        // child: View
30                        //              the child to select
31                        var type = typeof(constraint);
32                        var hash = (type == "string" || type == "number") ? constraint : constraint.__hash;
33                        view.selectedChildren[hash] = child;
34                },
35
36
37                getAllSelectedChildren: function(view, selChildren){
38                        // summary:
39                        //              get current all selected children for this view and it's selected subviews
40                        //
41                        // view: View
42                        //              the View to get the child from
43                        //
44                        // selChildren: Array
45                        //              the Array of the subChildren found
46                        //
47                        // returns:
48                        //              selChildren array of all of the selected child views
49                        //
50                        selChildren = selChildren || [];
51                        if(view && view.selectedChildren){
52                                for(var hash in view.selectedChildren){
53                                        if(view.selectedChildren[hash]){
54                                                var subChild = view.selectedChildren[hash];
55                                                selChildren.push(subChild);
56                                                this.getAllSelectedChildren(subChild, selChildren);
57                                        }
58                                }
59                        }
60                        return selChildren;
61                },
62
63                register: function(constraint){
64                        // if the constraint has already been registered we don't care about it...
65                        var type = typeof(constraint);
66                        if(!constraint.__hash && type != "string" && type != "number"){
67                                var match = null;
68                                arr.some(constraints, function(item){
69                                        var ok = true;
70                                        for(var prop in item){
71                                                if(prop.charAt(0) !== "_"){//skip the private properties
72                                                        if(item[prop] != constraint[prop]){
73                                                                ok = false;
74                                                                break;
75                                                        }
76                                                }
77                                        }
78                                        if(ok == true){
79                                                match = item;
80                                        }
81                                        return ok;
82                                });
83                                if(match){
84                                        constraint.__hash = match.__hash;
85                                }else{
86                                        // create a new "hash"
87                                        var hash = "";
88                                        for(var prop in constraint){
89                                                if(prop.charAt(0) !== "_"){
90                                                        hash += constraint[prop];
91                                                }
92                                        }
93                                        constraint.__hash = hash;
94                                        constraints.push(constraint);
95                                }
96                        }
97                }
98        };
99});
Note: See TracBrowser for help on using the repository browser.