1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/_base/array', |
---|
4 | 'dijit/registry', |
---|
5 | 'dojo/_base/lang', |
---|
6 | 'dojo/_base/event', |
---|
7 | 'dojo/fx', |
---|
8 | 'dijit/_WidgetBase', |
---|
9 | 'dijit/_TemplatedMixin', |
---|
10 | 'dijit/_WidgetsInTemplateMixin', |
---|
11 | 'dijit/_Container', |
---|
12 | './LineWithActionsWidget', |
---|
13 | 'dojo/text!./templates/Selector.html', |
---|
14 | 'dojo/dom-class' |
---|
15 | ],function( |
---|
16 | declare, |
---|
17 | baseArray, |
---|
18 | registry, |
---|
19 | lang, |
---|
20 | event, |
---|
21 | fx, |
---|
22 | _WidgetBase, |
---|
23 | _TemplatedMixin, |
---|
24 | _WidgetsInTemplateMixin, |
---|
25 | _Container, |
---|
26 | LineWithActionsWidget, |
---|
27 | templateString, |
---|
28 | domClass |
---|
29 | ){ |
---|
30 | return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{ |
---|
31 | templateString: templateString, |
---|
32 | title: "", |
---|
33 | baseClass: 'rftSelector', |
---|
34 | modifiers: 'blue', |
---|
35 | _folded: true, |
---|
36 | _titleLine: null, |
---|
37 | _selectorLine: null, |
---|
38 | _selectedItem: null, |
---|
39 | |
---|
40 | startup: function() { |
---|
41 | domClass.add(this.domNode, this.modifiers); |
---|
42 | domClass.add(this.selectedColorNode, "pending"); |
---|
43 | |
---|
44 | this._titleLine = new LineWithActionsWidget({ |
---|
45 | title: this.title, |
---|
46 | modifiers: this.modifiers, |
---|
47 | actions: { |
---|
48 | "Include in survey" : { |
---|
49 | callback: lang.hitch(this, this._onInclude), |
---|
50 | properties: { |
---|
51 | blockButton: true, |
---|
52 | modifiers: this.modifiers, |
---|
53 | icon: "Accept", |
---|
54 | label: "Include" |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | },this.titleNode); |
---|
59 | this._titleLine.startup(); |
---|
60 | |
---|
61 | this._selectorLine = new LineWithActionsWidget({ |
---|
62 | title: 'None', |
---|
63 | modifiers: this.modifiers, |
---|
64 | actions: { |
---|
65 | "Toggle dropdown" : { |
---|
66 | callback: lang.hitch(this, this._onToggleDropdown), |
---|
67 | properties: { |
---|
68 | blockButton: true, |
---|
69 | modifiers: this.modifiers, |
---|
70 | showLabel: false, |
---|
71 | icon: "HalfArrowDown" |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | },this.selectedItemNode); |
---|
76 | this._selectorLine.startup(); |
---|
77 | |
---|
78 | fx.wipeOut({ |
---|
79 | node: this.optionsNode |
---|
80 | }).play(); |
---|
81 | }, |
---|
82 | _onSelect: function(item, widget) { |
---|
83 | this._selectedItem = item; |
---|
84 | this._onToggleDropdown(); |
---|
85 | this._selectorLine.set("title", item.title); |
---|
86 | baseArray.forEach(this.optionsNode.childNodes, function(node){ |
---|
87 | var line = registry.byNode(node); |
---|
88 | if (line) { |
---|
89 | if (line === widget) { |
---|
90 | domClass.add(line.domNode, "inheritBgColor light"); |
---|
91 | } else { |
---|
92 | domClass.remove(line.domNode, "inheritBgColor light"); |
---|
93 | } |
---|
94 | } |
---|
95 | }, this); |
---|
96 | this.onSelect(item); |
---|
97 | }, |
---|
98 | _onInclude: function() { |
---|
99 | if (this._selectedItem) { |
---|
100 | this.onInclude(this._selectedItem); |
---|
101 | } |
---|
102 | }, |
---|
103 | _onToggleDropdown: function(evt) { |
---|
104 | if (this._folded) { |
---|
105 | var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0]; |
---|
106 | if (downArrowIcon){ |
---|
107 | domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown"); |
---|
108 | } |
---|
109 | fx.wipeIn({ |
---|
110 | node: this.optionsNode |
---|
111 | }).play(); |
---|
112 | this._folded = false; |
---|
113 | } else { |
---|
114 | var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this._selectorLine.buttonsNode)[0]; |
---|
115 | if (upArrowIcon){ |
---|
116 | domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp"); |
---|
117 | } |
---|
118 | fx.wipeOut({ |
---|
119 | node: this.optionsNode |
---|
120 | }).play(); |
---|
121 | this._folded = true; |
---|
122 | } |
---|
123 | evt && event.stop(evt); |
---|
124 | return false; |
---|
125 | }, |
---|
126 | addItem: function(item) { |
---|
127 | var w = new LineWithActionsWidget({ |
---|
128 | title: item.title, |
---|
129 | actions: { |
---|
130 | "Info" : { |
---|
131 | callback: function() { |
---|
132 | item.description && alert(item.description); |
---|
133 | }, |
---|
134 | properties: { |
---|
135 | blockButton: false, |
---|
136 | showLabel: false, |
---|
137 | icon: "Inspect" |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | }).placeAt(this.optionsNode); |
---|
142 | w.startup(); |
---|
143 | w.on("click", lang.hitch(this, this._onSelect, item, w)); |
---|
144 | }, |
---|
145 | onSelect: function(item) {}, |
---|
146 | onInclude: function(item) {} |
---|
147 | }); |
---|
148 | }); |
---|