source: Dev/trunk/src/client/dojox/app/tests/scrollableTestApp2/views/Scrollable1P.js

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

Added Dojo 1.9.3 release.

File size: 5.8 KB
Line 
1define(["dojo/dom", "dojo/dom-style", "dojo/_base/connect", "dojo/_base/lang", "dojo/_base/declare", "dijit/registry", "dojox/mvc/at",
2"dojox/mobile/TransitionEvent", "dojox/mvc/Repeat", "dojox/mvc/getStateful", "dojox/mvc/Output", "dojo/sniff",
3"dojox/mobile/RoundRectList", "dojox/mvc/WidgetList", "dojox/mvc/Templated", "dojox/mobile/ListItem", "dojo/text!../views/RoundRectWidListTemplate.html"],
4function(dom, domStyle, connect, lang, declare, registry, at, TransitionEvent, Repeat, getStateful, Output, has, RoundRectList, WidgetList, Templated,
5        ListItem, RoundRectWidListTemplate){
6        var _connectResults = []; // events connect result
7
8        var repeatmodel = null; //repeat view data model
9        var roundRectWidList = null;
10       
11        // these ids are updated here and in the html file to avoid duplicate ids
12        var backId = 'sc1back1P';
13        var insert1Id = 'sc1insert1xP';
14        var insert10Id = 'sc1insert10xP';
15        var remove10Id = 'sc1remove10xP';
16
17        var app = null;
18
19        // insert an item
20        var insertResult = function(index, e){
21                if(index<0 || index>repeatmodel.model.length){
22                        throw Error("index out of data model.");
23                }
24                if((repeatmodel.model[index].First=="") ||
25                        (repeatmodel.model[index+1] && (repeatmodel.model[index+1].First == ""))){
26                        return;
27                }
28                var data = {id:Math.random(), "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""};
29                repeatmodel.model.splice(index+1, 0, new getStateful(data));
30                this.app.setDetailsContext(index+1);
31                var transOpts = {
32                        title : "repeatDetails",
33                        target : "repeatDetails",
34                        url : "#repeatDetails", // this is optional if not set it will be created from target   
35                        params : {"cursor":index+1}
36                };
37                new TransitionEvent(e.target, transOpts, e).dispatch();
38               
39        };
40       
41        var showListData = function(/*dojox/mvc/EditStoreRefListController*/ datamodel){
42                // summary:
43                //              create the WidgetList programatically if it has not been created, and
44                //              set the children for items_list widget to the datamodel to show the items in the selected list.
45                //              RoundRectWidListTemplate is used for the templateString of the WidgetList.
46                //
47                // datamodel: dojox/mvc/EditStoreRefListController
48                //              The EditStoreRefListController whose model holds the items for the selected list.
49                //
50                if(!roundRectWidList){
51                        var clz = declare([WidgetList, RoundRectList], {});
52                        roundRectWidList = new clz({
53                                children: at(datamodel, 'model'),
54                                childClz: declare([Templated /* dojox/mvc/Templated module return value */, ListItem /* dojox/mobile/ListItem module return value */]),
55                                childParams: {
56                                        transitionOptions: {title:'Details',target:'repeatDetails',url:'#repeatDetails',params:{'cursor':this.indexAtStartup}},
57                                        clickable: true,
58                                        onClick: function(){
59                                                console.log("in onClick this.indexAtStartup="+this.indexAtStartup);
60                                                app.setDetailsContext(this.indexAtStartup);}
61                                },
62                                childBindings: {
63                                        titleNode: {value: at("rel:", "First")}
64                                },
65                                templateString: RoundRectWidListTemplate
66                        });
67                        roundRectWidList.placeAt(dom.byId("addWidgetHere"));
68                        roundRectWidList.startup();
69                }else{
70                        roundRectWidList.set("children", at(datamodel, 'model'));
71                }
72        };
73
74        return {
75                init: function(){
76                        app = this.app;
77
78                        repeatmodel = this.loadedModels.repeatmodels;
79                        var connectResult;
80
81                        connectResult = connect.connect(dom.byId(insert1Id), "click", function(e){
82                                app.insertResult(repeatmodel.model.length-1,e);
83                        });
84                        _connectResults.push(connectResult);
85
86                        connectResult = connect.connect(dom.byId(insert10Id), "click", function(){
87                                //Add 10 items to the end of the model
88                                app.showProgressIndicator(true);
89                                setTimeout(lang.hitch(this,function(){
90                                        var maxentries = repeatmodel.model.length+10;
91                                        for(var i = repeatmodel.model.length; i < maxentries; i++){
92                                                var data = {id:Math.random(), "First": "First"+repeatmodel.model.length, "Last": "Last"+repeatmodel.model.length, "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""};
93                                                repeatmodel.model.splice(repeatmodel.model.length, 0, new getStateful(data));                                   
94                                        }
95                                        app.showProgressIndicator(false);
96                                }), 100);                               
97                               
98                        });
99                        _connectResults.push(connectResult);
100
101                        connectResult = connect.connect(dom.byId(remove10Id), "click", function(){
102                                //remove 10 items to the end of the model
103                                app.showProgressIndicator(true);
104                                setTimeout(lang.hitch(this,function(){                         
105                                        var maxentries = repeatmodel.model.length-10;
106                                        for(var i = repeatmodel.model.length; i >= maxentries; i--){
107                                                repeatmodel.model.splice(i, 1);
108                                        }
109                                        repeatmodel.set("cursorIndex", 0);             
110                                        app.showProgressIndicator(false);
111                                }), 100);                               
112                        });
113                        _connectResults.push(connectResult);
114                       
115                        showListData(this.loadedModels.repeatmodels);
116                },
117
118
119                beforeActivate: function(){
120                        // summary:
121                        //              view life cycle beforeActivate()
122                        if(dom.byId(backId) && !has("phone")){
123                                domStyle.set(dom.byId(backId), "visibility", "hidden"); // hide the back button in tablet mode
124                        }
125                        if(dom.byId("tab1WrapperA")){
126                                domStyle.set(dom.byId("tab1WrapperA"), "visibility", "visible");  // show the nav view if it being used
127                                domStyle.set(dom.byId("tab1WrapperB"), "visibility", "visible");  // show the nav view if it being used
128                        }
129                        //domStyle.set(dom.byId(wrapperIdA), "visibility", "visible");  // show the view when it is ready
130                        //domStyle.set(dom.byId(wrapperIdB), "visibility", "visible");  // show the view when it is ready
131                        //domStyle.set(dom.byId(wrapperIdC), "visibility", "visible");  // show the view when it is ready
132                        //domStyle.set(dom.byId(wrapperIdD), "visibility", "visible");  // show the view when it is ready
133
134                        showListData(this.loadedModels.repeatmodels);                   
135                },
136
137                afterActivate: function(){
138                        // summary:
139                        //              view life cycle afterActivate()
140                },
141               
142               
143                destroy: function(){
144                        var connectResult = _connectResults.pop();
145                        while(connectResult){
146                                connect.disconnect(connectResult);
147                                connectResult = _connectResults.pop();
148                        }
149                }
150        };
151});
Note: See TracBrowser for help on using the repository browser.