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

Last change on this file since 362 was 362, checked in by hendrikvanantwerpen, 13 years ago

Selector can be clicked on whole line now.
Question editor in survey page does lazy loading per
category and displays total number of questions.

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            onToggle: function(evt) {
105                if (this._folded) {
106                    var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0];
107                    if (downArrowIcon){
108                        domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown");
109                    }
110                    fx.wipeIn({
111                        node: this.optionsNode
112                    }).play();
113                    this._folded = false;
114                } else {
115                    var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this._selectorLine.buttonsNode)[0];
116                    if (upArrowIcon){
117                        domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp");
118                    }
119                    fx.wipeOut({
120                        node: this.optionsNode
121                    }).play();
122                    this._folded = true;
123                }
124                evt && event.stop(evt);
125                return false;
126            },
127            addItem: function(item) {
128                var w = new LineWithActionsWidget({
129                    title: item.title,
130                    actions: {
131                        "Info" : {
132                            callback: function() {
133                                item.description && alert(item.description);
134                            },
135                            properties: {
136                                blockButton: false,
137                                showLabel: false,
138                                icon: "Inspect"
139                            }
140                        }
141                    }
142                }).placeAt(this.optionsNode);
143                w.startup();
144                w.on("click", lang.hitch(this, this._onSelect, item, w));
145            },
146            onSelect: function(item) {},
147            onInclude: function(item) {}
148        });
149});
Note: See TracBrowser for help on using the repository browser.