1 | define([ |
---|
2 | "dojo/_base/array", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/_base/lang", |
---|
5 | "dojo/dom-class", |
---|
6 | "dojo/dom-construct", |
---|
7 | "dijit/_Contained", |
---|
8 | "dijit/_Container", |
---|
9 | "dijit/_WidgetBase", |
---|
10 | "./SpinWheelSlot" |
---|
11 | ], function(array, declare, lang, domClass, domConstruct, Contained, Container, WidgetBase, SpinWheelSlot){ |
---|
12 | |
---|
13 | /*===== |
---|
14 | var Contained = dijit._Contained; |
---|
15 | var Container = dijit._Container; |
---|
16 | var WidgetBase = dijit._WidgetBase; |
---|
17 | =====*/ |
---|
18 | |
---|
19 | // module: |
---|
20 | // dojox/mobile/SpinWheel |
---|
21 | // summary: |
---|
22 | // A value picker widget that has spin wheels. |
---|
23 | |
---|
24 | return declare("dojox.mobile.SpinWheel", [WidgetBase, Container, Contained],{ |
---|
25 | // summary: |
---|
26 | // A value picker widget that has spin wheels. |
---|
27 | // description: |
---|
28 | // SpinWheel is a value picker component. It is a sectioned wheel |
---|
29 | // that can be used to pick up some values from the wheel slots by |
---|
30 | // spinning them. |
---|
31 | |
---|
32 | // slotClasses: Array |
---|
33 | // An array of slot classes to be this SpinWheel's slots. |
---|
34 | slotClasses: [], |
---|
35 | |
---|
36 | // slotProps: Array |
---|
37 | // An array of property objects for each slot class specified in |
---|
38 | // slotClasses. |
---|
39 | slotProps: [], |
---|
40 | |
---|
41 | /* internal properties */ |
---|
42 | centerPos: 0, |
---|
43 | |
---|
44 | buildRendering: function(){ |
---|
45 | this.inherited(arguments); |
---|
46 | domClass.add(this.domNode, "mblSpinWheel"); |
---|
47 | this.centerPos = Math.round(this.domNode.offsetHeight / 2); |
---|
48 | |
---|
49 | this.slots = []; |
---|
50 | for(var i = 0; i < this.slotClasses.length; i++){ |
---|
51 | this.slots.push(((typeof this.slotClasses[i] =='string') ? lang.getObject(this.slotClasses[i]) : this.slotClasses[i])(this.slotProps[i])); |
---|
52 | this.addChild(this.slots[i]); |
---|
53 | } |
---|
54 | domConstruct.create("DIV", {className: "mblSpinWheelBar"}, this.domNode); |
---|
55 | }, |
---|
56 | |
---|
57 | startup: function(){ |
---|
58 | this.inherited(arguments); |
---|
59 | this.reset(); |
---|
60 | }, |
---|
61 | |
---|
62 | getValue: function(){ |
---|
63 | // summary: |
---|
64 | // Returns an array of slot values. |
---|
65 | var a = []; |
---|
66 | array.forEach(this.getChildren(), function(w){ |
---|
67 | if(w instanceof SpinWheelSlot){ |
---|
68 | a.push(w.getValue()); |
---|
69 | } |
---|
70 | }, this); |
---|
71 | return a; |
---|
72 | }, |
---|
73 | |
---|
74 | setValue: function(/*Array*/a){ |
---|
75 | // summary: |
---|
76 | // Sets the slot values. |
---|
77 | var i = 0; |
---|
78 | array.forEach(this.getChildren(), function(w){ |
---|
79 | if(w instanceof SpinWheelSlot){ |
---|
80 | w.setValue(a[i]); |
---|
81 | w.setColor(a[i]); |
---|
82 | i++; |
---|
83 | } |
---|
84 | }, this); |
---|
85 | }, |
---|
86 | |
---|
87 | reset: function(){ |
---|
88 | // summary: |
---|
89 | // Resets the SpinWheel to show the initial values. |
---|
90 | array.forEach(this.getChildren(), function(w){ |
---|
91 | if(w instanceof SpinWheelSlot){ |
---|
92 | w.setInitialValue(); |
---|
93 | } |
---|
94 | }, this); |
---|
95 | } |
---|
96 | }); |
---|
97 | }); |
---|