source: Dev/trunk/src/client/dojox/mobile/TreeView.js @ 536

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

Added Dojo 1.9.3 release.

File size: 3.3 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/array",
4        "dojo/_base/declare",
5        "dojo/_base/lang",
6        "dojo/_base/window",
7        "dojo/dom-construct",
8        "dijit/registry",
9        "./Heading",
10        "./ListItem",
11        "./ProgressIndicator",
12        "./RoundRectList",
13        "./ScrollableView",
14        "./viewRegistry",
15        "dojo/has",
16        "dojo/has!dojo-bidi?dojox/mobile/bidi/TreeView"
17], function(kernel, array, declare, lang, win, domConstruct, registry, Heading, ListItem, ProgressIndicator, RoundRectList, ScrollableView, viewRegistry, has, BidiTreeView){
18
19        // module:
20        //              dojox/mobile/TreeView
21
22        kernel.experimental("dojox.mobile.TreeView");
23
24        var TreeView = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiTreeView" : "dojox.mobile.TreeView", ScrollableView, {
25                // summary:
26                //              A scrollable view with tree-style navigation.
27                // description:
28                //              This widget can be connected to a dojox/data/FileStore as a
29                //              quick directory browser. You may use it when implementing the
30                //              Master-Detail pattern.
31
32                postCreate: function(){
33                        this._load();
34                        this.inherited(arguments);
35                },
36               
37                _customizeListItem: function(listItemArgs){
38                },
39
40                _load: function(){
41                        this.model.getRoot(
42                                lang.hitch(this, function(item){
43                                        var scope = this;
44                                        var list = new RoundRectList();
45                                        var node = {};
46                                        var listItemArgs = {
47                                                label: scope.model.rootLabel,
48                                                moveTo: '#',
49                                                onClick: function(){ scope.handleClick(this); },
50                                                item: item
51                                        };
52                                        this._customizeListItem(listItemArgs);
53                                        var listitem = new ListItem(listItemArgs);
54                                        list.addChild(listitem);
55                                        this.addChild(list);
56                                })
57                        )
58                },
59
60                handleClick: function(li){
61                        // summary:
62                        //              Called when the user clicks a tree item.
63                        // li: dojox/mobile/ListItem
64                        //              The item that the user clicked.
65                        var newViewId = "view_";
66                        if(li.item[this.model.newItemIdAttr]){
67                                newViewId += li.item[this.model.newItemIdAttr];
68                        }else{
69                                newViewId += "rootView";
70                        }
71                        newViewId = newViewId.replace('/', '_');
72                        if(registry.byId(newViewId)){  // view already exists, just transition to it
73                                registry.byNode(li.domNode).transitionTo(newViewId);
74                                return;
75                        }
76
77                        var prog = ProgressIndicator.getInstance();
78                        win.body().appendChild(prog.domNode);
79                        prog.start();
80
81                        this.model.getChildren(li.item,
82                                lang.hitch(this, function(items){
83                                        var scope = this;
84                                        var list = new RoundRectList();
85                                        array.forEach(items, function(item, i){
86                                                var listItemArgs = {
87                                                        item: item,
88                                                        label: item[scope.model.store.label],
89                                                        transition: "slide"
90                                                };
91                                                scope._customizeListItem(listItemArgs);
92                                                if(scope.model.mayHaveChildren(item)){
93                                                        listItemArgs.moveTo = '#';
94                                                        listItemArgs.onClick = function(){ scope.handleClick(this); };
95                                                }
96                                                var listitem = new ListItem(listItemArgs);
97                                                list.addChild(listitem);
98                                        });
99
100                                        var heading = new Heading({
101                                                label: "Dynamic View",
102                                                back: "Back",
103                                                moveTo: viewRegistry.getEnclosingView(li.domNode).id
104                                        });
105
106                                        var newView = ScrollableView({
107                                                id: newViewId
108                                        }, domConstruct.create("div", null, win.body()));
109                                        newView.addChild(heading);
110                                        newView.addChild(list);
111                                        newView.startup();
112                                        prog.stop();
113                                        registry.byNode(li.domNode).transitionTo(newView.id);
114                                })
115                        )
116                }
117        });
118       
119        return has("dojo-bidi") ? declare("dojox.mobile.TreeView", [TreeView, BidiTreeView]) : TreeView;               
120});
Note: See TracBrowser for help on using the repository browser.