1 | define(["dojo/dom", "dojo/dom-style", "dojo/_base/connect", "dojo/_base/lang","dijit/registry", "dojox/mvc/at", |
---|
2 | "dojox/mvc/Repeat", "dojox/mvc/getStateful", "dojox/mvc/Output", "dojo/sniff"], |
---|
3 | function(dom, domStyle, connect, lang, registry, at, Repeat, getStateful, Output, has){ |
---|
4 | var _connectResults = []; // events connect result |
---|
5 | |
---|
6 | var repeatmodel = null; //repeat view data model |
---|
7 | |
---|
8 | // these ids are updated here and in the html file to avoid duplicate ids |
---|
9 | var backId = 'sc4back1'; |
---|
10 | var insert1Id = 'sc4insert1x'; |
---|
11 | var insert10Id = 'sc4insert10x'; |
---|
12 | var remove10Id = 'sc4remove10x'; |
---|
13 | |
---|
14 | var app = null; |
---|
15 | |
---|
16 | return { |
---|
17 | // repeat view init |
---|
18 | init: function(){ |
---|
19 | app = this.app; |
---|
20 | |
---|
21 | repeatmodel = this.loadedModels.repeatmodels; |
---|
22 | var connectResult; |
---|
23 | |
---|
24 | connectResult = connect.connect(dom.byId(insert1Id), "click", lang.hitch(this,function(e){ |
---|
25 | this.app.insertResult(repeatmodel.model.length-1,e); |
---|
26 | })); |
---|
27 | _connectResults.push(connectResult); |
---|
28 | |
---|
29 | connectResult = connect.connect(dom.byId(insert10Id), "click", function(){ |
---|
30 | //Add 10 items to the end of the model |
---|
31 | app.showProgressIndicator(true); |
---|
32 | setTimeout(lang.hitch(this,function(){ |
---|
33 | var maxentries = repeatmodel.model.length+10; |
---|
34 | for(var i = repeatmodel.model.length; i < maxentries; i++){ |
---|
35 | var data = {id:Math.random(), "First": "First"+repeatmodel.model.length, "Last": "Last"+repeatmodel.model.length, "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""}; |
---|
36 | repeatmodel.model.splice(repeatmodel.model.length, 0, new getStateful(data)); |
---|
37 | } |
---|
38 | app.showProgressIndicator(false); |
---|
39 | }), 100); |
---|
40 | |
---|
41 | }); |
---|
42 | _connectResults.push(connectResult); |
---|
43 | |
---|
44 | connectResult = connect.connect(dom.byId(remove10Id), "click", function(){ |
---|
45 | //remove 10 items to the end of the model |
---|
46 | app.showProgressIndicator(true); |
---|
47 | setTimeout(lang.hitch(this,function(){ |
---|
48 | var maxentries = repeatmodel.model.length-10; |
---|
49 | for(var i = repeatmodel.model.length; i >= maxentries; i--){ |
---|
50 | repeatmodel.model.splice(i, 1); |
---|
51 | } |
---|
52 | repeatmodel.set("cursorIndex", 0); |
---|
53 | app.showProgressIndicator(false); |
---|
54 | }), 100); |
---|
55 | }); |
---|
56 | _connectResults.push(connectResult); |
---|
57 | }, |
---|
58 | |
---|
59 | |
---|
60 | beforeActivate: function(){ |
---|
61 | // summary: |
---|
62 | // view life cycle beforeActivate() |
---|
63 | if(dom.byId(backId) && !has("phone")){ |
---|
64 | domStyle.set(dom.byId(backId), "visibility", "hidden"); // hide the back button in tablet mode |
---|
65 | } |
---|
66 | if(dom.byId("tab1WrapperA")){ |
---|
67 | domStyle.set(dom.byId("tab1WrapperA"), "visibility", "visible"); // show the nav view if it being used |
---|
68 | domStyle.set(dom.byId("tab1WrapperB"), "visibility", "visible"); // show the nav view if it being used |
---|
69 | } |
---|
70 | }, |
---|
71 | |
---|
72 | |
---|
73 | destroy: function(){ |
---|
74 | var connectResult = _connectResults.pop(); |
---|
75 | while(connectResult){ |
---|
76 | connect.disconnect(connectResult); |
---|
77 | connectResult = _connectResults.pop(); |
---|
78 | } |
---|
79 | } |
---|
80 | }; |
---|
81 | }); |
---|