1 | define([ |
---|
2 | "dojo/_base/array", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dijit/_Contained", |
---|
5 | "dijit/_Container", |
---|
6 | "dijit/_WidgetBase" |
---|
7 | ], function(array, declare, Contained, Container, WidgetBase){ |
---|
8 | |
---|
9 | // module: |
---|
10 | // dojox/mobile/_PickerBase |
---|
11 | |
---|
12 | return declare("dojox.mobile._PickerBase", [WidgetBase, Container, Contained], { |
---|
13 | // summary: |
---|
14 | // A base class for picker classes (e.g. SpinWheel, ValuePicker). |
---|
15 | |
---|
16 | /*===== |
---|
17 | // values: Array |
---|
18 | // An array of slot values. |
---|
19 | // Warning: Do not use this property directly, make sure to call set() or get() methods. |
---|
20 | values: "", |
---|
21 | =====*/ |
---|
22 | |
---|
23 | /*===== |
---|
24 | // colors: Array |
---|
25 | // An array of slot colors. |
---|
26 | // Warning: Do not use this property directly, make sure to call set() or get() methods. |
---|
27 | colors: "", |
---|
28 | =====*/ |
---|
29 | |
---|
30 | /* internal properties */ |
---|
31 | |
---|
32 | // slotClasses: [protected] Array |
---|
33 | // An array of slot classes. This property is intended to be used |
---|
34 | // when you create a subclass of this widget that has specific slots. |
---|
35 | slotClasses: [], |
---|
36 | |
---|
37 | // slotProps: [protected] Array |
---|
38 | // An array of property objects for each slot class specified in |
---|
39 | // slotClasses. This property is intended to be used when you |
---|
40 | // create a subclass of this widget that has specific slots. |
---|
41 | slotProps: [], |
---|
42 | |
---|
43 | // slotOrder: [protected] Array |
---|
44 | // An array of index of slotClasses and slotProps. |
---|
45 | // If there are three slots and slotOrder=[2,1,0], the slots are |
---|
46 | // displayed in reversed order. This property is intended to be used |
---|
47 | // when you create a subclass of this widget that has specific slots. |
---|
48 | slotOrder: [], |
---|
49 | |
---|
50 | buildRendering: function(){ |
---|
51 | this.inherited(arguments); |
---|
52 | this.slots = []; |
---|
53 | for(var i = 0; i < this.slotClasses.length; i++){ |
---|
54 | var idx = this.slotOrder.length ? this.slotOrder[i] : i; |
---|
55 | var slot = new this.slotClasses[idx](this.slotProps[idx]); |
---|
56 | this.addChild(slot); |
---|
57 | this.slots[idx] = slot; |
---|
58 | } |
---|
59 | }, |
---|
60 | |
---|
61 | startup: function(){ |
---|
62 | if(this._started){ return; } |
---|
63 | this._duringStartup = true; |
---|
64 | this.inherited(arguments); |
---|
65 | this.reset(); |
---|
66 | delete this._duringStartup; |
---|
67 | }, |
---|
68 | |
---|
69 | getSlots: function(){ |
---|
70 | // summary: |
---|
71 | // Returns an array of child slot widgets. |
---|
72 | return this.slots.length ? this.slots : |
---|
73 | array.filter(this.getChildren(), function(c){ |
---|
74 | return c.declaredClass.indexOf("Slot") !== -1; |
---|
75 | }); |
---|
76 | }, |
---|
77 | |
---|
78 | _getValuesAttr: function(){ |
---|
79 | // summary: |
---|
80 | // Returns an array of slot values. |
---|
81 | // tags: |
---|
82 | // private |
---|
83 | return array.map(this.getSlots(), function(w){ |
---|
84 | return w.get("value"); |
---|
85 | }); |
---|
86 | }, |
---|
87 | |
---|
88 | _setValuesAttr: function(/*Array*/a){ |
---|
89 | // summary: |
---|
90 | // Sets the slot values. |
---|
91 | // tags: |
---|
92 | // private |
---|
93 | array.forEach(this.getSlots(), function(w, i){ |
---|
94 | w.set("value", a[i]); |
---|
95 | }); |
---|
96 | }, |
---|
97 | |
---|
98 | _setColorsAttr: function(/*Array*/a){ |
---|
99 | // summary: |
---|
100 | // Sets the slot colors. |
---|
101 | // tags: |
---|
102 | // private |
---|
103 | array.forEach(this.getSlots(), function(w, i){ |
---|
104 | w.setColor && w.setColor(a[i]); |
---|
105 | }); |
---|
106 | }, |
---|
107 | |
---|
108 | reset: function(){ |
---|
109 | // summary: |
---|
110 | // Resets the picker to show the initial values. |
---|
111 | array.forEach(this.getSlots(), function(w){ |
---|
112 | w.setInitialValue(); |
---|
113 | }); |
---|
114 | } |
---|
115 | }); |
---|
116 | }); |
---|