source: Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js @ 367

Last change on this file since 367 was 364, checked in by jkraaijeveld, 13 years ago

Since lists where common, created a ListView? base class with basic functionality. For the session editor, created a AccountListView? which only has the created method declared and derives everything else from ListView?.

File size: 5.5 KB
Line 
1define([
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.onToggle),
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                this._selectorLine.on('click',lang.hitch(this, this.onToggle));
78
79                fx.wipeOut({
80                    node: this.optionsNode
81                }).play();
82            },
83            _onSelect: function(item, widget) {
84                this._selectedItem = item;
85                this.onToggle();
86                this._selectorLine.set("title", item.title);
87                baseArray.forEach(this.optionsNode.childNodes, function(node){
88                    var line = registry.byNode(node);
89                    if (line) {
90                        if (line === widget) {
91                            domClass.add(line.domNode, "inheritBgColor light");
92                        } else {
93                            domClass.remove(line.domNode, "inheritBgColor light");
94                        }
95                    }
96                }, this);
97                this.onSelect(item);
98            },
99            _onInclude: function() {
100                if (this._selectedItem) {
101                    this.onInclude(this._selectedItem);
102                }
103            },
104
105            onToggle: function(evt) {
106                if (this._folded) {
107                    var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0];
108                    if (downArrowIcon){
109                        domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown");
110                    }
111                    fx.wipeIn({
112                        node: this.optionsNode
113                    }).play();
114                    this._folded = false;
115                } else {
116                    var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this._selectorLine.buttonsNode)[0];
117                    if (upArrowIcon){
118                        domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp");
119                    }
120                    fx.wipeOut({
121                        node: this.optionsNode
122                    }).play();
123                    this._folded = true;
124                }
125                evt && event.stop(evt);
126                return false;
127            },
128            addItem: function(item) {
129                var w = new LineWithActionsWidget({
130                    title: item.title,
131                    actions: {
132                        "Info" : {
133                            callback: function() {
134                                item.description && alert(item.description);
135                            },
136                            properties: {
137                                blockButton: false,
138                                showLabel: false,
139                                icon: "Inspect"
140                            }
141                        }
142                    }
143                }).placeAt(this.optionsNode);
144                w.startup();
145                w.on("click", lang.hitch(this, this._onSelect, item, w));
146            },
147            onSelect: function(item) {},
148            onInclude: function(item) {}
149        });
150});
Note: See TracBrowser for help on using the repository browser.